Game Development Reference
In-Depth Information
REGISTER_SCRIPT_EVENT() macro. CreateEventFromScript() finds the crea-
tion function pointer and calls it.
Now that we have a nice little class that can translate C++ and Lua data, we need a
system to be able to queue up and receive events on the Lua side. Events coming
from C++ don
'
t need anything special,
they can just call VQueueEvent() or
VTriggerEvent() as normal.
The easiest problem to tackle is that of queuing events from Lua. We
'
ll use the same
scheme used for attaching processes from Lua, using ScriptExports to expose a
couple of wrapper functions.
bool InternalScriptExports::QueueEvent(EventType eventType,
LuaPlus::LuaObject eventData)
{
shared_ptr<ScriptEvent> pEvent(BuildEvent(eventType, eventData));
if (pEvent)
{
IEventManager::Get()->VQueueEvent(pEvent);
return true;
}
return false;
}
bool InternalScriptExports::TriggerEvent(EventType eventType,
LuaPlus::LuaObject eventData)
{
shared_ptr<ScriptEvent> pEvent(BuildEvent(eventType, eventData));
if (pEvent)
return IEventManager::Get()->VTriggerEvent(pEvent);
return false;
}
Both of these functions are very simple; they just call BuildEvent() to create the
event instance and then call into the Event Manager. BuildEvent() is a helper
function.
shared_ptr<ScriptEvent> InternalScriptExports::BuildEvent(EventType eventType,
LuaPlus::LuaObject& eventData)
{
// create the event from the event type
shared_ptr<ScriptEvent> pEvent(
ScriptEvent::CreateEventFromScript(eventType));
if (!pEvent)
return shared_ptr<ScriptEvent>();
Search WWH ::




Custom Search