コード例 #1
0
ファイル: ScriptEvent.cpp プロジェクト: moresascha/Chimera
 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");
     }
 }
コード例 #2
0
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());
}
コード例 #3
0
ファイル: AIView.cpp プロジェクト: moresascha/Chimera
    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));
        }
    }
コード例 #4
0
ファイル: LuaStateManager.cpp プロジェクト: Ostkaka/ANT
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;
}
コード例 #5
0
ファイル: LuaScriptExports.cpp プロジェクト: Ostkaka/ANT
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");
	}
}
コード例 #6
0
ファイル: ScriptExports.cpp プロジェクト: wsantas/gamecode4
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");
	}
}
コード例 #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);
}
コード例 #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);
}
コード例 #9
0
ファイル: ScriptEvent.cpp プロジェクト: moresascha/Chimera
        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;
        }
コード例 #10
0
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);
}
コード例 #11
0
 // /////////////////////////////////////////////////////////////////
 //
 // /////////////////////////////////////////////////////////////////
 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!");
 }
コード例 #12
0
ファイル: LuaManager.cpp プロジェクト: simplerr/Devbox
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;
}
コード例 #13
0
void BaseScriptComponent::UnregisterScriptFunctions(void)
{
	LuaPlus::LuaObject metaTableObj = LuaStateManager::Get()->GetGlobalVars().Lookup(METATABLE_NAME);
	if (!metaTableObj.IsNil())
		metaTableObj.AssignNil(LuaStateManager::Get()->GetLuaState());
}