#include <luascriptloader.h>

Implements an ScriptLoader that runs Lua 5, extended by default with a few specific commands.
Public Member Functions | |
| LuaScriptLoader (const char *id) | |
| virtual | ~LuaScriptLoader () |
| virtual bool | RunCode (const char *lua_code, string &result) |
| Executes a chunk of Lua code and provide a string representation of the result. | |
| virtual bool | RunFunction (const char *func_name, string &result) |
| const string & | GenerateStackTrace () |
| Generates a stack trace. | |
| virtual lua_State * | GetContext () |
Static Public Member Functions | |
| static void | RemoveThunk (lua_State *, void *) |
| static void | AddThunk (lua_State *, void *) |
| static void | FindThunk (lua_State *, void *) |
| static void | AddClassToCache (lua_State *, Class *) |
| static bool | ThunkNebObject (lua_State *, Root *) |
| static Root * | UnpackThunkRoot (lua_State *, int) |
| Simply unwraps a thunk for a passable Root* value. | |
| static void | InArgsToStack (lua_State *, Cmd *) |
| Take a cmd's in-args and put them on the LUA stack. | |
| static void | OutArgsToStack (lua_State *, Cmd *, bool) |
| Pushes the output args of a cmd onto the LUA stack, and optionally prints the output. | |
| static bool | StackToInArgs (lua_State *, Cmd *) |
| Pull a cmd's in-args from the stack and pack them into the cmd. | |
| static bool | StackToOutArgs (lua_State *, Cmd *) |
| Take a cmd's out-args from the stack and pack them into the cmd. | |
| static void | ListArgToTable (lua_State *, Arg *, bool) |
| Create a new table on the stack and populate it with the members of the list Arg. | |
Public Attributes | |
| string | class_cache_name |
| string | thunk_store_name |
Private Member Functions | |
| bool | ExecuteLuaChunk (string &result, int err_func) |
| Executes the chunk at the top of the Lua stack. | |
| void | reg_globalfunc (lua_CFunction func, const char *name) |
Static Private Member Functions | |
| static void | ArgToStack (lua_State *, Arg *) |
| Convert an Arg to a Lua compatible value and push it on the LUA stack. | |
| static bool | StackToArg (lua_State *, Arg *, int index) |
| Convert a value from the LUA stack to an Arg of the specified type. | |
| static void | StackToString (lua_State *L, int bottom, string &result) |
| Empties the Lua stack and returns a string representation of the contents. | |
Private Attributes | |
| lua_State * | L |
| Lua context. | |
| bool | echo |
| bool | selgrab |
| string | stack_trace |
| Contains stack trace after GenerateStackTrace is called. | |
| LuaScriptLoader::LuaScriptLoader | ( | const char * | id | ) |
Constructor. Initializes Lua 5 interpreter.
| LuaScriptLoader::~LuaScriptLoader | ( | ) | [virtual] |
Destructor.
| bool LuaScriptLoader::RunCode | ( | const char * | lua_code, | |
| string & | result | |||
| ) | [virtual] |
Executes a chunk of Lua code and provide a string representation of the result.
| lua_code | A null-terminated string of Lua code. | |
| result | The result (if any) of the execution of the Lua code. |
True if successful. Reimplemented from ScriptLoader.
| bool LuaScriptLoader::RunFunction | ( | const char * | func_name, | |
| string & | result | |||
| ) | [virtual] |
Runs a LUA script function with the specified name without any args.
param func_name Function name. param result Will be filled with the result.
True if successful. Reimplemented from ScriptLoader.
| const string & LuaScriptLoader::GenerateStackTrace | ( | ) |
Generates a stack trace.
| lua_State * LuaScriptLoader::GetContext | ( | ) | [virtual] |
Simple accessor to allow users to get at the Lua context if needed. Care is needed here not to close the context.
| void LuaScriptLoader::RemoveThunk | ( | lua_State * | L, | |
| void * | key | |||
| ) | [static] |
Removes a thunk from the _nebthunks table.
| L | Lua context. | |
| key | The key that is associated with the thunk. |
| void LuaScriptLoader::AddThunk | ( | lua_State * | L, | |
| void * | key | |||
| ) | [static] |
Adds a thunk (assumed to be at the top of the lua stack) to the _nebthunks table. The thunk will remain on the stack.
| L | Lua context. | |
| key | The key with which the thunk should be associated. |
| void LuaScriptLoader::FindThunk | ( | lua_State * | L, | |
| void * | key | |||
| ) | [static] |
Returns a thunk (in the _nebthunks table) that is associated with the specified key. Or nil a thunk for the specified key doesn't exist yet.
| L | Lua context. | |
| key | The key with which the thunk should be associated. |
| void LuaScriptLoader::AddClassToCache | ( | lua_State * | L, | |
| Class * | clazz | |||
| ) | [static] |
Add a class to the class cache.
| L | Lua context. | |
| clazz | Pointer to Class object. |
| bool LuaScriptLoader::ThunkNebObject | ( | lua_State * | L, | |
| Root * | root | |||
| ) | [static] |
Builds a Lua table for a more natural syntax for getting at the NOH and calling cmds.
| L | Lua context. | |
| root | Pointer to Root object. |
True if successful. | Root * LuaScriptLoader::UnpackThunkRoot | ( | lua_State * | L, | |
| int | table_idx | |||
| ) | [static] |
Simply unwraps a thunk for a passable Root* value.
| L | Lua context. | |
| table_idx | The absolute stack index of the table. |
| void LuaScriptLoader::InArgsToStack | ( | lua_State * | L, | |
| Cmd * | cmd | |||
| ) | [static] |
Take a cmd's in-args and put them on the LUA stack.
| L | Lua state object. | |
| cmd | Pointer to command. |
| void LuaScriptLoader::OutArgsToStack | ( | lua_State * | L, | |
| Cmd * | cmd, | |||
| bool | ||||
| ) | [static] |
Pushes the output args of a cmd onto the LUA stack, and optionally prints the output.
| L | Lua state object. | |
| cmd | Pointer to command. | |
| Print stack into log file. |
| bool LuaScriptLoader::StackToInArgs | ( | lua_State * | L, | |
| Cmd * | cmd | |||
| ) | [static] |
Pull a cmd's in-args from the stack and pack them into the cmd.
| L | Lua state object. | |
| cmd | Pointer to command. |
True if successful. | bool LuaScriptLoader::StackToOutArgs | ( | lua_State * | L, | |
| Cmd * | cmd | |||
| ) | [static] |
Take a cmd's out-args from the stack and pack them into the cmd.
| L | Lua state object. | |
| cmd | Pointer to command. |
| void LuaScriptLoader::ListArgToTable | ( | lua_State * | L, | |
| Arg * | arg, | |||
| bool | ||||
| ) | [static] |
Create a new table on the stack and populate it with the members of the list Arg.
| L | Lua state object. | |
| arg | Pointer to argument. | |
| Print stack into log file. |
| void LuaScriptLoader::ArgToStack | ( | lua_State * | L, | |
| Arg * | arg | |||
| ) | [static, private] |
Convert an Arg to a Lua compatible value and push it on the LUA stack.
| L | Lua state object. | |
| arg | Pointer to argument. |
| bool LuaScriptLoader::StackToArg | ( | lua_State * | L, | |
| Arg * | arg, | |||
| int | index | |||
| ) | [static, private] |
Convert a value from the LUA stack to an Arg of the specified type.
| L | Lua state object. | |
| arg | Pointer to argument. | |
| index | The absolute stack index of the value to convert. |
| void LuaScriptLoader::StackToString | ( | lua_State * | L, | |
| int | bottom, | |||
| string & | result | |||
| ) | [static, private] |
Empties the Lua stack and returns a string representation of the contents.
Only items between the bottom index and the stack top (excluding the bottom index) will be crammed into the string, passing 0 for the bottom will dump all the items in the stack.
| L | Lua context. | |
| bottom | Absolute index of the bottom stack item. | |
| result | String representation of the contents. |
| bool LuaScriptLoader::ExecuteLuaChunk | ( | string & | result, | |
| int | err_func | |||
| ) | [private] |
Executes the chunk at the top of the Lua stack.
| result | Will be filled with the result. | |
| err_func | Stack index of error handler. |
True if successful. | void LuaScriptLoader::reg_globalfunc | ( | lua_CFunction | func, | |
| const char * | name | |||
| ) | [private] |
Register global Lua function.
| func | Lua function. | |
| name | Name of the function. |
lua_State* LuaScriptLoader::L [private] |
Lua context.
bool LuaScriptLoader::echo [private] |
bool LuaScriptLoader::selgrab [private] |
string LuaScriptLoader::stack_trace [private] |
Contains stack trace after GenerateStackTrace is called.
1.5.3