当前位置: 首页>>代码示例>>C++>>正文


C++ LuaObject::CreateTable方法代码示例

本文整理汇总了C++中luaplus::LuaObject::CreateTable方法的典型用法代码示例。如果您正苦于以下问题:C++ LuaObject::CreateTable方法的具体用法?C++ LuaObject::CreateTable怎么用?C++ LuaObject::CreateTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在luaplus::LuaObject的用法示例。


在下文中一共展示了LuaObject::CreateTable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getGlobalVars

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;
}
开发者ID:Ostkaka,项目名称:ANT,代码行数:42,代码来源:LuaStateManager.cpp

示例2: Init

    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    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();
//.........这里部分代码省略.........
开发者ID:pjohalloran,项目名称:gameframework,代码行数:101,代码来源:LuaStateManager.cpp


注:本文中的luaplus::LuaObject::CreateTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。