Game Development Reference
In-Depth Information
// These are exported to Lua
static bool LoadAndExecuteScriptResource(const char* scriptResource);
};
The static functions that are exported to Lua are done in the typical manner. These
functions are wrappers for engine functionality and typically just send the request to
that
system. For
example, here
'
s
the
LoadAndExecuteScriptResource()
function:
bool InternalScriptExports::LoadAndExecuteScriptResource(
const char* scriptResource)
{
Resource resource(scriptResource);
shared_ptr<ResHandle> pResourceHandle =
g_pApp->m_ResCache->GetHandle(&resource);
if (pResourceHandle)
return true;
return false;
}
The functions are registered with the global ScriptExports::Register()
function:
namespace ScriptExports
{
void Register(void);
void Unregister(void);
}
And the implementation:
void ScriptExports::Register(void)
{
LuaPlus::LuaObject globals = LuaStateManager::Get()->GetGlobalVars();
// init
InternalScriptExports::Init();
// resource loading
globals.RegisterDirect(
LoadAndExecuteScriptResource
,
InternalScriptExports::LoadAndExecuteScriptResource);
}
void ScriptExports::Unregister(void)
{
InternalScriptExports::Destroy();
}
Search WWH ::




Custom Search