aot_file_to_buffer Subroutine

public subroutine aot_file_to_buffer(filename, buffer, ErrCode, ErrString)

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.

Arguments

Type IntentOptional 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.


Calls

proc~~aot_file_to_buffer~~CallsGraph proc~aot_file_to_buffer aot_file_to_buffer interface~flu_dump flu_dump proc~aot_file_to_buffer->interface~flu_dump proc~aot_err_handler aot_err_handler proc~aot_file_to_buffer->proc~aot_err_handler proc~close_config close_config proc~aot_file_to_buffer->proc~close_config proc~flul_loadfile fluL_loadfile proc~aot_file_to_buffer->proc~flul_loadfile proc~flul_newstate fluL_newstate proc~aot_file_to_buffer->proc~flul_newstate proc~flu_dump_tobuf flu_dump_toBuf interface~flu_dump->proc~flu_dump_tobuf proc~flu_tolstring flu_tolstring proc~aot_err_handler->proc~flu_tolstring proc~flu_close flu_close proc~close_config->proc~flu_close interface~lual_loadfilex luaL_loadfilex proc~flul_loadfile->interface~lual_loadfilex interface~lual_newstate luaL_newstate proc~flul_newstate->interface~lual_newstate interface~lua_close lua_close proc~flu_close->interface~lua_close interface~dump_lua_tobuf dump_lua_toBuf proc~flu_dump_tobuf->interface~dump_lua_tobuf interface~lua_tolstring lua_tolstring proc~flu_tolstring->interface~lua_tolstring

Source Code

  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