Game Development Reference
In-Depth Information
m_scriptAbortFunction = temp;
}
else
{
GCC_ERROR(
scriptClass is not a table in \
ScriptProcess::BuildCppDataFromScript()
);
return false;
}
if (constructionData.IsTable())
{
for (LuaPlus::LuaTableIterator constructionDataIt(constructionData);
constructionDataIt; constructionDataIt.Next())
{
const char* key = constructionDataIt.GetKey().GetString();
LuaPlus::LuaObject val = constructionDataIt.GetValue();
if (strcmp(key,
) == 0 && val.IsInteger())
m_frequency = val.GetInteger();
else
m_self.SetObject(key, val);
frequency
}
}
return true;
}
The first parameter to this function is scriptClass , which is the Lua table that
represents the class we
re trying to instantiate. The originalScriptClass param-
eter from CreateFromScript() is passed in as this parameter. This ensures that
when the function looks for a function called OnInit() or OnUpdate() ,it
'
s looking
at the right class. The second parameter, constructionData , is used for any extra
configuration.
The first part of this function ensures that scriptClass is a valid table. Everything
within that if block has the same format; its entire purpose is to find the Lua versions
of the various Process virtual functions. Since it
'
s looking for functions that have the
same name, it gives the illusion that Lua is overriding C++ virtual functions. Any
found functions are placed in the appropriate member variables. The only required
function is OnUpdate() , which will cause the function to fail if it
'
s not found. The
OnUpdate() function in Process is a pure virtual function, so this makes sense.
The second part of the function processes the constructionData parameter. It loops
through each element on the table and tests to see if the key is frequency and the value
is an integer. If it is, the m_frequency member is set. If not, the value is set on the
'
Search WWH ::




Custom Search