Ejemplo n.º 1
0
void BaseScriptComponent::CreateScriptObject(void)
{
    LuaStateManager* pStateMgr = LuaStateManager::Get();
    AC_ASSERT(pStateMgr);
	AC_ASSERT(!m_scriptObject.IsNil());
	
	LuaPlus::LuaObject metaTableObj = pStateMgr->GetGlobalVars().Lookup(METATABLE_NAME);
	AC_ASSERT(!metaTableObj.IsNil());
	
	LuaPlus::LuaObject boxedPtr = pStateMgr->GetLuaState()->BoxPointer(this);
	boxedPtr.SetMetaTable(metaTableObj);
	m_scriptObject.SetLightUserData("__object", this);
	m_scriptObject.SetMetaTable(metaTableObj);
}
void LuaScriptComponent::CreateScriptObject()
{
	LuaStateManager* pStateManager = LuaStateManager::Get();
	CB_ASSERT(pStateManager);
	CB_ASSERT(!m_ScriptObject.IsNil());

	LuaPlus::LuaObject metaTableObj = pStateManager->GetGlobalVars().Lookup(LUA_METATABLE_NAME);
	CB_ASSERT(!metaTableObj.IsNil());

	// bind the __object field in lua to this object
	LuaPlus::LuaObject boxedPtr = pStateManager->GetLuaState()->BoxPointer(this);
	boxedPtr.SetMetaTable(metaTableObj);
	m_ScriptObject.SetLightUserData("__object", this);
	m_ScriptObject.SetMetaTable(metaTableObj);
}
Ejemplo n.º 3
0
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    LuaStateManager::LuaStateManager(void) : m_GlobalState(true)
    {
        //Create our metatable...
        m_MetaTable = m_GlobalState->GetGlobals().CreateTable("LuaStateManagerMetaTable");
        m_MetaTable.SetObject("__index", m_MetaTable);

        // Here we register two functions to make them accessible to script.
        m_MetaTable.RegisterObjectDirect("DoFile", (LuaStateManager *)0, &LuaStateManager::DoFile);
        m_MetaTable.RegisterObjectDirect("DoResourceFile", (LuaStateManager *)0, &LuaStateManager::DoResourceFile);
        m_MetaTable.RegisterObjectDirect("PrintDebugMessage", (LuaStateManager *)0, &LuaStateManager::PrintDebugMessage);

        LuaPlus::LuaObject luaStateManObj = m_GlobalState->BoxPointer(this);
        luaStateManObj.SetMetaTable(m_MetaTable);

        // And here we expose the metatable as a named entity.
        m_GlobalState->GetGlobals().SetObject("LuaStateManager", luaStateManObj);
    }