コード例 #1
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;
}
コード例 #2
0
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    bool LuaStateManager::Init(char const * const pInitFileName)
    {
        // Create our global actor table.
        // This table will hold context for all actors created in the game world.
        LuaPlus::LuaObject globals = m_GlobalState->GetGlobals();
        LuaPlus::LuaObject actorTable = globals.CreateTable("ActorList");

        // Execute the init file and setup some useful global variables for the lua scripts to know.
        if(DoFile(pInitFileName)) {
            std::string luaCommand;                     // The LUA command to execute.
            std::string currOpVal;                      // The current option value retrieved.
            boost::shared_ptr<GameOptions> opPtr = g_appPtr->GetGameOptions();

            // Write out the location of the game root directory.
            boost::filesystem::path gameRoot(g_appPtr->GetGameRootDir());
            //if(GameHalloran::RetrieveAndConvertOption<std::string>(opPtr, std::string("GameRoot"), GameHalloran::GameOptions::PROGRAMMER, currOpVal))
            //{
            luaCommand = std::string("INIT_GAME_ROOT_PATH = \"") + gameRoot.generic_string() + std::string("\";");
            if(!ExecuteString(luaCommand.c_str())) {
                return (false);
            }
            currOpVal.clear();
            luaCommand.clear();
            //}

            // Write out what type of build is running.
#ifdef DEBUG
            luaCommand = std::string("INIT_RUNNING_DEBUG_BUILD = true;");
#else
            luaCommand = std::string("INIT_RUNNING_DEBUG_BUILD = false;");
#endif
            if(!ExecuteString(luaCommand.c_str())) {
                return (false);
            }
            luaCommand.clear();

            // Write out the various player options so they are available to the lua UI setup scripts.
            luaCommand = std::string("INIT_PLAYER_OPTIONS = {};");
            if(!ExecuteString(luaCommand.c_str())) {
                return (false);
            }
            luaCommand.clear();

            // Sound options.
            if(GameHalloran::RetrieveAndConvertOption<std::string>(opPtr, std::string("MasterVolume"), GameHalloran::GameOptions::PLAYER, currOpVal)) {
                luaCommand = std::string("INIT_PLAYER_OPTIONS.MasterVolume = ") + currOpVal + std::string(";");
                if(!ExecuteString(luaCommand.c_str())) {
                    return (false);
                }
                currOpVal.clear();
                luaCommand.clear();
            }
            bool flag;
            if(GameHalloran::RetrieveAndConvertOption<bool>(opPtr, std::string("Music"), GameHalloran::GameOptions::PLAYER, flag)) {
                luaCommand = std::string("INIT_PLAYER_OPTIONS.Music = ") + (flag ? std::string("true") : std::string("false")) + std::string(";");
                if(!ExecuteString(luaCommand.c_str())) {
                    return (false);
                }
                luaCommand.clear();
            }
            if(GameHalloran::RetrieveAndConvertOption<bool>(opPtr, std::string("SoundFx"), GameHalloran::GameOptions::PLAYER, flag)) {
                luaCommand = std::string("INIT_PLAYER_OPTIONS.SoundFx = ") + (flag ? std::string("true") : std::string("false")) + std::string(";");
                if(!ExecuteString(luaCommand.c_str())) {
                    return (false);
                }
                luaCommand.clear();
            }

            // Graphics options.
            if(GameHalloran::RetrieveAndConvertOption<bool>(opPtr, std::string("RenderShadows"), GameHalloran::GameOptions::PLAYER, flag)) {
                luaCommand = std::string("INIT_PLAYER_OPTIONS.RenderShadows = ") + (flag ? std::string("true") : std::string("false")) + std::string(";");
                if(!ExecuteString(luaCommand.c_str())) {
                    return (false);
                }
                luaCommand.clear();
            }
            if(GameHalloran::RetrieveAndConvertOption<std::string>(opPtr, std::string("ScreenWidth"), GameHalloran::GameOptions::PLAYER, currOpVal)) {
                luaCommand = std::string("INIT_PLAYER_OPTIONS.ScreenResolution = \"") + currOpVal + std::string("*");
                boost::shared_ptr<GameOptions> opPtr = g_appPtr->GetGameOptions();
                if(GameHalloran::RetrieveAndConvertOption<std::string>(opPtr, std::string("ScreenHeight"), GameHalloran::GameOptions::PLAYER, currOpVal)) {
                    luaCommand += currOpVal + std::string("\";");
                    if(!ExecuteString(luaCommand.c_str())) {
                        return (false);
                    }
                }
                currOpVal.clear();
                luaCommand.clear();
            }
            if(GameHalloran::RetrieveAndConvertOption<std::string>(opPtr, std::string("Multisampling"), GameHalloran::GameOptions::PLAYER, currOpVal)) {
                currOpVal = std::string("x") + currOpVal;

                luaCommand = std::string("INIT_PLAYER_OPTIONS.Multisampling = \"") + currOpVal + std::string("\";");
                if(!ExecuteString(luaCommand.c_str())) {
                    return (false);
                }
                currOpVal.clear();
                luaCommand.clear();
            }
            if(GameHalloran::RetrieveAndConvertOption<std::string>(opPtr, std::string("TextureFilteringType"), GameHalloran::GameOptions::PLAYER, currOpVal)) {
                luaCommand = std::string("INIT_PLAYER_OPTIONS.TextureFilteringType = \"") + currOpVal + std::string("\";");
                if(!ExecuteString(luaCommand.c_str())) {
                    return (false);
                }
                currOpVal.clear();
                luaCommand.clear();
            }

            return (true);
        }

        return (false);
    }