Game Development Reference
In-Depth Information
protected:
LuaPlus::LuaObject m_eventData;
public:
// construction
ScriptEvent(void) { m_eventDataIsValid = false; }
// script event data, which should only be called from the appropriate
// ScriptExports functions
LuaPlus::LuaObject GetEventData(void); // called when event is sent from
// C++ to script
bool SetEventData(LuaPlus::LuaObject eventData); // called when event is
// sent from script to C++
// Static helper functions for registering events with the script.
static void RegisterEventTypeWithScript(const char* key, EventType type);
static void AddCreationFunction(EventType type,
CreateEventForScriptFunctionType pCreationFunctionPtr);
static ScriptEvent* CreateEventFromScript(EventType type);
protected:
virtual void VBuildEventData(void);
virtual bool VBuildEventFromScript(void) { return true; }
};
The macros at the top are used for registering the event and exporting it to Lua.
REGISTER_SCRIPT_EVENT() is called during the initialization of the application,
passing in the class and the event type guid as parameters. It calls the static Regis-
terEventTypeWithScript() and AddCreationFunction() functions, which
you
ll see below. The reason this needs to be a macro is so that the RegisterE-
ventTypeWithScript() function can use the name of the class as the first param-
eter with the # operator, which places quotes around the token. The
EXPORT_FOR_SCRIPT_EVENT() macro is called inside the subclass declaration to
generate the CreateEventForScript() function. This is a macro so that you
have one central place to change any of this code should you need to do so without
having to go to every single subclass.
Inside the ScriptEvent class is a static map variable thatmapseventtypeguidsto
creation functions. Whenever an event needs to be created by guid, it looks up the
appropriate function in the map and calls it to create the appropriate subclass instance.
The m_eventData member is the Lua representation of the data used by the event. It is
typically a table, but it can be anything you like. This data is manipulated by the
'
Search WWH ::




Custom Search