![]() |
GenericContainer
GenericContaine a tool for C++ programming
|
This module provides integration between the GenericContainer
and Lua.
More...
Classes | |
class | GC_namespace::LuaInterpreter |
A class implementing a simple Lua interpreter. More... | |
Functions | |
void | GC_namespace::Lua_global_to_GC (void *void_L, char const *global_var, GenericContainer &gc) |
Convert a Lua global variable to a GenericContainer . | |
void | GC_namespace::Lua_GC_to_global (void *void_L, GenericContainer const &gc, char const *global_var) |
Convert a GenericContainer to a Lua global variable. | |
This module provides integration between the GenericContainer
and Lua.
The GC_namespace
offers functionality to convert Lua global variables to and from a GenericContainer
object, as well as execute Lua scripts using the LuaInterpreter
class.
This tutorial explains how to use the Lua interface in the GC_namespace
for working with Lua global variables and GenericContainer
objects. It covers how to convert Lua global variables into a GenericContainer
object and how to set Lua global variables from a GenericContainer
. Additionally, the tutorial introduces the LuaInterpreter
class for executing Lua code from C++.
The function Lua_global_to_GC
allows you to retrieve a Lua global variable and convert it into a GenericContainer
object. This is useful when you want to access Lua variables in C++ and perform operations using GenericContainer
's versatile structure.
Example:
The function Lua_GC_to_global
is the reverse operation of Lua_global_to_GC
. It allows you to take a GenericContainer
object and store its data in a Lua global variable. This is helpful when you need to pass C++ data structures into Lua.
Example:
The LuaInterpreter
class provides a simple interface for interacting with Lua scripts and commands from C++. It can execute Lua commands, call Lua functions, and work with Lua global variables and GenericContainer
.
The LuaInterpreter
class manages a Lua interpreter (lua_State
) internally. You can create an instance of this class to load Lua scripts, execute Lua commands, and access Lua variables.
Example of initializing the interpreter and running Lua commands:
The LuaInterpreter::execute
function allows you to execute a Lua command string. This function is useful for executing arbitrary Lua code from your C++ application.
Example:
The LuaInterpreter::do_file
function loads and executes a Lua script file. This is commonly used for configuration scripts or any Lua script file you want to run.
Example:
The LuaInterpreter::call
function allows you to call a Lua function with arguments provided by a GenericContainer
. The result of the Lua function is returned in another GenericContainer
.
The arguments
container should have the following fields:
"function"
: A string containing the name of the Lua function to be called."args"
: A GenericContainer
containing the function's arguments.Example:
void GC_namespace::Lua_GC_to_global | ( | void * | void_L, |
GenericContainer const & | gc, | ||
char const * | global_var ) |
Convert a GenericContainer
to a Lua global variable.
This function converts the contents of a GenericContainer
and stores it in a Lua global variable. It allows passing data from C++ to Lua.
[in] | void_L | Pointer to the Lua interpreter (lua_State). |
[in] | gc | The GenericContainer to be converted. |
[in] | global_var | Name of the Lua global variable where the result will be stored. |
void GC_namespace::Lua_global_to_GC | ( | void * | void_L, |
char const * | global_var, | ||
GenericContainer & | gc ) |
Convert a Lua global variable to a GenericContainer
.
This function retrieves the value of a Lua global variable and converts it into a GenericContainer
object. This allows easy access to Lua data from C++.
[in] | void_L | Pointer to the Lua interpreter (lua_State). |
[in] | global_var | Name of the Lua global variable to convert. |
[out] | gc | The resulting GenericContainer . |