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


C++ cLuaState::WalkToNamedGlobal方法代码示例

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


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

示例1: key

bool cPrefabPiecePool::ReadPoolMetadataCubesetVer1(
	const AString & a_FileName,
	cLuaState & a_LuaState,
	bool a_LogWarnings
)
{
	// Push the Cubeset.Metadata table on top of the Lua stack:
	auto gp = a_LuaState.WalkToNamedGlobal("Cubeset.Metadata");
	if (!gp.IsValid())
	{
		return true;
	}

	// Iterate over elements in the table, put them into the m_GeneratorParams map:
	lua_pushnil(a_LuaState);  // Table is at index -2, starting key (nil) at index -1
	while (lua_next(a_LuaState, -2) != 0)
	{
		// Table at index -3, key at index -2, value at index -1
		AString key, val;
		a_LuaState.GetStackValues(-2, key, val);
		m_Metadata[key] = val;
		lua_pop(a_LuaState, 1);  // Table at index -2, key at index -1
	}
	return true;
}
开发者ID:changyongGuo,项目名称:cuberite,代码行数:25,代码来源:PrefabPiecePool.cpp

示例2:

bool cPrefabPiecePool::LoadFromCubesetVer1(const AString & a_FileName, cLuaState & a_LuaState, bool a_LogWarnings)
{
	// Load the metadata and apply the known ones:
	ReadPoolMetadataCubesetVer1(a_FileName, a_LuaState, a_LogWarnings);
	ApplyBaseMetadataCubesetVer1(a_FileName, a_LogWarnings);

	// Push the Cubeset.Pieces global value on the stack:
	auto pieces = a_LuaState.WalkToNamedGlobal("Cubeset.Pieces");
	if (!pieces.IsValid() || !lua_istable(a_LuaState, -1))
	{
		CONDWARNING(a_LogWarnings, "The cubeset file %s doesn't contain any pieces", a_FileName.c_str());
		return false;
	}

	// Iterate over all items in the Cubeset.Pieces value:
	int idx = 1;
	bool res = true;
	while (true)
	{
		lua_pushinteger(a_LuaState, idx);  // stk: [Pieces] [idx]
		lua_gettable(a_LuaState, -2);      // stk: [Pieces] [PieceItem]
		if (!lua_istable(a_LuaState, -1))
		{
			// The PieceItem is not present, we've iterated over all items
			lua_pop(a_LuaState, 1);  // stk: [Pieces]
			break;
		}
		if (!LoadCubesetPieceVer1(a_FileName, a_LuaState, idx, a_LogWarnings))
		{
			res = false;
		}
		lua_pop(a_LuaState, 1);  // stk: [Pieces]
		idx += 1;
	}
	return res;
}
开发者ID:changyongGuo,项目名称:cuberite,代码行数:36,代码来源:PrefabPiecePool.cpp


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