Lua abstraction layer that provides procedures for reading from and writing to the Lua stack.
The following example creates a new Lua state, then pushes an observation to and pulls it from the stack:
integer :: rc
type(lua_state_type) :: lua
type(observ_type) :: observ1, observ2
rc = dm_lua_init(lua) ! Initialise Lua interpreter.
call dm_lua_from(lua, observ1) ! Push observation onto stack.
rc = dm_lua_to(lua, observ2) ! Read observation back from stack.
call dm_lua_destroy(lua) ! Destroy Lua interpreter.
Pushes table element on stack and optionally returns value.
Returns allocatable 4-byte integer array from table field name
in
values
.
The function returns the following error codes:
E_ALLOC
if array allocation failed.E_EMPTY
if the field of given name is null.E_TYPE
if the field is not an integer array.On error, values
will be allocated but empty.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Table field name. |
||
integer(kind=i4), | intent(out), | allocatable | :: | values(:) |
Table field values. |
Returns allocatable 8-byte integer array from table field name
in
values
.
The function returns the following error codes:
E_ALLOC
if array allocation failed.E_EMPTY
if the field of given name is null.E_TYPE
if the field is not an integer array.On error, values
will be allocated but empty.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Table field name. |
||
integer(kind=i8), | intent(out), | allocatable | :: | values(:) |
Table field values. |
Returns allocatable character array from table field name
in
values
. If values
is allocated, it will be deallocated first.
The function returns the following error codes:
E_ALLOC
if array allocation failed.E_EMPTY
if the field of given name is null.E_BOUNDS
if a string length is greater than the array length.E_TYPE
if not a table or not a string element.On error, values
will be allocated but empty.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Table field name. |
||
character(len=*), | intent(inout), | allocatable | :: | values(:) |
Table field values. |
|
logical, | intent(in), | optional | :: | unescape |
Unescape strings. |
Returns 4-byte integer from table field name
in value
.
The function returns the following error codes:
E_EMPTY
if the field of given name is null.E_TYPE
if the field is not of type integer.On error, value
will not be overwritten.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Table field name. |
||
integer(kind=i4), | intent(inout) | :: | value |
Table field value. |
Returns 8-byte integer from table field name
in value
.
The function returns the following error codes:
E_EMPTY
if the field of given name is null.E_TYPE
if the field is not of type integer.On error, value
will not be overwritten.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Table field name. |
||
integer(kind=i8), | intent(inout) | :: | value |
Table field value. |
Returns logical from table field name
in value
.
The function returns the following error codes:
E_EMPTY
if the field of given name is null.E_TYPE
if the field is not of type boolean.On error, value
will not be overwritten.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Table field name. |
||
logical, | intent(inout) | :: | value |
Table field value. |
Returns 8-byte real from table field name
in value
.
The function returns the following error codes:
E_EMPTY
if the field of given name is null.E_TYPE
if the field is not of type number.On error, value
will not be overwritten.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Table field name. |
||
real(kind=r8), | intent(inout) | :: | value |
Table field value. |
Pushes table field of given name on stack.
The function returns the following error codes:
E_EMPTY
if the field of given name is null.Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Field name. |
Returns character string from table field name
in value
. If
unescape
is passed and .true.
, the returned string will have all
occurences of \\
replaced by \
.
The function returns the following error codes:
E_EMPTY
if the field of given name is null.E_BOUNDS
if the actual string length is greater than the length
of the passed value argument.E_TYPE
if the field is not of type string.On error, value
will not be overwritten.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Table field name. |
||
character(len=*), | intent(inout) | :: | value |
Table field value. |
||
logical, | intent(in), | optional | :: | unescape |
Unescape the string. |
Pushes table index on stack and optionally returns value.
Returns 4-byte integer from table element i
in value
.
The function returns the following error codes:
E_EMPTY
if the table element of given name is null.E_INVALID
if the element on top of the stack is not a table.E_TYPE
if the table element is not of type integer.On error, value
will not be overwritten.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in) | :: | i |
Variable index. |
||
integer, | intent(inout) | :: | value |
Variable value. |
Returns 8-byte integer from table element i
in value
.
The function returns the following error codes:
E_EMPTY
if the table element of given name is null.E_INVALID
if the element on top of the stack is not a table.E_TYPE
if the table element is not of type integer.On error, value
will not be overwritten.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in) | :: | i |
Variable index. |
||
integer(kind=i8), | intent(inout) | :: | value |
Variable value. |
Returns logical from table element i
in value
.
The function returns the following error codes:
E_EMPTY
if the table element of given name is null.E_INVALID
if the element on top of the stack is not a table.E_TYPE
if the table element is not of type boolean.On error, value
will not be overwritten.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in) | :: | i |
Variable index. |
||
logical, | intent(inout) | :: | value |
Variable value. |
Returns 8-byte real from table element i
in value
.
The function returns the following error codes:
E_EMPTY
if the table element of given name is null.E_INVALID
if the element on top of the stack is not a table.E_TYPE
if the table element is not of type number.On error, value
will not be overwritten.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in) | :: | i |
Variable index. |
||
real(kind=r8), | intent(inout) | :: | value |
Variable value. |
Pushes table element at index i
on stack.
The function returns the following error codes:
E_INVALID
if the element on top of the stack is not a table.E_EMPTY
if the table is empty.Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in) | :: | i |
Variable index. |
Returns character string from table element i
in value
. If
unescape
is passed and .true.
, the returned string will have all
occurences of \\
replaced by \
.
The function returns the following error codes:
E_EMPTY
if the table element of given name is null.E_INVALID
if the element on top of the stack is not a table.E_BOUNDS
if the actual string length is greater than the length
of the passed value argument.E_TYPE
if the table element is not of type string.On error, value
will not be overwritten.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in) | :: | i |
Variable index. |
||
character(len=*), | intent(inout) | :: | value |
Variable value. |
||
logical, | intent(in), | optional | :: | unescape |
Unescape string. |
Converts derived types to Lua table on stack.
Pushes observation on Lua stack.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
type(observ_type), | intent(inout) | :: | observ |
Observation type. |
Pushes request on Lua stack.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
type(request_type), | intent(inout) | :: | request |
Request type. |
Pushes global variable on stack and optionally returns value.
Returns the values of global variable as 4-byte integers.
The function returns the following error codes:
E_ALLOC
if array allocation failed.E_TYPE
if variable is not an integer table.Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Variable name. |
||
integer(kind=i4), | intent(out), | allocatable | :: | values(:) |
Variable values. |
Returns the values of global variable as 8-byte integers.
The function returns the following error codes:
E_ALLOC
if array allocation failed.E_TYPE
if variable is not an integer table.Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Variable name. |
||
integer(kind=i8), | intent(out), | allocatable | :: | values(:) |
Variable values. |
Returns the value of global variable as 4-byte integer. The
function returns E_TYPE
if the variable is not of type integer.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Variable name. |
||
integer(kind=i4), | intent(inout) | :: | value |
Variable value. |
Returns the value of global variable as 8-byte integer. The
function returns E_TYPE
if the variable is not of type integer.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Variable name. |
||
integer(kind=i8), | intent(inout) | :: | value |
Variable value. |
Returns the value of global variable as logical. The function
returns E_TYPE
if the variable is not of type boolean.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Variable name. |
||
logical, | intent(inout) | :: | value |
Variable value. |
Returns the value of global variable as 8-byte real. The function
returns E_TYPE
if the variable is not of type number.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Variable name. |
||
real(kind=r8), | intent(inout) | :: | value |
Variable value. |
Pushes global variable on stack. Returns E_EMPTY
if the variable
does not exist.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Variable name. |
Returns the value of global variable as allocatable string. The
function returns E_TYPE
if the variable is not of type string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Variable name. |
||
character(len=*), | intent(inout) | :: | value |
Variable value. |
Sets 4-byte integer variable of given name.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Name of variable |
||
integer(kind=i4), | intent(in) | :: | value |
Value of variable. |
Converts Lua table to Fortran derived type.
Reads Lua table into Fortran job type. The table has to be on top of the stack and will be removed once finished.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
type(job_type), | intent(out) | :: | job |
Job type. |
Reads Lua table into Fortran job list. The table has to be on top of the stack and will be removed once finished.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
type(job_list_type), | intent(out) | :: | job_list |
Job list type. |
Reads Lua table into Fortran jobs type array. The table has to be on top of the stack and will be removed once finished.
The functions returns the following error codes:
E_ALLOC
if the array allocation failed.E_EMPTY
if the table is empty.E_TYPE
if the stack element is not a table.Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
type(job_type), | intent(out), | allocatable | :: | jobs(:) |
Job type array. |
Reads Lua table into Fortran observation type. The table has to be on top of the stack and will be removed once finished.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
type(observ_type), | intent(out) | :: | observ |
Observation type. |
Reads Lua table into Fortran observation type array. The table has to be on top of the stack and will be removed once finished.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
type(observ_type), | intent(out), | allocatable | :: | observs(:) |
Observation type array. |
Reads Lua table into Fortran report type. The table has to be on top of the stack and will be removed once finished.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
type(report_type), | intent(out) | :: | report |
Report type. |
Reads Lua table into Fortran request type. The table has to be on top of the stack and will be removed once finished.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
type(request_type), | intent(out) | :: | request |
Request type. |
C-interoperable Lua callback function.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in), | value | :: | ptr |
Lua state pointer. |
Return value.
Lua state type that stores the Lua pointer.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(c_ptr), | public | :: | ctx | = | c_null_ptr |
C pointer to Lua interpreter. |
Calls Lua function on top of stack.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in) | :: | nargs |
Number of arguments. |
||
integer, | intent(in) | :: | nresults |
Number of results. |
Converts Lua error code to DMPACK error code.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | lua_error |
Lua error code. |
Returns last error message as allocatable character string or an empty string if no message is available.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
Last error message.
Escapes passed character string by replacing each occurance of \
with \\
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | str |
String to escape. |
Escaped string.
Executes Lua command passed in character string command
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | command |
Lua command to evaluate. |
Executes Lua script.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | file_path |
Path to Lua script file. |
Initialises Lua interpreter and opens libraries, unless libs
is
.false.
. Returns E_EXIST
if the Lua pointer is already
associated, and E_LUA
if one of the Lua calls failed.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
logical, | intent(in), | optional | :: | libs |
Open Lua libraries. |
Returns .true.
if element on top of stack is of type function.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
Returns .true.
if element on top of stack is nil.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
Returns .true.
if pointer to Lua interpreter is associated.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
Returns .true.
if element on top of stack is of type table.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
Opens Lua script and executes it by default. The function returns the following error codes:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | file_path |
Path to Lua script. |
||
logical, | intent(in), | optional | :: | eval |
Evaluate script once. |
Loads global table of given name. The function returns the following error codes:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Name of table. |
||
integer, | intent(out), | optional | :: | n |
Number of elements in table. |
Returns size of table on stack. Returns -1
on error.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
Returns 4-byte integer from Lua stack at position idx
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in) | :: | idx |
Stack index. |
Returns 8-byte integer from Lua stack at position idx
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in) | :: | idx |
Stack index. |
Returns 8-byte integer from Lua stack at position idx
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in) | :: | idx |
Stack index. |
Returns 4-byte real from Lua stack at position idx
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in) | :: | idx |
Stack index. |
Returns 8-byte real from Lua stack at position idx
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in) | :: | idx |
Stack index. |
Returns allocatable character string from Lua stack at position idx
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in) | :: | idx |
Stack index. |
String value.
Unescapes passed character string by replacing each occurance of
\\
with \
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | str |
String to escape. |
Unescaped string.
Returns Lua version as allocatable string of the form 5.4
or
liblua/5.4
if argument name
is .true.
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in), | optional | :: | name |
Add prefix |
Closes Lua.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
Dumps stack to standard output or file unit.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in), | optional | :: | unit |
File unit. |
Pops element on stack.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(in), | optional | :: | n |
Stack position. |
Registers a new Lua command.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
character(len=*), | intent(in) | :: | name |
Lua procedure name. |
||
procedure(dm_lua_callback) | :: | proc |
C-interoperable subroutine to call. |
Returns Lua version number.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lua_state_type), | intent(inout) | :: | lua |
Lua type. |
||
integer, | intent(out) | :: | major |
Major version number. |
||
integer, | intent(out) | :: | minor |
Minor version number. |