lua++
|
Lua wrapper. More...
#include <luapp_state.hpp>
Public Member Functions | |
state () | |
Constructor. | |
~state () | |
Destructor. | |
lua_State * | get_state () |
Return the associated Lua state. | |
std::string | conc_table (const std::string &sTable) |
Concatenates a Lua table into a string. | |
void | copy_table (state &mLua, const std::string &sSrcName, const std::string &sDestName="") |
Copy the content of a table from a Lua state to another. | |
void | do_file (const std::string &sFile) |
Executes a Lua file. | |
void | do_string (const std::string &sStr) |
Executes a string containing Lua instructions. | |
void | call_function (const std::string &sfunctionName) |
Executes a Lua function. | |
void | call_function (const std::string &sfunctionName, const std::vector< var > &lArgumentStack) |
Executes a Lua function with arguments. | |
void | reg (const std::string &sfunctionName, c_function mFunction) |
Binds a C++ function to a Lua function. | |
template<class T > | |
void | reg () |
regs a Lunar class to be used on this state. | |
void | print_error (const std::string &sError) |
Prints an error string in the log file with the Lua tag. | |
std::string | format_error (const std::string &sError) |
Formats a raw error string. | |
void | set_lua_error_function (c_function pFunc) |
Sets a custom error formatting function. | |
void | set_print_error_function (print_function pFunc) |
Sets a custom error printing function. | |
bool | is_serializable (int iIndex=-1) |
Checks if a variable is serializable. | |
std::string | serialize_global (const std::string &sName) |
Writes the content of a global variable in a string. | |
std::string | serialize (const std::string &sTab="", int iIndex=-1) |
Writes the content of a variable in a string. | |
void | push_number (const double &dValue) |
Puts a number on the stack. | |
void | push_bool (bool bValue) |
Puts a boolean on the stack. | |
void | push_string (const std::string &sValue) |
Puts a string on the stack. | |
void | push_var (const var &vValue) |
Puts a value on the stack. | |
void | pushValue (int iIndex) |
pushes a copy of the value at the given index on the stack. | |
void | push_nil (uint uiNumber=1) |
Puts "nil" (null) on the stack. | |
void | push_global (const std::string &sName) |
Puts the value of a global Lua variable on the stack. | |
template<class T > | |
T * | push_new () |
pushes a new Lunar object on the stack. | |
void | set_global (const std::string &sName) |
Sets the value of a global Lua variable. | |
void | new_table () |
Creates a new empty table and pushes it on the stack. | |
bool | next (int iIndex=-2) |
Iterates over the table at the given index. | |
void | pop (uint uiNumber=1) |
Removes the value at the top of the stack. | |
double | get_number (int iIndex=-1) |
Returns the value at the given index converted to a number. | |
bool | get_bool (int iIndex=-1) |
Returns the value at the given index converted to a bool. | |
std::string | get_string (int iIndex=-1) |
Returns the value at the given index converted to a string. | |
var | get_value (int iIndex=-1) |
Returns the value at the given index. | |
template<class T > | |
T * | get (int iIndex=-1) const |
Returns the Lunar object at the given index. | |
uint | get_top () |
Returns the number of value on the stack. | |
type | get_type (int iIndex=-1) |
Returns the type of the value on the stack. | |
std::string | get_type_name (type mType) |
Returns the name of a type. | |
void | get_global (const std::string &sName) |
Puts a global variable on the stack. | |
int | get_global_int (const std::string &sName, bool bCritical=true, int iDefaultValue=0) |
Reads an int from Lua. | |
double | get_global_double (const std::string &sName, bool bCritical=true, double dDefaultValue=0.0) |
Reads a float from Lua. | |
std::string | get_global_string (const std::string &sName, bool bCritical=true, const std::string &sDefaultValue="") |
Wrapper to read a string from Lua. | |
bool | get_global_bool (const std::string &sName, bool bCritical=true, bool bDefaultValue=false) |
Reads a bool from Lua. | |
void | get_field (const std::string &sName, int iIndex=-1) |
Puts a value from a Lua table on the stack. | |
void | get_field (int iID, int iIndex=-1) |
Puts a value from a Lua table on the stack. | |
int | get_field_int (const std::string &sName, bool bCritical=true, int iDefaultValue=0, bool bSetValue=false) |
Reads an int from a Lua table. | |
double | get_field_double (const std::string &sName, bool bCritical=true, double dDefaultValue=0.0, bool bSetValue=false) |
Reads a float from a Lua table. | |
std::string | get_field_string (const std::string &sName, bool bCritical=true, const std::string &sDefaultValue="", bool bSetValue=false) |
Reads a string from a Lua table. | |
bool | get_field_bool (const std::string &sName, bool bCritical=true, bool bDefaultValue=false, bool bSetValue=false) |
Reads a bool from a Lua table. | |
void | set_field (const std::string &sName) |
Writes a value into a Lua table. | |
void | set_field (int iID) |
Writes a value into a Lua table. | |
void | set_field_int (const std::string &sName, int iValue) |
Writes an int into a Lua table. | |
void | set_field_double (const std::string &sName, double dValue) |
Writes a float into a Lua table. | |
void | set_field_string (const std::string &sName, const std::string &sValue) |
Writes a string into a Lua table. | |
void | set_field_bool (const std::string &sName, bool bValue) |
Writes a bool into a Lua table. | |
void | set_field_int (int iID, int iValue) |
Writes an int into a Lua table. | |
void | set_field_double (int iID, double dValue) |
Writes a float into a Lua table. | |
void | set_field_string (int iID, const std::string &sValue) |
Writes a string into a Lua table. | |
void | set_field_bool (int iID, bool bValue) |
Writes a bool into a Lua table. | |
void | set_top (uint uiSize) |
Changes the stack size. | |
Static Public Member Functions | |
static state * | get_state (lua_State *pLua) |
Public Attributes | |
std::string | sComString |
Private Attributes | |
lua_State * | pLua_ |
c_function | pErrorFunction_ |
print_function | pPrintFunction_ |
Static Private Attributes | |
static std::map< lua_State *, state * > | lLuaStateMap_ |
Constructor.
Definition at line 42 of file luapp_state.cpp.
Destructor.
Definition at line 62 of file luapp_state.cpp.
void lua::state::call_function | ( | const std::string & | sfunctionName | ) |
Executes a Lua function.
sfunctionName | The name of the function to execute |
Definition at line 351 of file luapp_state.cpp.
void lua::state::call_function | ( | const std::string & | sfunctionName, |
const std::vector< var > & | lArgumentStack | ||
) |
Executes a Lua function with arguments.
sfunctionName | The name of the function to execute |
lArgumentStack | The agument stack (order matters) |
Definition at line 396 of file luapp_state.cpp.
std::string lua::state::conc_table | ( | const std::string & | sTable | ) |
Concatenates a Lua table into a string.
sTable | The name of the table in Lua |
Definition at line 84 of file luapp_state.cpp.
void lua::state::copy_table | ( | state & | mLua, |
const std::string & | sSrcName, | ||
const std::string & | sDestName = "" |
||
) |
Copy the content of a table from a Lua state to another.
mLua | The other Lua state into wich the table will be copied |
sSrcName | The name of the table in the source state |
sDestName | The name of the table in the destination state |
Definition at line 111 of file luapp_state.cpp.
void lua::state::do_file | ( | const std::string & | sFile | ) |
Executes a Lua file.
sFile | The name of the file |
Definition at line 251 of file luapp_state.cpp.
void lua::state::do_string | ( | const std::string & | sStr | ) |
Executes a string containing Lua instructions.
sStr | The string to execute |
Definition at line 306 of file luapp_state.cpp.
std::string lua::state::format_error | ( | const std::string & | sError | ) |
Formats a raw error string.
sError | The raw error string |
Definition at line 449 of file luapp_state.cpp.
T* lua::state::get | ( | int | iIndex = -1 | ) | const [inline] |
Returns the Lunar object at the given index.
iIndex | The index at which to search for the value |
Definition at line 252 of file luapp_state.hpp.
bool lua::state::get_bool | ( | int | iIndex = -1 | ) |
Returns the value at the given index converted to a bool.
iIndex | The index at which to search for the value |
Definition at line 731 of file luapp_state.cpp.
void lua::state::get_field | ( | const std::string & | sName, |
int | iIndex = -1 |
||
) |
Puts a value from a Lua table on the stack.
sName | The name of the key associated to the value |
iIndex | The position of the table in the stack |
Definition at line 986 of file luapp_state.cpp.
void lua::state::get_field | ( | int | iID, |
int | iIndex = -1 |
||
) |
Puts a value from a Lua table on the stack.
iID | The id of the key associated to the value |
iIndex | The position of the table in the stack |
Definition at line 997 of file luapp_state.cpp.
bool lua::state::get_field_bool | ( | const std::string & | sName, |
bool | bCritical = true , |
||
bool | bDefaultValue = false , |
||
bool | bSetValue = false |
||
) |
Reads a bool from a Lua table.
sName | The name of the key associated to the value |
bCritical | If 'true', an error will be printed if the variable is not found. Else, it will be assigned its default value |
bDefaultValue | The default value |
bSetValue | If 'true' and the key wasn't found in the table, this function will create that key in the Lua table and assign it its default value |
Definition at line 1124 of file luapp_state.cpp.
double lua::state::get_field_double | ( | const std::string & | sName, |
bool | bCritical = true , |
||
double | dDefaultValue = 0.0 , |
||
bool | bSetValue = false |
||
) |
Reads a float from a Lua table.
sName | The name of the key associated to the value |
bCritical | If 'true', an error will be printed if the variable is not found. Else, it will be assigned its default value |
dDefaultValue | The default value |
bSetValue | If 'true' and the key wasn't found in the table, this function will create that key in the Lua table and assign it its default value |
Definition at line 1049 of file luapp_state.cpp.
int lua::state::get_field_int | ( | const std::string & | sName, |
bool | bCritical = true , |
||
int | iDefaultValue = 0 , |
||
bool | bSetValue = false |
||
) |
Reads an int from a Lua table.
sName | The name of the key associated to the value |
bCritical | If 'true', an error will be printed if the variable is not found. Else, it will be assigned its default value |
iDefaultValue | The default value |
bSetValue | If 'true' and the key wasn't found in the table, this function will create that key in the Lua table and assign it its default value |
Definition at line 1012 of file luapp_state.cpp.
std::string lua::state::get_field_string | ( | const std::string & | sName, |
bool | bCritical = true , |
||
const std::string & | sDefaultValue = "" , |
||
bool | bSetValue = false |
||
) |
Reads a string from a Lua table.
sName | The name of the key associated to the value |
bCritical | If 'true', an error will be printed if the variable is not found. Else, it will be assigned its default value |
sDefaultValue | The default value |
bSetValue | If 'true' and the key wasn't found in the table, this function will create that key in the Lua table and assign it its default value |
Definition at line 1087 of file luapp_state.cpp.
void lua::state::get_global | ( | const std::string & | sName | ) |
Puts a global variable on the stack.
sName | The name of the global variable |
Definition at line 795 of file luapp_state.cpp.
bool lua::state::get_global_bool | ( | const std::string & | sName, |
bool | bCritical = true , |
||
bool | bDefaultValue = false |
||
) |
Reads a bool from Lua.
sName | The name of the variable (global scope) |
bCritical | If 'true', an error will be printed if the variable is not found. Else, it will be assigned its default value |
bDefaultValue | The default value |
Definition at line 951 of file luapp_state.cpp.
double lua::state::get_global_double | ( | const std::string & | sName, |
bool | bCritical = true , |
||
double | dDefaultValue = 0.0 |
||
) |
Reads a float from Lua.
sName | The name of the variable (global scope) |
bCritical | If 'true', an error will be printed if the variable is not found. Else, it will be assigned its default value |
dDefaultValue | The default value |
Definition at line 881 of file luapp_state.cpp.
int lua::state::get_global_int | ( | const std::string & | sName, |
bool | bCritical = true , |
||
int | iDefaultValue = 0 |
||
) |
Reads an int from Lua.
sName | The name of the variable (global scope) |
bCritical | If 'true', an error will be printed if the variable is not found. Else, it will be assigned its default value |
iDefaultValue | The default value |
Definition at line 846 of file luapp_state.cpp.
std::string lua::state::get_global_string | ( | const std::string & | sName, |
bool | bCritical = true , |
||
const std::string & | sDefaultValue = "" |
||
) |
Wrapper to read a string from Lua.
sName | The name of the variable (global scope) |
bCritical | If 'true', an error will be printed if the variable is not found. Else, it will be assigned its default value |
sDefaultValue | The default value |
Definition at line 916 of file luapp_state.cpp.
double lua::state::get_number | ( | int | iIndex = -1 | ) |
Returns the value at the given index converted to a number.
iIndex | The index at which to search for the value |
Definition at line 726 of file luapp_state.cpp.
lua_State * lua::state::get_state | ( | ) |
Return the associated Lua state.
Definition at line 79 of file luapp_state.cpp.
state * lua::state::get_state | ( | lua_State * | pLua | ) | [static] |
Definition at line 70 of file luapp_state.cpp.
std::string lua::state::get_string | ( | int | iIndex = -1 | ) |
Returns the value at the given index converted to a string.
iIndex | The index at which to search for the value |
Definition at line 736 of file luapp_state.cpp.
uint lua::state::get_top | ( | ) |
Returns the number of value on the stack.
Definition at line 753 of file luapp_state.cpp.
type lua::state::get_type | ( | int | iIndex = -1 | ) |
Returns the type of the value on the stack.
iIndex | The index of the value to analyse |
Definition at line 758 of file luapp_state.cpp.
std::string lua::state::get_type_name | ( | type | mType | ) |
Returns the name of a type.
mType | The type to serialize |
Definition at line 777 of file luapp_state.cpp.
var lua::state::get_value | ( | int | iIndex = -1 | ) |
Returns the value at the given index.
iIndex | The index at which to search for the value |
Definition at line 741 of file luapp_state.cpp.
bool lua::state::is_serializable | ( | int | iIndex = -1 | ) |
Checks if a variable is serializable.
iIndex | The index on the stack of the variable |
Definition at line 480 of file luapp_state.cpp.
void lua::state::new_table | ( | ) |
Creates a new empty table and pushes it on the stack.
Definition at line 692 of file luapp_state.cpp.
bool lua::state::next | ( | int | iIndex = -2 | ) |
Iterates over the table at the given index.
iIndex | The index of the table to iterate on |
Definition at line 703 of file luapp_state.cpp.
void lua::state::pop | ( | uint | uiNumber = 1 | ) |
Removes the value at the top of the stack.
uiNumber | The number of value to remove |
Definition at line 715 of file luapp_state.cpp.
void lua::state::print_error | ( | const std::string & | sError | ) |
Prints an error string in the log file with the Lua tag.
sError | The error string to output |
Definition at line 459 of file luapp_state.cpp.
void lua::state::push_bool | ( | bool | bValue | ) |
Puts a boolean on the stack.
bValue | The value to push on the stack |
Definition at line 595 of file luapp_state.cpp.
void lua::state::push_global | ( | const std::string & | sName | ) |
Puts the value of a global Lua variable on the stack.
sName | The name of this variable |
Definition at line 628 of file luapp_state.cpp.
T* lua::state::push_new | ( | ) | [inline] |
pushes a new Lunar object on the stack.
Definition at line 196 of file luapp_state.hpp.
void lua::state::push_nil | ( | uint | uiNumber = 1 | ) |
Puts "nil" (null) on the stack.
uiNumber | The number of "nil" to push |
Definition at line 605 of file luapp_state.cpp.
void lua::state::push_number | ( | const double & | dValue | ) |
Puts a number on the stack.
dValue | The value to push on the stack (converted to float) |
Definition at line 590 of file luapp_state.cpp.
void lua::state::push_string | ( | const std::string & | sValue | ) |
Puts a string on the stack.
sValue | The value to push on the stack |
Definition at line 600 of file luapp_state.cpp.
void lua::state::push_var | ( | const var & | vValue | ) |
Puts a value on the stack.
vValue | The value to push on the stack |
Definition at line 611 of file luapp_state.cpp.
void lua::state::pushValue | ( | int | iIndex | ) |
pushes a copy of the value at the given index on the stack.
iIndex | The index of the value to push |
Definition at line 623 of file luapp_state.cpp.
void lua::state::reg | ( | const std::string & | sfunctionName, |
c_function | mFunction | ||
) |
Binds a C++ function to a Lua function.
sfunctionName | The name of the Lua function |
mFunction | The C++ function to bind |
Definition at line 444 of file luapp_state.cpp.
void lua::state::reg | ( | ) | [inline] |
regs a Lunar class to be used on this state.
Definition at line 102 of file luapp_state.hpp.
std::string lua::state::serialize | ( | const std::string & | sTab = "" , |
int | iIndex = -1 |
||
) |
Writes the content of a variable in a string.
sTab | Number of space to put in front of each line |
iIndex | The index on the stack of the variable |
Definition at line 512 of file luapp_state.cpp.
std::string lua::state::serialize_global | ( | const std::string & | sName | ) |
Writes the content of a global variable in a string.
sName | The name of the global variable |
Definition at line 499 of file luapp_state.cpp.
void lua::state::set_field | ( | const std::string & | sName | ) |
Writes a value into a Lua table.
sName | The name of the key associated to the value |
Definition at line 1161 of file luapp_state.cpp.
void lua::state::set_field | ( | int | iID | ) |
Writes a value into a Lua table.
iID | The ID of the key associated to the value |
Definition at line 1175 of file luapp_state.cpp.
void lua::state::set_field_bool | ( | const std::string & | sName, |
bool | bValue | ||
) |
Writes a bool into a Lua table.
sName | The name of the key associated to the value |
bValue | The value to set |
Definition at line 1228 of file luapp_state.cpp.
void lua::state::set_field_bool | ( | int | iID, |
bool | bValue | ||
) |
Writes a bool into a Lua table.
iID | The ID of the key associated to the value |
bValue | The value to set |
Definition at line 1280 of file luapp_state.cpp.
void lua::state::set_field_double | ( | const std::string & | sName, |
double | dValue | ||
) |
Writes a float into a Lua table.
sName | The name of the key associated to the value |
dValue | The value to set |
Definition at line 1202 of file luapp_state.cpp.
void lua::state::set_field_double | ( | int | iID, |
double | dValue | ||
) |
Writes a float into a Lua table.
iID | The ID of the key associated to the value |
dValue | The value to set |
Definition at line 1254 of file luapp_state.cpp.
void lua::state::set_field_int | ( | const std::string & | sName, |
int | iValue | ||
) |
Writes an int into a Lua table.
sName | The name of the key associated to the value |
iValue | The value to set |
Definition at line 1189 of file luapp_state.cpp.
void lua::state::set_field_int | ( | int | iID, |
int | iValue | ||
) |
Writes an int into a Lua table.
iID | The ID of the key associated to the value |
iValue | The value to set |
Definition at line 1241 of file luapp_state.cpp.
void lua::state::set_field_string | ( | const std::string & | sName, |
const std::string & | sValue | ||
) |
Writes a string into a Lua table.
sName | The name of the key associated to the value |
sValue | The value to set |
Definition at line 1215 of file luapp_state.cpp.
void lua::state::set_field_string | ( | int | iID, |
const std::string & | sValue | ||
) |
Writes a string into a Lua table.
iID | The ID of the key associated to the value |
sValue | The value to set |
Definition at line 1267 of file luapp_state.cpp.
void lua::state::set_global | ( | const std::string & | sName | ) |
Sets the value of a global Lua variable.
sName | The name of this variable |
Definition at line 633 of file luapp_state.cpp.
void lua::state::set_lua_error_function | ( | c_function | pFunc | ) |
Sets a custom error formatting function.
pFunc | The error function |
Definition at line 464 of file luapp_state.cpp.
void lua::state::set_print_error_function | ( | print_function | pFunc | ) |
Sets a custom error printing function.
pFunc | The error printing function |
Definition at line 472 of file luapp_state.cpp.
void lua::state::set_top | ( | uint | uiSize | ) |
Changes the stack size.
uiSize | The new size of the stack |
Definition at line 1293 of file luapp_state.cpp.
std::map< lua_State *, state * > lua::state::lLuaStateMap_ [static, private] |
Definition at line 488 of file luapp_state.hpp.
c_function lua::state::pErrorFunction_ [private] |
Definition at line 492 of file luapp_state.hpp.
lua_State* lua::state::pLua_ [private] |
Definition at line 490 of file luapp_state.hpp.
print_function lua::state::pPrintFunction_ [private] |
Definition at line 493 of file luapp_state.hpp.
std::string lua::state::sComString |
Definition at line 482 of file luapp_state.hpp.