Esempio n. 1
0
 void LuaEventListener::EventListenerDelegate(event::IEventPtr event)
 {
     LuaScriptEventTransformation* t = chimera::g_pApp->GetScriptEventManager()->GetTransformation(event->VGetEventType());
     if(t)
     {
         if(!m_function.IsFunction())
         {
             LOG_ERROR_NR((std::string(m_function.GetString()) + std::string(" is not a function")).c_str());
         }
         LuaPlus::LuaFunction<void> function(m_function);
         
         LuaPlus::LuaObject obj = t->VBuildForScript(event);
         if(obj.IsNil())
         {
             function();
         }
         else
         {
             function(obj);
         }
     }
     else
     {
         LOG_ERROR("no Transformation");
     }
 }
void LuaScriptComponent::UnregisterScriptFunctions()
{
	// nil out the meta table object in lua
	LuaPlus::LuaObject metaTableObj = LuaStateManager::Get()->GetGlobalVars().Lookup(LUA_METATABLE_NAME);
	if (!metaTableObj.IsNil())
		metaTableObj.AssignNil(LuaStateManager::Get()->GetLuaState());
}
Esempio n. 3
0
    void ScriptOnUpdate(ActorId id, const util::Vec3& position, int levelSize)
    {
        LuaPlus::LuaObject o = chimera::g_pApp->GetScript()->GetState()->GetGlobal("OnUpdate");
        if(!o.IsNil() && o.IsFunction())
        {
            LuaPlus::LuaFunction<void> function = chimera::g_pApp->GetScript()->GetState()->GetGlobal("OnUpdate");

            function(chimera::script::GetIntegerObject(id), chimera::script::GetVec3Object(position), chimera::script::GetIntegerObject(levelSize));
        }
    }
