LuaScriptLoader Class Reference
[Lua Module]

#include <luascriptloader.h>

Inheritance diagram for LuaScriptLoader:

ScriptLoader Server< LuaScriptLoader > Root Object TreeNode< Root > Referenced Counted Serialized List< Root > ListNode< Root >

List of all members.


Detailed Description

Lua 5 wrapper.

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 RootUnpackThunkRoot (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.


Constructor & Destructor Documentation

LuaScriptLoader::LuaScriptLoader ( const char *  id  ) 

Constructor. Initializes Lua 5 interpreter.

LuaScriptLoader::~LuaScriptLoader (  )  [virtual]

Destructor.


Member Function Documentation

bool LuaScriptLoader::RunCode ( const char *  lua_code,
string &  result 
) [virtual]

Executes a chunk of Lua code and provide a string representation of the result.

Parameters:
lua_code A null-terminated string of Lua code.
result The result (if any) of the execution of the Lua code.
Returns:
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.

Returns:
True if successful.

Reimplemented from ScriptLoader.

const string & LuaScriptLoader::GenerateStackTrace (  ) 

Generates a stack trace.

Returns:
A pointer to the string containing the stack trace.
Warning:
The pointer points to an internal buffer that is likely to change, therefore you should copy the string before any further Lua server methods are called.

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.

Returns:
Lua context.

void LuaScriptLoader::RemoveThunk ( lua_State *  L,
void *  key 
) [static]

Removes a thunk from the _nebthunks table.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Warning:
The global class cache table is expected to be on top of the stack when this method is called.
Parameters:
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.

Parameters:
L Lua context.
root Pointer to Root object.
Returns:
True if successful.

Root * LuaScriptLoader::UnpackThunkRoot ( lua_State *  L,
int  table_idx 
) [static]

Simply unwraps a thunk for a passable Root* value.

Parameters:
L Lua context.
table_idx The absolute stack index of the table.
Returns:
Unpacked pointer to Root object.

void LuaScriptLoader::InArgsToStack ( lua_State *  L,
Cmd cmd 
) [static]

Take a cmd's in-args and put them on the LUA stack.

Parameters:
L Lua state object.
cmd Pointer to command.

void LuaScriptLoader::OutArgsToStack ( lua_State *  L,
Cmd cmd,
bool  print 
) [static]

Pushes the output args of a cmd onto the LUA stack, and optionally prints the output.

Parameters:
L Lua state object.
cmd Pointer to command.
print 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.

Parameters:
L Lua state object.
cmd Pointer to command.
Returns:
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.

Parameters:
L Lua state object.
cmd Pointer to command.

void LuaScriptLoader::ListArgToTable ( lua_State *  L,
Arg arg,
bool  print 
) [static]

Create a new table on the stack and populate it with the members of the list Arg.

Parameters:
L Lua state object.
arg Pointer to argument.
print 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.

Parameters:
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.

Parameters:
L Lua state object.
arg Pointer to argument.
index The absolute stack index of the value to convert.
Returns:
True if arg was successfuly retrieved and converted.

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.

Parameters:
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.

Parameters:
result Will be filled with the result.
err_func Stack index of error handler.
Returns:
True if successful.

void LuaScriptLoader::reg_globalfunc ( lua_CFunction  func,
const char *  name 
) [private]

Register global Lua function.

Parameters:
func Lua function.
name Name of the function.


Member Data Documentation

string LuaScriptLoader::class_cache_name

string LuaScriptLoader::thunk_store_name

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.


The documentation for this class was generated from the following files:
Generated on Sat Oct 20 14:47:32 2007 for Dark Oberon by  doxygen 1.5.3