Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

ScriptState Class Reference

Inheritance diagram for ScriptState:

Inheritance graph
[legend]
Collaboration diagram for ScriptState:

Collaboration graph
[legend]

Detailed Description

Independent script state.

Definition at line 18 of file ScriptState.h.

Public Member Functions

 ScriptState ()
 ~ScriptState ()
void doFile (const Path &file)
 Process script file.
void doString (const std::string &input)
 Process string.
bool callCommand (int funcRef, int param)
 Call "bool function(param)" function.
void unref (int funcRef)
 Remove function from registry.
void registerFunc (const char *name, lua_CFunction func)
void registerLeader (Scripter *leader)
 Register light userdata for lua script.


Constructor & Destructor Documentation

ScriptState::ScriptState  ) 
 

Definition at line 23 of file ScriptState.cpp.

00024 {
00025     m_state = lua_open();
00026     luaopen_base(m_state);
00027     luaopen_string(m_state);
00028     luaopen_math(m_state);
00029     luaopen_table(m_state);
00030 
00031     prepareErrorHandler();
00032 }

ScriptState::~ScriptState  ) 
 

Definition at line 34 of file ScriptState.cpp.

00035 {
00036     lua_close(m_state);
00037 }


Member Function Documentation

bool ScriptState::callCommand int  funcRef,
int  param
 

Call "bool function(param)" function.

Parameters:
funcRef function index at registry
param integer parametr
Returns:
boolean result from function
Exceptions:
ScriptException when function is bad

Definition at line 128 of file ScriptState.cpp.

00129 {
00130     int numResults = 1;
00131     lua_rawgeti(m_state, LUA_REGISTRYINDEX, funcRef);
00132     lua_pushnumber(m_state, param);
00133     callStack(0, 1, numResults);
00134 
00135     if (0 == lua_isboolean(m_state, -1)) {
00136         const char *type = lua_typename(m_state, lua_type(m_state, -1));
00137         lua_pop(m_state, numResults);
00138         throw ScriptException(
00139                 ExInfo("script command failure - boolean expected")
00140                 .addInfo("got", type));
00141     }
00142     bool result = lua_toboolean(m_state, -1);
00143     lua_pop(m_state, numResults);
00144     return result;
00145 }

void ScriptState::doFile const Path file  ) 
 

Process script file.

Parameters:
file script

Definition at line 95 of file ScriptState.cpp.

00096 {
00097     int error = luaL_loadfile(m_state, file.getNative().c_str());
00098     callStack(error);
00099 }

void ScriptState::doString const std::string &  input  ) 
 

Process string.

Parameters:
input script

Definition at line 106 of file ScriptState.cpp.

00107 {
00108     int error = luaL_loadbuffer(m_state, input.c_str(), input.size(),
00109             input.c_str());
00110     callStack(error);
00111 }

void ScriptState::registerFunc const char *  name,
lua_CFunction  func
 

Definition at line 114 of file ScriptState.cpp.

00115 {
00116     lua_register(m_state, name, func);
00117 }

void ScriptState::registerLeader Scripter leader  ) 
 

Register light userdata for lua script.

Definition at line 162 of file ScriptState.cpp.

00163 {
00164     lua_pushstring(m_state, script_getLeaderName());
00165     lua_pushlightuserdata(m_state, leader);
00166     lua_rawset(m_state, LUA_REGISTRYINDEX);
00167 }

void ScriptState::unref int  funcRef  ) 
 

Remove function from registry.

Parameters:
funcRef function index at registry

Definition at line 152 of file ScriptState.cpp.

00153 {
00154     luaL_unref(m_state, LUA_REGISTRYINDEX, funcRef);
00155 }


The documentation for this class was generated from the following files:
Generated on Wed Jun 1 09:56:42 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2