Esempio n. 4
0
LuaPlus::LuaObject ant::LuaStateManager::createPath( const std::string& path, bool ignoreLastElement /*= false*/ )
{
	StringVec splitPath;
	Split(path,splitPath, '.');
	if (ignoreLastElement)
	{
		splitPath.pop_back();
	}

	LuaPlus::LuaObject context = getGlobalVars();
	for (auto it = splitPath.begin() ; it != splitPath.end() ; it++)
	{
		// Is the context valid?
		if (context.IsNil())
		{
			GCC_ERROR("Something broke in CreatePath(); bailing out (element == " + (*it) + ")");
			return context;  // this will be nil
		}

		// grab whatever exists for this element
		const std::string& element = (*it);
		LuaPlus::LuaObject curr = context.GetByName(element.c_str());

		if (!curr.IsTable())
		{
			// if the element is not a table and not nil, we clobber it
			if (!curr.IsNil())
			{
				GCC_WARNING("Overwriting element '" + element + "' in table");
				context.SetNil(element.c_str());
			}

			// element is either nil or was clobbered so add the new table
			context.CreateTable(element.c_str());
		}

		context = context.GetByName(element.c_str());
	}

	// We have created a complete path here
	return context;
}
Esempio n. 5
0
void ant::InternalLuaScriptExports::attachScriptProcess( LuaPlus::LuaObject scriptProcess )
{
	LuaPlus::LuaObject temp = scriptProcess.Lookup("__object");
	if (!temp.IsNil())
	{
		IProcessStrongPtr pProcess(static_cast<IProcess*>(temp.GetLightUserData()));
		ProcessManagerSingleton::instance()->getProcessManager()->attachProcess(pProcess);
	}
	else
	{
		GCC_ERROR("Could not find __object in script proces");
	}
}
Esempio n. 6
0
void InternalScriptExports::AttachScriptProcess(LuaPlus::LuaObject scriptProcess)
{
	LuaPlus::LuaObject temp = scriptProcess.Lookup("__object");
	if (!temp.IsNil())
	{
		shared_ptr<Process> pProcess(static_cast<Process*>(temp.GetLightUserData()));
        g_pApp->m_pGame->AttachProcess(pProcess);
	}
	else
	{
		GCC_ERROR("Couldn't find __object in script process");
	}
}
Esempio n. 7
0
//---------------------------------------------------------------------------------------------------------------------
// This function is called to register an event type with the script to link them.  The simplest way to do this is 
// with the REGISTER_SCRIPT_EVENT() macro, which calls this function.
//---------------------------------------------------------------------------------------------------------------------
void ScriptEvent::RegisterEventTypeWithScript(const char* key, EventType type)
{
	// get or create the EventType table
	LuaPlus::LuaObject eventTypeTable = LuaStateManager::Get()->GetGlobalVars().GetByName("EventType");
	if (eventTypeTable.IsNil())
		eventTypeTable = LuaStateManager::Get()->GetGlobalVars().CreateTable("EventType");

	// error checking
	GCC_ASSERT(eventTypeTable.IsTable());
	GCC_ASSERT(eventTypeTable[key].IsNil());
	
	// add the entry
	eventTypeTable.SetNumber(key, (double)type);
}
Esempio n. 8
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);
}
Esempio n. 9
0
        void LuaScriptEventManager::RegisterEventTransformer(LuaScriptEventTransformation transformer, EventType type, LPCSTR name)
        {
            LuaScript* luas = (LuaScript*)chimera::g_pApp->GetScript();
            LuaPlus::LuaObject table = luas->GetState()->GetGlobals().GetByName("EventType");

            if(table.IsNil())
            {
                table = luas->GetState()->GetGlobals().CreateTable("EventType");
            }

            table.SetNumber(name, type);

            m_transformMap[type] = transformer;
        }
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);
}
 // /////////////////////////////////////////////////////////////////
 //
 // /////////////////////////////////////////////////////////////////
 void LuaStateManager::IdentifyLuaObjectType(LuaPlus::LuaObject &objToTest)
 {
     assert(!objToTest.IsNil() && "Nil!");
     assert(!objToTest.IsBoolean() && "Boolean!");
     assert(!objToTest.IsCFunction() && "C-Function!");
     assert(!objToTest.IsFunction() && "Function!");
     assert(!objToTest.IsInteger() && "Integer!");
     assert(!objToTest.IsLightUserData() && "Light User Data!");
     assert(!objToTest.IsNone() && "None!");
     assert(!objToTest.IsNumber() && "Number!");
     assert(!objToTest.IsString() && "String!");
     assert(!objToTest.IsTable() && "Table!");
     assert(!objToTest.IsUserData() && "User Data!");
     assert(!objToTest.IsWString() && "Wide String!");
     assert(0 && "UNKNOWN!");
 }
Esempio n. 12
0
void LuaManager::PrintTable(LuaPlus::LuaObject table, bool recursive)
{
	if(table.IsNil())
	{
		if(!recursive)
			GLIB_LOG("LuaManager", "null table");
		return;
	}

	if(!recursive)
		GLIB_LOG("LuaManager", "PrintTable()");

	cout << (!recursive ? "--\n" : "{ ");

	bool noMembers = true;
	for(LuaPlus::LuaTableIterator iter(table); iter; iter.Next())
	{
		noMembers = false;

		LuaPlus::LuaObject key = iter.GetKey();
		LuaPlus::LuaObject value = iter.GetValue();

		cout << key.ToString() << ": ";
		if(value.IsFunction())
			cout << "function" << "\n";
		else if(value.IsTable())
			PrintTable(value, true);
		else if(value.IsLightUserData())
			cout << "light user data" << "\n";
		else
			cout << value.ToString() << ", ";
	}

	cout << (!recursive ? "\n--" : "}");
	cout << endl;
}
Esempio n. 13
0
void BaseScriptComponent::UnregisterScriptFunctions(void)
{
	LuaPlus::LuaObject metaTableObj = LuaStateManager::Get()->GetGlobalVars().Lookup(METATABLE_NAME);
	if (!metaTableObj.IsNil())
		metaTableObj.AssignNil(LuaStateManager::Get()->GetLuaState());
}