Commits

Harald Klimach committed e6c9fcf Merge

Merged the changes to the errorcode handling in

  • Participants
  • Parent commits fe22229, a16b15a

Comments (0)

Files changed (3)

source/aot_fun_module.f90

   !> Execute a given function and put its results
   !! on the stack, where it is retrievable with
   !! aot_top_get_val.
-  subroutine aot_fun_do(L, fun, nresults)
+  subroutine aot_fun_do(L, fun, nresults, ErrCode, ErrString)
     type(flu_state) :: L
     type(aot_fun_type) :: fun
-    integer :: nresults
+    integer, intent(in) :: nresults
+    integer, intent(out), optional :: ErrCode
+    character(len=*), intent(out), optional :: ErrString
 
-    integer :: errcode
+    integer :: err
 
     if (fun%handle /= 0) then
-      errcode = flu_pcall(L, fun%arg_count, nresults, 0)
+      err = flu_pcall(L, fun%arg_count, nresults, 0)
+      call aot_err_handler(L=L, err=err, msg="Failed aot_fun_do! ", &
+        &                  ErrCode = ErrCode, ErrString = ErrString)
       fun%arg_count = -1
     end if
   end subroutine aot_fun_do

source/aot_top_module.f90

 
   public :: aoterr_Fatal, aoterr_NonExistent, aoterr_WrongType
   public :: aot_top_get_val
+  public :: aot_err_handler
 
   !> Some parameters for the error handling.
   !!
   end subroutine aot_top_get_string
 
 
+  subroutine aot_err_handler(L, err, msg, ErrString, ErrCode)
+    type(flu_State) :: L
+    integer, intent(in) :: err
+    character(len=*), intent(in) :: msg
+    character(len=*), intent(out), optional :: ErrString
+    integer, intent(out), optional :: ErrCode
+
+    logical :: stop_on_error
+    character, pointer, dimension(:) :: string
+    integer :: str_len
+    integer :: i
+
+    stop_on_error = .not.(present(ErrString) .or. present(ErrCode))
+
+    if (present(ErrCode)) then
+      ErrCode = err
+    end if
+
+    if (err .ne. 0) then
+
+      string => flu_tolstring(L, -1, str_len)
+      if (present(ErrString)) then
+        do i=1,min(str_len, len(ErrString))
+          ErrString(i:i) = string(i)
+        end do
+      end if
+
+      if (stop_on_error) then
+        write(*,*) msg, string
+        STOP
+      end if
+
+    end if
+
+  end subroutine aot_err_handler
+
+
 end module aot_top_module

source/aotus_module.f90

     if (.not.flu_isopen(L)) L = fluL_newstate()
 
     err = fluL_loadfile(L, filename)
-    call aot_config_err_handler(L, err, 'Cannot load configuration file:', ErrString, ErrCode)
+    call aot_err_handler(L, err, 'Cannot load configuration file:', ErrString, &
+      &                  ErrCode)
 
     call fluL_openlibs(L)
 
     err = flu_pcall(L, 0, 0, 0)
-    call aot_config_err_handler(L, err, 'Cannot run configuration file:', ErrString, ErrCode)
+    call aot_err_handler(L, err, 'Cannot run configuration file:', ErrString, &
+      &                  ErrCode)
 
   end subroutine open_config_file
 
 
     err = fluL_loadstring(L, chunk)
 
-    call aot_config_err_handler(L, err, 'Cannot load chunk:', ErrString, ErrCode)
+    call aot_err_handler(L, err, 'Cannot load chunk:', ErrString, ErrCode)
 
     call fluL_openlibs(L)
 
     err = flu_pcall(L, 0, 0, 0)
 
-    call aot_config_err_handler(L, err, 'Cannot run chunk:', ErrString, ErrCode)
+    call aot_err_handler(L, err, 'Cannot run chunk:', ErrString, ErrCode)
 
   end subroutine open_config_chunk
 
-  subroutine aot_config_err_handler(L, err, msg, ErrString, ErrCode)
-
-    type(flu_State) :: L
-    integer, intent(in) :: err
-    character(len=*), intent(in) :: msg
-    character(len=*), intent(out), optional :: ErrString
-    integer, intent(out), optional :: ErrCode
-
-    logical :: stop_on_error
-    character, pointer, dimension(:) :: string
-    integer :: str_len
-    integer :: i
-
-    stop_on_error = .not.(present(ErrString) .or. present(ErrCode))
-
-    if (present(ErrCode)) then
-      ErrCode = err
-    end if
-
-    if (err .ne. 0) then
-
-      string => flu_tolstring(L, -1, str_len)
-      if (present(ErrString)) then
-        do i=1,min(str_len, len(ErrString))
-          ErrString(i:i) = string(i)
-        end do
-      end if
-
-      if (stop_on_error) then
-        write(*,*) msg, string
-        STOP
-      end if
-
-    end if
-
-  end subroutine aot_config_err_handler
-
-
 end module aotus_module