LuaScript¶
-
class
rlogic
::
LuaScript
: public rlogic::LogicNode¶ The LuaScript class is the cornerstone of RAMSES Logic as it encapsulates a Lua script and the associated with it Lua environment. LuaScript instances are created by the rlogic::LogicEngine class.
A LuaScript can be created from Lua source code which must fulfill following requirements:
valid Lua 5.1 syntax
contains two global functions - interface() and run() with no parameters and no return values
declares its inputs and outputs in the interface() function, and its logic in the run() function
the interface() function declares zero or more inputs and outputs to the IN and OUT global symbols
inputs and outputs are declared like this:
function interface() IN.input_name = TYPE OUT.output_name = TYPE end
TYPE is one of [INT|FLOAT|BOOL|STRING|VEC2F|VEC3F|VEC4F|VEC2I|VEC3I|VEC4I], or…
TYPE can be also a Lua table with nested properties, obeying the same rules as above, or…
TYPE can be an array declaration of the form ARRAY(n, T) where:
n is a positive integer
T obeys the same rules as TYPE, except T can not be an ARRAY itself
T can be a struct, i.e. arrays of structs are supported
Each property must have a name (string) - other types like number, bool etc. are not supported as keys
the run() function only accesses the IN and OUT global symbols and the properties defined by it
Violating any of these requirements will result in errors, which can be obtained by calling rlogic::LogicEngine::getErrors(). The LuaScript object encapsulates a Lua environment (see official Lua docs) which strips all global table entries after the script is loaded to the Lua state, and leaves only the run() function.
See also the full documentation at https://ramses-logic.readthedocs.io/en/latest/api.html for more details on Lua and its interaction with C++.
Public Functions
-
std::string_view
getFilename
() const¶ Returns the filename provided when the script was created
- Return
the filename of the script
-
void
overrideLuaPrint
(LuaPrintFunction luaPrintFunction)¶ Overrides the lua print function with a custom function. Each time “print” is used inside a lua script, the function will be called. Because the lua “print” function allows an arbitrary amount of parameters, the function is called for each provided parameter.
- Parameters
luaPrintFunction
: to use for printing
-
LuaScript
(std::unique_ptr<internal::LuaScriptImpl> impl) noexcept¶ Constructor of LuaScript. User is not supposed to call this - script are created by other factory classes
- Parameters
impl
: implementation details of the script
-
LuaScript
(const LuaScript &other) = delete¶ Copy Constructor of LuaScript is deleted because scripts are not supposed to be copied
- Parameters
other
: script to copy from
-
LuaScript
(LuaScript &&other) = delete¶ Move Constructor of LuaScript is deleted because scripts are not supposed to be moved
- Parameters
other
: script to move from