Subroutine to load a script from a file and put it into a character buffer.
This is useful to rerun a given code in a file without the need to touch the file itself again.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | filename | Name of file to load the Lua code from |
||
type(cbuf_type), | intent(out) | :: | buffer | Buffer to store the script in the given file in |
||
integer, | intent(out), | optional | :: | ErrCode | Error code returned by Lua during loading or executing the file. This optional parameter might be used to react on errors in the calling side. If neither ErrCode nor ErrString are given, this subroutine will stop the program execution and print the error message from Lua to the stdout. |
|
character(len=*), | intent(out), | optional | :: | ErrString | Obtained error description from the Lua stack. This optional argument holds the Lua error message in case somehting went wrong. It can be used to provide some feedback to the user in the calling routine. If neither ErrCode nor ErrString are provided, open_config() will print the error message and stop program execution. |
subroutine aot_file_to_buffer(filename, buffer, ErrCode, ErrString)
!> Name of file to load the Lua code from
character(len=*), intent(in) :: filename
!> Buffer to store the script in the given file in
type(cbuf_type), intent(out) :: buffer
!> Error code returned by Lua during loading or executing the file.
!!
!! This optional parameter might be used to react on errors in the calling
!! side. If neither ErrCode nor ErrString are given, this subroutine will
!! stop the program execution and print the error message from Lua to the
!! stdout.
integer, intent(out), optional :: ErrCode
!> Obtained error description from the Lua stack.
!!
!! This optional argument holds the Lua error message in case somehting
!! went wrong. It can be used to provide some feedback to the user in the
!! calling routine. If neither ErrCode nor ErrString are provided,
!! open_config() will print the error message and stop program execution.
character(len=*), intent(out), optional :: ErrString
type(flu_State) :: L
integer :: err
integer :: buflen
L = fluL_newstate()
err = fluL_loadfile(L, filename)
call aot_err_handler(L, err, 'Cannot load configuration file:', ErrString, &
& ErrCode)
if (err == 0) then
call flu_dump(L = L, buf = buffer, length = buflen, iError = err)
if (err /= 0) then
if (present(ErrCode)) then
ErrCode = err
if (present(ErrString)) then
ErrString = 'Error while dumping the Lua script into a buffer!'
end if
else
write(*,*) 'Error while dumping the Lua script into a buffer!'
write(*,*) 'STOPPING'
STOP
end if
end if
end if
call close_config(L)
end subroutine aot_file_to_buffer