Game Development Reference
In-Depth Information
Managing the Lua State
The Lua state is managed through a singleton that encapsulates construction and
destruction and exposes a few useful methods. It also handles some error checking.
Here
'
s the class declaration:
class LuaStateManager : public IScriptManager
{
static LuaStateManager* s_pSingleton;
LuaPlus::LuaState* m_pLuaState;
std::string m_lastError;
public:
// Singleton functions
static bool Create(void);
static void Destroy(void);
static LuaStateManager* Get(void)
{ GCC_ASSERT(s_pSingleton); return s_pSingleton; }
// IScriptManager interface
virtual bool VInit(void) override;
virtual void VExecuteFile(const char* resource) override;
virtual void VExecuteString(const char* str) override;
LuaPlus::LuaObject GetGlobalVars(void);
LuaPlus::LuaState* GetLuaState(void) const;
// public helpers
LuaPlus::LuaObject CreatePath(const char* pathString,
bool toIgnoreLastElement = false);
void ConvertVec3ToTable(const Vec3& vec,
LuaPlus::LuaObject& outLuaTable) const;
void ConvertTableToVec3(const LuaPlus::LuaObject& luaTable,
Vec3& outVec3) const;
private:
void SetError(int errorNum);
void ClearStack(void);
// Private constructor & destructor; call the static Create() and Destroy()
// functions instead.
explicit LuaStateManager(void);
virtual
LuaStateManager(void);
˜
};
This class inherits from IScriptManager , a pure virtual interface. This is what
you
'
d override to implement a new scripting system. As stated before, this is a
 
 
Search WWH ::




Custom Search