Game Development Reference
In-Depth Information
private:
// private helpers
static void RegisterScriptClassFunctions(void);
static LuaPlus::LuaObject CreateFromScript(LuaPlus::LuaObject self,
LuaPlus::LuaObject constructionData,
LuaPlus::LuaObject originalSubClass);
virtual bool VBuildCppDataFromScript(LuaPlus::LuaObject scriptClass,
LuaPlus::LuaObject constructionData);
// These are needed because the base-class version of these functions are
// all const and LuaPlus can
t deal with registering const functions.
bool ScriptIsAlive(void) { return IsAlive(); }
bool ScriptIsDead(void) { return IsDead(); }
bool ScriptIsPaused(void) { return IsPaused(); }
'
// This wrapper function is needed so we can translate a Lua script object
// to something C++ can use.
void ScriptAttachChild(LuaPlus::LuaObject child);
// don't allow construction outside of this class
explicit ScriptProcess(void);
// static create function so Lua can instantiate it; only used internally
static ScriptProcess* Create(const char* scriptName = NULL);
static void Destroy(ScriptProcess* pObj);
};
The m_frequency and m_time members are used for timing. They allow the Lua
update function to be called at a set frequency. This can be important because cross-
ing the C++ / Lua boundary can be expensive. You should only call the update func-
tion as often as you have to.
The next several member variables hold the various Lua functions that are treated as
overrides. The m_self member holds onto the Lua instance of the class. This is
passed into the Lua overrides as the first parameter, which mimics calling the func-
tion using Lua
s colon operator. It allows the functions to access the appropriate
member variables.
The static RegisterScriptClass() function must be called during the application
initialization to set up the initial metatable to allow the ScriptProcess class to be
accessible from Lua. Here
'
'
s the function:
const char* SCRIPT_PROCESS_NAME =
ScriptProcess
;
void ScriptProcess::RegisterScriptClass(void)
{
Search WWH ::




Custom Search