lua++
|
A helper to write Lua glues. More...
#include <luapp_function.hpp>
Public Member Functions | |
function (const std::string &sName, lua_State *pLua, uint uiReturnNbr=0u) | |
Default constructor. | |
function (const std::string &sName, state *pLua, uint uiReturnNbr=0u) | |
Default constructor. | |
~function () | |
Destructor. | |
void | add (uint uiIndex, const std::string &sName, type mLuaType, bool bOptional=false) |
Adds an argument to that function. | |
void | new_param_set () |
Tells the function there is another parameter set that will be provided. | |
uint | get_param_set_rank () |
Returns the indice of the paramater set that the user has provided. | |
bool | check (bool bPrintError=true) |
Checks if all the arguments types and retreive them. | |
utils::wptr< argument > | get (uint uiIndex) |
Returns the argument at the provided index. | |
bool | is_provided (uint uiIndex) const |
Checks if an argument has been provided (in case it is optional). | |
uint | get_argument_count () const |
Returns the number of provided arguments. | |
void | push (const var &vValue) |
Adds a return value. | |
void | push_nil (uint uiNbr=1) |
Adds nil to the return values. | |
void | notify_pushed () |
Tells this function you pushed a return value. | |
int | on_return () |
ends the function. | |
const std::string & | get_name () const |
Returns the name of this function. | |
state * | get_state () const |
Returns the state used by this function. | |
Private Attributes | |
std::string | sName_ |
state * | pLua_ |
uint | uiArgumentCount_ |
uint | uiReturnNbr_ |
uint | uiReturnCount_ |
std::vector< argument_list > | lArgListStack_ |
argument_list * | pArgList_ |
A helper to write Lua glues.
A glue is a C++ function that is executed in Lua. Due to the way Lua communicates with C++, creating such functions can become boring if you check every argument's type, or if you allow optional arguments, or even two possible types for a single argument.
This is done quite easilly with this class.
Look at the source code for existing glues to see how things work (UIObject::_SetPoint() is a good example).
Definition at line 172 of file luapp_function.hpp.
lua::function::function | ( | const std::string & | sName, |
lua_State * | pLua, | ||
uint | uiReturnNbr = 0u |
||
) |
Default constructor.
sName | The name of your function (used to print errors in the log) |
pLua | The Lua state to use |
uiReturnNbr | The maximum number of returned values |
Definition at line 13 of file luapp_function.cpp.
lua::function::function | ( | const std::string & | sName, |
state * | pLua, | ||
uint | uiReturnNbr = 0u |
||
) |
Default constructor.
sName | The name of your function (used to print errors in the log) |
pLua | The Lua state to use |
uiReturnNbr | The maximum number of returned values |
Definition at line 20 of file luapp_function.cpp.
Destructor.
Definition at line 26 of file luapp_function.cpp.
void lua::function::add | ( | uint | uiIndex, |
const std::string & | sName, | ||
type | mLuaType, | ||
bool | bOptional = false |
||
) |
Adds an argument to that function.
uiIndex | The index of this argument |
sName | The name of this argument (used to print errors in the log) |
mLuaType | The expected type in Lua |
bOptional | 'true' if this argument is not essential and can be ommited |
Definition at line 43 of file luapp_function.cpp.
bool lua::function::check | ( | bool | bPrintError = true | ) |
Checks if all the arguments types and retreive them.
bPrintError | If set to 'false', this function will fail silently |
Definition at line 108 of file luapp_function.cpp.
utils::wptr< argument > lua::function::get | ( | uint | uiIndex | ) |
Returns the argument at the provided index.
uiIndex | The index of the argument |
Definition at line 73 of file luapp_function.cpp.
uint lua::function::get_argument_count | ( | ) | const |
Returns the number of provided arguments.
Definition at line 103 of file luapp_function.cpp.
const std::string & lua::function::get_name | ( | ) | const |
Returns the name of this function.
Definition at line 270 of file luapp_function.cpp.
uint lua::function::get_param_set_rank | ( | ) |
Returns the indice of the paramater set that the user has provided.
Definition at line 68 of file luapp_function.cpp.
state * lua::function::get_state | ( | ) | const |
Returns the state used by this function.
Definition at line 321 of file luapp_function.cpp.
bool lua::function::is_provided | ( | uint | uiIndex | ) | const |
Checks if an argument has been provided (in case it is optional).
uiIndex | The index of the argument |
Definition at line 87 of file luapp_function.cpp.
void lua::function::new_param_set | ( | ) |
Tells the function there is another parameter set that will be provided.
Definition at line 61 of file luapp_function.cpp.
void lua::function::notify_pushed | ( | ) |
Tells this function you pushed a return value.
Definition at line 298 of file luapp_function.cpp.
int lua::function::on_return | ( | ) |
ends the function.
Definition at line 306 of file luapp_function.cpp.
void lua::function::push | ( | const var & | vValue | ) |
Adds a return value.
vValue | One of the returned value |
Definition at line 275 of file luapp_function.cpp.
void lua::function::push_nil | ( | uint | uiNbr = 1 | ) |
Adds nil to the return values.
uiNbr | The number of nil to push |
Definition at line 285 of file luapp_function.cpp.
std::vector<argument_list> lua::function::lArgListStack_ [private] |
Definition at line 297 of file luapp_function.hpp.
argument_list* lua::function::pArgList_ [private] |
Definition at line 298 of file luapp_function.hpp.
state* lua::function::pLua_ [private] |
Definition at line 293 of file luapp_function.hpp.
std::string lua::function::sName_ [private] |
Definition at line 292 of file luapp_function.hpp.
uint lua::function::uiArgumentCount_ [private] |
Definition at line 294 of file luapp_function.hpp.
uint lua::function::uiReturnCount_ [private] |
Definition at line 296 of file luapp_function.hpp.
uint lua::function::uiReturnNbr_ [private] |
Definition at line 295 of file luapp_function.hpp.