Game Development Reference
In-Depth Information
Agent* const agent = AgentUtilities::GetAgent(
luaVM, 1);
return AgentUtilities::PushRadius(luaVM, agent);
}
return 0;
}
To bind the function to Lua, we define a constant array that maps the function's name
within Lua to the C function that should be called. The array of function mappings must
always end with a null luaL_Reg type struct. Lua uses a null luaL_Reg type struct as
a terminator when processing the function map:
AgentUtilities.cpp
const luaL_Reg AgentFunctions[] =
{
{ "GetRadius", Lua_Script_AgentGetRadius },
{ NULL, NULL }
};
The actual function binding to the Lua virtual machine takes place in the lu-
aL_register helper function. The register function binds the table of function names
to their corresponding C callback function. The package name is specified at this step and
will be associated with each function within the mapping:
AgentUtilities.cpp
void AgentUtilities::BindVMFunctions(lua_State* const luaVM)
{
luaL_register(luaVM, "Agent", AgentFunctions);
}
Note
If NULL is passed in as the package name, Lua requires that a table be at the top of the
Lua stack. Lua will add the C functions to the Lua table at the top of the stack.
Search WWH ::




Custom Search