open_config_file Subroutine

public subroutine open_config_file(L, filename, ErrCode, ErrString, buffer)

Subroutine to load and execute a script from a file.

If you are using MPI for parallelization, have a look at the tem_open_distconf routine in the treelm library instead.

Arguments

Type IntentOptional Attributes Name
type(flu_State) :: L

Handle to the Lua script

character(len=*), intent(in) :: filename

Name of file to load the Lua code from

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.

type(cbuf_type), intent(out), optional :: buffer

Optional argument to return the compiled script after loading it to the caller.

It might be handy to reuse the loaded script later on, this argument allows you to obtain the script in compiled form, before it is executed. The buffer will be allocated and filled with the Lua data. It contains the actual string in buffer%buffer which is a character pointer, and the original c_ptr to this


Calls

proc~~open_config_file~~CallsGraph proc~open_config_file open_config_file interface~flu_dump flu_dump proc~open_config_file->interface~flu_dump proc~aot_err_handler aot_err_handler proc~open_config_file->proc~aot_err_handler proc~flu_isopen flu_isopen proc~open_config_file->proc~flu_isopen proc~flu_pcall flu_pcall proc~open_config_file->proc~flu_pcall proc~flul_loadfile fluL_loadfile proc~open_config_file->proc~flul_loadfile proc~flul_newstate fluL_newstate proc~open_config_file->proc~flul_newstate proc~flul_openlibs fluL_openlibs proc~open_config_file->proc~flul_openlibs 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 interface~lua_pcallk lua_pcallk proc~flu_pcall->interface~lua_pcallk interface~lual_loadfilex luaL_loadfilex proc~flul_loadfile->interface~lual_loadfilex interface~lual_newstate luaL_newstate proc~flul_newstate->interface~lual_newstate interface~lual_openlibs luaL_openlibs proc~flul_openlibs->interface~lual_openlibs 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

Called by

proc~~open_config_file~~CalledByGraph proc~open_config_file open_config_file proc~aot_path_open_table aot_path_open_table proc~aot_path_open_table->proc~open_config_file interface~aot_path_open aot_path_open interface~aot_path_open->proc~aot_path_open_table proc~aot_path_open_fun aot_path_open_fun interface~aot_path_open->proc~aot_path_open_fun proc~aot_path_open_fun->proc~aot_path_open_table

Source Code

  subroutine open_config_file(L, filename, ErrCode, ErrString, buffer)
    type(flu_State) :: L !! Handle to the Lua script

    !> Name of file to load the Lua code from
    character(len=*), intent(in) :: filename

    !> 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

    !> Optional argument to return the compiled script after loading it to
    !! the caller.
    !!
    !! It might be handy to reuse the loaded script later on, this argument
    !! allows you to obtain the script in compiled form, before it is executed.
    !! The buffer will be allocated and filled with the Lua data.
    !! It contains the actual string in buffer%buffer which is a character
    !! pointer, and the original c_ptr to this
    type(cbuf_type), intent(out), optional :: buffer

    integer :: err
    integer :: length

    if (.not.flu_isopen(L)) L = fluL_newstate()

    err = fluL_loadfile(L, filename)
    call aot_err_handler(L, err, 'Cannot load configuration file:', ErrString, &
      &                  ErrCode)

    if (err == 0) then
      if (present(buffer)) then
        call flu_dump(L, buffer, length, err)
      end if
      call fluL_openlibs(L)

      err = flu_pcall(L, 0, 0, 0)
      call aot_err_handler(L, err, 'Cannot run configuration file:',  &
        &                  ErrString, ErrCode)
    end if

  end subroutine open_config_file