Represents a single Lua runtime.
More...
#include <Runtime.hpp>
|
enum class | ErrorCode {
None
, TypeMismatch
, VariableDoesntExist
, NotFunction
,
FunctionError
} |
|
template<typename T > |
using | Result = Util::Result<T, Util::Error<ErrorCode>> |
|
|
SL_SYMBOL | Runtime (const std::string &filename) |
| Construct a Lua runtime from a script.
|
|
SL_SYMBOL | Runtime (Runtime &&r) |
|
| Runtime (const Runtime &)=delete |
|
SL_SYMBOL Result< void > | registerFunction (const std::string &table_name, const std::string &func_name, SL::Function function) |
| Registers a C++ function for use in the Lua runtime.
|
|
template<typename T > |
SL_SYMBOL Result< T > | getGlobal (const std::string &name) |
| Get a global variable by name from runtime.
|
|
template<typename T > |
SL_SYMBOL Result< void > | setGlobal (const std::string &name, const T &value) |
| Set a global variable from a value to a name.
|
|
template<typename... Return, typename... Args> |
Result< std::tuple< Return... > > | runFunction (const std::string &name, Args &&... args) |
| Invokes a Lua function from this environment.
|
|
SL_SYMBOL bool | good () const |
|
SL_SYMBOL | operator bool () const |
|
const auto & | filename () const |
|
|
template<typename... Libraries> |
static Runtime | create (const std::string &filename) |
| Creates a runtime with the given Libraries loaded into it.
|
|
Represents a single Lua runtime.
◆ Runtime()
SL_SYMBOL SL::Runtime::Runtime |
( |
const std::string & | filename | ) |
|
Construct a Lua runtime from a script.
- Parameters
-
filename | File path to the script |
◆ create()
template<typename... Libraries>
Runtime SL::Runtime::create |
( |
const std::string & | filename | ) |
|
|
static |
Creates a runtime with the given Libraries loaded into it.
- Template Parameters
-
Libraries | List of library types that are derived from SL::Lib::Base. |
- Parameters
-
filename | Name of the file to load into the runtime |
- Returns
- Runtime The created runtime
◆ getGlobal()
template<typename T >
SL_SYMBOL Result< T > SL::Runtime::getGlobal |
( |
const std::string & | name | ) |
|
Get a global variable by name from runtime.
- Template Parameters
-
T | Type of the global variable (supported types in Lua namespace) |
- Parameters
-
name | Name of the variable in the script |
- Returns
- Result<T> The value of the variable or error
◆ registerFunction()
SL_SYMBOL Result< void > SL::Runtime::registerFunction |
( |
const std::string & | table_name, |
|
|
const std::string & | func_name, |
|
|
SL::Function | function ) |
Registers a C++ function for use in the Lua runtime.
- Parameters
-
table_name | Name of the table to register function in |
func_name | Name of the function to call in Lua |
function | Pointer to a static function |
- Returns
- Result<void> Returns if an error has occured
◆ runFunction()
template<typename... Return, typename... Args>
Runtime::Result< std::tuple< Return... > > SL::Runtime::runFunction |
( |
const std::string & | name, |
|
|
Args &&... | args ) |
|
inline |
Invokes a Lua function from this environment.
- Template Parameters
-
Return | Expected return types from the function |
Args | Arguments to pass into the function |
- Parameters
-
name | Name of the function |
args | Values of the arguments |
- Returns
- Result<std::tuple<Return...>> Contains the values returned from the function or error
◆ setGlobal()
template<typename T >
SL_SYMBOL Result< void > SL::Runtime::setGlobal |
( |
const std::string & | name, |
|
|
const T & | value ) |
Set a global variable from a value to a name.
- Template Parameters
-
T | Type of the global variable (supported types in Lua namespace) |
- Parameters
-
name | Name of the global variable |
value | Value of the global variable |
- Returns
- Result<void> The status of the operation
The documentation for this struct was generated from the following file:
- /Users/runner/work/simple-lua/simple-lua/include/SL/Lua/Runtime.hpp