Game Development Reference
In-Depth Information
'
singleton class. It
s created and destroyed explicitly through the static Create() and
Destroy() methods. The Get() method gets the singleton pointer.
The ExecuteFile() function opens and runs a Lua script while the Execute-
String() function parses an arbitrary string as Lua code. These two functions just
wrap LuaState::DoFile() and LuaState::DoString() , respectively.
The Init() function is called from the Create() function and initializes the Lua
state and registers a couple of functions. Here
'
s the definition:
bool LuaStateManager::Init(void)
{
m_pLuaState = LuaPlus::LuaState::Create(true);
if (m_pLuaState == NULL)
return false;
// register functions
m_pLuaState->GetGlobals().RegisterDirect(
, (*this),
&LuaStateManager::ExecuteFile);
ExecuteFile
m_pLuaState->GetGlobals().RegisterDirect(
, (*this),
&LuaStateManager::ExecuteString);
ExecuteString
return true;
}
GetGlobalVars() and GetLuaState() are both simple wrappers. CreatePath()
is a handy function that takes a string and creates a table path to it. For example, if you
pass in A.B.C ,itwillcreateatablecalled A with a single element named B , which has
a single element named C . This can be handy when exposing methods to specific tables
in script. You ' ll see it used below when we talk about the Script component.
ConvertVec3ToTable() and ConvertTableToVec3() are both helpers for con-
verting vectors between C++ and Lua.
Script Exports
All global script exports are placed into an internal class for organizational purposes.
This allows for a single place to export functions from. Here
'
s the initial implemen-
tation of the class:
class InternalScriptExports
{
public:
// initialization
static bool Init(void);
static void Destroy(void);
 
 
Search WWH ::




Custom Search