#include <luaxx/luaxx.hpp>
The functions provided by this class, closely resemble those of the Lua C API.
Definition at line 156 of file luaxx.hpp.
Public Member Functions | |
| template<> | |
| std::string | as (std::string default_value, int index) |
| Get the value at index as a string. | |
| template<> | |
| bool | as (bool default_value, int index) |
| Get the value at index as a bool. | |
| template<typename T> | |
| T | as (int index=-1) |
| Get the value at index as the given type. | |
| template<typename T> | |
| T | as (T default_value, int index=-1) |
| Get the value at index as the given type. | |
| state & | call (int nargs=0, int nresults=0) |
| Call a lua function in unprotected mode. | |
| state & | check (number &n, int narg) |
| Check an argument of the current function. | |
| state & | check (std::string &s, int narg) |
| Check an argument of the current function. | |
| state & | check (integer &i, int narg) |
| Check an argument of the current function. | |
| state & | check (int narg) |
| Check an argument of the current function. | |
| state & | checkstack (int size) |
| Ensure the stack is at least the given size. | |
| bool | empty () |
| Check if the stack is empty. | |
| template<typename msg_t> | |
| void | error (msg_t message) |
| Generate a Lua error. | |
| state & | getfield (const std::string &k, int index=-1) |
| Get a value from a table on the stack. | |
| state & | getglobal (const std::string &name) |
| Load a global symbol onto the stack. | |
| bool | getmetatable (int index) |
| Get the metatable of the value at the given index. | |
| state & | getmetatable (const std::string &tname) |
| Get the metatable associated with the given registry entry. | |
| state & | gettable (int index=-2) |
| Get a value from a table on the stack. | |
| int | gettop () |
| Get the number of elements in the stack. | |
| state & | insert (int index) |
| Move the top element to the given index. | |
| template<typename T> | |
| bool | is (int index=-1) |
| Check if the given index is of the given type (defaults to using lua_isnumber()). | |
| template<typename iterator_t> | |
| state & | load (iterator_t begin, iterator_t end) |
| Load a sequence of data as a Lua chunk. | |
| state & | loadfile (const std::string &filename) |
| Load a file as a Lua chunk. | |
| state & | loadstring (const std::string &s) |
| Load a string as a Lua chunk. | |
| bool | newmetatable (const std::string &tname) |
| Create a new metatable and add it to the registry. | |
| state & | newtable () |
| Create a new table on the stack. | |
| void * | newuserdata (size_t nbytes) |
| Create a new userdatum on the stack. | |
| template<typename userdata_t> | |
| userdata_t * | newuserdata () |
| Create a new userdatum on the stack. | |
| bool | next (int index=-2) |
| Get the next key value pair from a table on the stack. | |
| size_t | objlen (int index=-1) |
| Get the length of a value on the stack. | |
| operator lua_State * () | |
| Convert a lua::state to a lua_State*. | |
| state & | pcall (int nargs=0, int nresults=0, int on_error=0) |
| Call a lua function. | |
| state & | pop (int elements=1) |
| Remove the given number of elemens from the stack. | |
| state & | push (void *p) |
| Push a light userdatum on to the stack. | |
| state & | push (table) |
| Create a new table on to the stack. | |
| state & | push (cfunction f) |
| Push an C function onto the stack. | |
| state & | push (const std::string &s) |
| Push an std::string onto the stack. | |
| state & | push (const char *s) |
| Push a C-style string onto the stack. | |
| state & | push (const char *s, size_t length) |
| Push a C-style string onto the stack. | |
| template<typename T> | |
| state & | push (T number) |
| Push a number onto the stack. | |
| state & | push (bool boolean) |
| Push a boolean onto the stack. | |
| state & | push (nil) |
| Push a nil onto the stack. | |
| state & | push () |
| Push a nil onto the stack. | |
| template<typename T> | |
| state & | pushlightuserdata (T p) |
| Push a light userdatum on to the stack. | |
| state & | pushvalue (int index) |
| Push a copy of the element at the given index to the top of the stack. | |
| state & | remove (int index) |
| Remove the given index from the stack. | |
| state & | replace (int index) |
| Replace the given index with the top element. | |
| state & | setfield (const std::string &k, int index=-2) |
| Set a field in a table. | |
| state & | setglobal (const std::string &name) |
| Set a global symbol. | |
| state & | settable (int index=-3) |
| Set a value in a table. | |
| state & | settop (int index) |
| Set a new index as the top of the stack. | |
| int | size () |
| Get the number of elements in the stack. | |
| state (lua_State *L) | |
| Construct our lua environment from an existing lua_State. | |
| state () | |
| Construct our lua environment. | |
| template<> | |
| state & | to (std::string &string, int index) |
| Get the value at index as a string. | |
| template<> | |
| state & | to (bool &boolean, int index) |
| Get the value at index as a bool. | |
| template<typename T> | |
| state & | to (T &number, int index=-1) |
| Get the value at index as the given numeric type. | |
| template<typename T> | |
| state & | touserdata (T &p, int index=-1) |
| Get the value at index as (light) userdata. | |
| ~state () | |
| Destroy our lua environment. | |
| lua::state::state | ( | lua_State * | L | ) |
| std::string lua::state::as | ( | std::string | default_value, | |
| int | index | |||
| ) | [inline] |
Get the value at index as a string.
| default_value | this value is returned if the conversion fails | |
| index | the index to get |
lua::state::as(std::string()) will convert the value at the indicated index to a string on the stack. This can confuse lua::state::next();
| bool lua::state::as | ( | bool | default_value, | |
| int | index | |||
| ) | [inline] |
Get the value at index as a bool.
| default_value | this value is returned if the conversion fails | |
| index | the index to get |
| std::string lua::state::as | ( | int | index = -1 |
) | [inline] |
Get the value at index as the given type.
[specialization] Get the value at index as a string (T = std::string).
[specialization] Get the value at index as a bool (T = bool).
| T | the expected type of the value |
| index | the index to get |
The default version of this function uses lua_tonumber() but specializations may cause different behavior.
| lua::bad_conversion | if the value on the stack could not be converted to the indicated type |
| T lua::state::as | ( | T | default_value, | |
| int | index = -1 | |||
| ) | [inline] |
Get the value at index as the given type.
| T | the type to retrieve the value on the stack as (the default template function uses lua_tonumber(), specializations may cause different behavior) |
| default_value | this value is returned if the conversion fails | |
| index | the index to get |
| state & lua::state::call | ( | int | nargs = 0, |
|
| int | nresults = 0 | |||
| ) |
Call a lua function in unprotected mode.
| nargs | the number of args to pass to the function | |
| nresults | the number of values to return from the function stored. |
| state & lua::state::check | ( | number & | n, | |
| int | narg | |||
| ) |
Check an argument of the current function.
| n | the lua::number (lua_Number) to hold the returned value | |
| narg | the argument number to check |
| state & lua::state::check | ( | std::string & | s, | |
| int | narg | |||
| ) |
Check an argument of the current function.
| s | the string to hold the returned value | |
| narg | the argument number to check |
| state & lua::state::check | ( | integer & | i, | |
| int | narg | |||
| ) |
Check an argument of the current function.
| i | the lua::integer (lua_Integer) to hold the returned value | |
| narg | the argument number to check |
This function is meant to be called from with in a lua::cfunction. The error throw is internal to the lua intrepeter. When compiled as C++, a C++ exception is thrown, so the stack is properly unwound. This exception is not meant to be caught.
| state & lua::state::check | ( | int | narg | ) |
Check an argument of the current function.
| narg | the argument number to check |
| state & lua::state::checkstack | ( | int | size | ) |
Ensure the stack is at least the given size.
| size | the size to use |
| lua::exception | Thrown if the operation fails. |
| bool lua::state::empty | ( | ) |
| void lua::state::error | ( | msg_t | message | ) | [inline] |
Generate a Lua error.
| msg_t | the type of error message data (should be automatically determined) |
| message | the error message/value |
This function never returns, instead it throws an exception caught by the intepreter.
Definition at line 406 of file luaxx.hpp.
References push().
| state & lua::state::getfield | ( | const std::string & | k, | |
| int | index = -1 | |||
| ) |
| state & lua::state::getglobal | ( | const std::string & | name | ) |
Load a global symbol onto the stack.
| name | the name of the global to load |
| bool lua::state::getmetatable | ( | int | index | ) |
Get the metatable of the value at the given index.
| index | the index the value is stored at |
| state & lua::state::getmetatable | ( | const std::string & | tname | ) |
Get the metatable associated with the given registry entry.
| tname | the name in the registry |
| state & lua::state::gettable | ( | int | index = -2 |
) |
Get a value from a table on the stack.
| index | the index the table is stored at |
| int lua::state::gettop | ( | ) |
| state & lua::state::insert | ( | int | index | ) |
Move the top element to the given index.
| index | the index to insert at |
| bool lua::state::is< lightuserdata > | ( | int | index = -1 |
) | [inline] |
Check if the given index is of the given type (defaults to using lua_isnumber()).
[specialization] Check if the given index is light userdata (T = lua::lightuserdata).
[specialization] Check if the given index is userdata (T = lua::userdata).
[specialization] Check if the given index is a function (T = lua::function).
[specialization] Check if the given index is a C function (T = lua::cfunction).
[specialization] Check if the given index is a table (T = lua::table).
[specialization] Check if the given index is a string (T = std::string).
[specialization] Check if the given index is a boolean (T = bool).
[specialization] Check if the given index is a nil (T = lua::nil).
| T | the type to check for (the default, if no specializations match, does lua_isnumber()) |
| index | the index to check |
| state & lua::state::load | ( | iterator_t | begin, | |
| iterator_t | end | |||
| ) | [inline] |
Load a sequence of data as a Lua chunk.
| iterator_t | the type of iterator to use (should be automatically determined) |
| begin | an iterator to the start of the sequence | |
| end | an iterator to the end of the sequence (one past the end) |
| state & lua::state::loadfile | ( | const std::string & | filename | ) |
Load a file as a Lua chunk.
| filename | the name of the file to load |
| state & lua::state::loadstring | ( | const std::string & | s | ) |
Load a string as a Lua chunk.
| s | the string to load |
| bool lua::state::newmetatable | ( | const std::string & | tname | ) |
Create a new metatable and add it to the registry.
| tname | the name to use for the new metatable in the registry |
| state & lua::state::newtable | ( | ) |
| void * lua::state::newuserdata | ( | size_t | nbytes | ) |
| userdata_t * lua::state::newuserdata | ( | ) | [inline] |
| bool lua::state::next | ( | int | index = -2 |
) |
Get the next key value pair from a table on the stack.
| index | the stack index the table is at |
while(L.next() != 0) { // do stuff L.pop(); }
For Loop Example:
for(L.push(lua::nil()); L.next(); L.pop()) { // do stuff }
| size_t lua::state::objlen | ( | int | index = -1 |
) |
| lua::state::operator lua_State * | ( | ) | [inline] |
Convert a lua::state to a lua_State*.
This operator allows lua::state to behave like a lua_State pointer.
| state & lua::state::pcall | ( | int | nargs = 0, |
|
| int | nresults = 0, |
|||
| int | on_error = 0 | |||
| ) |
Call a lua function.
| nargs | the number of args to pass to the function | |
| nresults | the number of values to return from the function | |
| on_error | A stack index where the error handling function is stored. |
| state & lua::state::pop | ( | int | elements = 1 |
) |
Remove the given number of elemens from the stack.
| elements | the number of elements to remove |
| state & lua::state::push | ( | void * | p | ) |
Push a light userdatum on to the stack.
| p | the pointer to push |
Create a new table on to the stack.
| state & lua::state::push | ( | cfunction | f | ) |
Push an C function onto the stack.
| f | the function to push |
| state & lua::state::push | ( | const std::string & | s | ) |
Push an std::string onto the stack.
| s | the string to push |
| state & lua::state::push | ( | const char * | s | ) |
Push a C-style string onto the stack.
| s | the string to push |
| state & lua::state::push | ( | const char * | s, | |
| size_t | length | |||
| ) |
Push a C-style string onto the stack.
| s | the string to push | |
| length | the length of the string |
| state & lua::state::push | ( | T | number | ) | [inline] |
Push a number onto the stack.
| T | the numeric type to push (should be automatically determined, if there is no specialization for the desired type, lua_pushnumber() will be used, and may fail) |
| number | the number to push |
| state & lua::state::push | ( | bool | boolean | ) |
Push a boolean onto the stack.
| boolean | the value to push |
| state & lua::state::push | ( | ) |
Push a nil onto the stack.
Definition at line 59 of file luaxx.cc.
Referenced by error().
| state & lua::state::pushlightuserdata | ( | T | p | ) | [inline] |
Push a light userdatum on to the stack.
| T | the type of data to push (should be automatically determined) |
| p | the pointer to push |
| state & lua::state::pushvalue | ( | int | index | ) |
Push a copy of the element at the given index to the top of the stack.
| index | the index of the element to copy |
| state & lua::state::remove | ( | int | index | ) |
Remove the given index from the stack.
| index | the index to remove |
| state & lua::state::replace | ( | int | index | ) |
Replace the given index with the top element.
| index | the index to replae |
Definition at line 367 of file luaxx.cc.
Referenced by to().
| state & lua::state::setfield | ( | const std::string & | k, | |
| int | index = -2 | |||
| ) |
| state & lua::state::setglobal | ( | const std::string & | name | ) |
Set a global symbol.
| name | the name of the global to set |
| state & lua::state::settable | ( | int | index = -3 |
) |
Set a value in a table.
| index | the index the table is stored at |
| state & lua::state::settop | ( | int | index | ) |
Set a new index as the top of the stack.
| index | the index to use as the new top |
| int lua::state::size | ( | ) |
| state & lua::state::to | ( | std::string & | string, | |
| int | index | |||
| ) | [inline] |
Get the value at index as a string.
| string | where to store the value | |
| index | the index to get |
| lua::bad_conversion | if the value on the stack could not be converted to the indicated type |
Definition at line 650 of file luaxx.cc.
References replace().
| state & lua::state::to | ( | bool & | boolean, | |
| int | index | |||
| ) | [inline] |
Get the value at index as a bool.
| boolean | where to store the value | |
| index | the index to get |
| lua::bad_conversion | if the value on the stack could not be converted to the indicated type |
| state & lua::state::to | ( | T & | number, | |
| int | index = -1 | |||
| ) | [inline] |
Get the value at index as the given numeric type.
| T | they numeric type to static_cast<T>() the numeric value on the stack to |
| number | where to store the value | |
| index | the index to get |
| lua::bad_conversion | if the value on the stack could not be converted to the indicated type |
| state & lua::state::touserdata | ( | T & | p, | |
| int | index = -1 | |||
| ) | [inline] |