本文整理汇总了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;
}
示例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;
}