|
Diluculum
1.0
|
#include <LuaState.hpp>
Public Member Functions | |
| LuaState (bool loadStdLib=true) | |
| LuaState (lua_State *state, bool loadStdLib=false) | |
| virtual | ~LuaState () |
| LuaValueList | doFile (const std::string &fileName) |
| LuaValueList | doString (const std::string &what) |
| LuaValueList | call (LuaFunction &func, const LuaValueList ¶ms, const std::string &chunkName="Diluculum chunk") |
| LuaVariable | operator[] (const std::string &variable) |
| LuaValueMap | globals () |
| lua_State * | getState () |
Returns the encapsulated lua_State*. | |
Private Member Functions | |
| LuaValueList | doStringOrFile (bool isString, const std::string &str) |
Private Attributes | |
| lua_State * | state_ |
The underlying lua_State*. | |
| const bool | ownsState_ |
LuaState: The Next Generation. The pleasant way to do perform relevant operations on a Lua state.
(My previous implementation of a class named LuaState was pretty low-level. It was essentially a C++ wrapper around a lua_State*, without higher level operations. This is an attempt to allow me to do the kind of things I do most of the time without much effort.)
Definition at line 50 of file LuaState.hpp.
| Diluculum::LuaState::LuaState | ( | bool | loadStdLib = true | ) | [explicit] |
Constructs a LuaState that owns a lua_State*. In other words, this will create the underlying Lua state on construction and destroy it when this LuaState is destroyed.
| loadStdLib | If true (the default), makes all the Lua standard libraries available. |
| LuaError | If something goes wrong. |
| Diluculum::LuaState::LuaState | ( | lua_State * | state, |
| bool | loadStdLib = false |
||
| ) | [explicit] |
Constructs a LuaState that doesn't own the underlying Lua state. In other words, this LuaState will use a user-supplied lua_State* and its destructor will not lua_close() it.
| state | The lua_State* that will be used by this LuaState. |
| loadStdLib | If true, makes all the Lua standard libraries available (default is false, because it is very likely that the libraries are already opened in the Lua state passed as the first parameter). |
| LuaError | If something goes wrong. |
| virtual Diluculum::LuaState::~LuaState | ( | ) | [virtual] |
| LuaValueList Diluculum::LuaState::call | ( | LuaFunction & | func, |
| const LuaValueList & | params, | ||
| const std::string & | chunkName = "Diluculum chunk" |
||
| ) |
Calls a given Lua function on this Lua state.
| func | The function to be called. |
| params | the list of parameters to pass to the function. |
| chunkName | The string to use as the "chunk name" in the call. This is something added to error messages, in order to make easier to stop where the error was. |
| LuaError | (or any of its subclasses), if some error is found during the function execution. |
| LuaValueList Diluculum::LuaState::doFile | ( | const std::string & | fileName | ) | [inline] |
Executes the file passed as parameter and returns all the values returned by this execution. Notice that when a LuaValueList is assigned to a LuaValue, just the first value in the list is assigned, so this is handy for situations when only the first return value is desired.
| fileName | The file to be executed. |
| LuaError | LuaError or any of its subclasses can be thrown. In particular, LuaTypeError will be thrown if the execution returns a type not supported by LuaType. |
Definition at line 93 of file LuaState.hpp.
References doStringOrFile().
| LuaValueList Diluculum::LuaState::doString | ( | const std::string & | what | ) | [inline] |
Executes the string passed as parameter and returns all the values returned by this execution. Notice that when a LuaValueList is assigned to a LuaValue, just the first value in the list is assigned, so this is handy for situations when only the first return value is desired.
| what | The string to be interpreted. |
what. | LuaError | LuaError or any of its subclasses can be thrown. In particular, LuaTypeError will be thrown if the execution returns a type not supported by LuaType. |
Definition at line 107 of file LuaState.hpp.
References doStringOrFile().
| LuaValueList Diluculum::LuaState::doStringOrFile | ( | bool | isString, |
| const std::string & | str | ||
| ) | [private] |
Since The implementation of doString and doFile() are quite similar, it looked like a good idea to use the same function to implement both at a lower level. This is it.
| isString | If true, means that it is desired to execute the contents of a string. If false, means that it is desired to execute the contents of a file. |
| str | Can be either a string of Lua code to be executed or a file with Lua code to be executed. The exact interpretation of this parameter depends on the first parameter, isString. |
| LuaError | LuaError or any of its subclasses can be thrown. In particular, LuaTypeError will be thrown if the execution returns a type not supported by LuaType. |
Referenced by doFile(), and doString().
| lua_State* Diluculum::LuaState::getState | ( | ) | [inline] |
Returns the encapsulated lua_State*.
Definition at line 150 of file LuaState.hpp.
References state_.
| LuaValueMap Diluculum::LuaState::globals | ( | ) |
Provides access to the table of global variables.
| LuaVariable Diluculum::LuaState::operator[] | ( | const std::string & | variable | ) |
Returns a LuaVariable representing the global variable named variable. Since the returned value also has a subscript operator, this is a handy way to access variables stored in tables. Also, since the LuaVariable has read/write support, this can be used even to modify the variables stored in the LuaState.
| variable | The name of the global variable to be accessed. |
variable. If no such variable exists, returns a variable containing Nil. LuaState::operator[] will not work (debug builds will assert()). Please use globals() instead. const bool Diluculum::LuaState::ownsState_ [private] |
Does this LuaState owns state_? (This used by the destructor to decide whether it has to lua_close() it or not.)
Definition at line 175 of file LuaState.hpp.
lua_State* Diluculum::LuaState::state_ [private] |
1.7.5.1