Game Development Reference
In-Depth Information
This is just the initial implementation. As more systems are integrated and
exposed to Lua later in this chapter, the InternalScriptExports class will grow.
You can see the final version of this class and how it all fits together in source
code in the ScriptExports.cpp source file,
located at Source/GCC4/LUAScripting/
ScriptExports.cpp.
Process System
The Lua system needs a heartbeat
a way to update over multiple frames. Fortu-
nately, the process system introduced in Chapter 7 works perfectly for this. It just
needs to be extended and exposed to Lua. One possibility would be to attach some
Lua information to the ProcessManager and Process classes, but this would be a
bad idea. We want to leave the original system intact and not add references to Lua
where we don
t have to.
A better approach would be to create a special type of process that has knowledge of
the scripting system. This special process is created from Lua with a parameter to a
table containing methods that are called at the appropriate times. The idea is to cre-
ate the illusion that the Lua table is inheriting from this special process so that it
looks pretty much the same in Lua or C++. We can do all of this without modifying
or even extending the Process Manager whatsoever; we just need to write a special
script process that inherits from Process . This subclass will override each of the
Process virtual functions to call the Lua versions of those functions
Here ' s the ScriptProcess class:
'
class ScriptProcess : public Process
{
unsigned long m_frequency, m_time;
LuaPlus::LuaObject m_scriptInitFunction, m_scriptUpdateFunction;
LuaPlus::LuaObject m_scriptSuccessFunction, m_scriptFailFunction;
LuaPlus::LuaObject m_scriptAbortFunction;
LuaPlus::LuaObject m_self;
public:
static void RegisterScriptClass(void);
protected:
// Process interface
virtual void VOnInit(void);
virtual void VOnUpdate(unsigned long deltaMs);
virtual void VOnSuccess(void);
virtual void VOnFail(void);
virtual void VOnAbort(void);
 
 
Search WWH ::




Custom Search