本文整理汇总了C++中cLuaState::WalkToValue方法的典型用法代码示例。如果您正苦于以下问题:C++ cLuaState::WalkToValue方法的具体用法?C++ cLuaState::WalkToValue怎么用?C++ cLuaState::WalkToValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cLuaState
的用法示例。
在下文中一共展示了cLuaState::WalkToValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool cPrefabPiecePool::ReadConnectorsCubesetVer1(
const AString & a_FileName,
cLuaState & a_LuaState,
const AString & a_PieceName,
cPrefab * a_Prefab,
bool a_LogWarnings
)
{
// Get the Connectors subtable:
auto conns = a_LuaState.WalkToValue("Connectors");
if (!conns.IsValid())
{
CONDWARNING(a_LogWarnings, "Cannot load piece %s from file %s, it has no connectors definition.", a_PieceName.c_str(), a_FileName.c_str());
return false;
}
// Iterate over all items in the Connectors table:
int idx = 1;
bool res = true;
while (true)
{
lua_pushinteger(a_LuaState, idx); // stk: [Connectors] [idx]
lua_gettable(a_LuaState, -2); // stk: [Connectors] [conn]
if (!lua_istable(a_LuaState, -1))
{
// The connector is not present, we've iterated over all items
lua_pop(a_LuaState, 1); // stk: [Connectors]
break;
}
int Type = 0, RelX = 0, RelY = 0, RelZ = 0;
AString DirectionStr;
cPiece::cConnector::eDirection Direction = cPiece::cConnector::dirYM;
if (
!a_LuaState.GetNamedValue("Type", Type) ||
!a_LuaState.GetNamedValue("RelX", RelX) ||
!a_LuaState.GetNamedValue("RelY", RelY) ||
!a_LuaState.GetNamedValue("RelZ", RelZ) ||
!a_LuaState.GetNamedValue("Direction", DirectionStr) ||
!cPiece::cConnector::StringToDirection(DirectionStr, Direction)
)
{
CONDWARNING(a_LogWarnings, "Piece %s in file %s has a malformed Connector at index %d ({%d, %d, %d}, type %d, direction %s). Skipping the connector.",
a_PieceName.c_str(), a_FileName.c_str(), idx, RelX, RelY, RelZ, Type, DirectionStr.c_str()
);
res = false;
lua_pop(a_LuaState, 1); // stk: [Connectors]
idx += 1;
continue;
}
a_Prefab->AddConnector(RelX, RelY, RelZ, Direction, Type);
lua_pop(a_LuaState, 1); // stk: [Connectors]
idx += 1;
}
return res;
}
示例2: GetMergeStrategyMap
bool cPrefabPiecePool::ApplyPieceMetadataCubesetVer1(
const AString & a_FileName,
cLuaState & a_LuaState,
const AString & a_PieceName,
cPrefab * a_Prefab,
bool a_LogWarnings
)
{
// Push the Metadata table on top of the Lua stack:
auto md = a_LuaState.WalkToValue("Metadata");
if (!md.IsValid())
{
return false;
}
// Get the values:
int AddWeightIfSame = 0, DefaultWeight = 100, MoveToGround = 0, ShouldExpandFloor = 0;
AString DepthWeight, MergeStrategy;
a_LuaState.GetNamedValue("AddWeightIfSame", AddWeightIfSame);
a_LuaState.GetNamedValue("DefaultWeight", DefaultWeight);
a_LuaState.GetNamedValue("DepthWeight", DepthWeight);
a_LuaState.GetNamedValue("MergeStrategy", MergeStrategy);
a_LuaState.GetNamedValue("MoveToGround", MoveToGround);
a_LuaState.GetNamedValue("ShouldExpandFloor", ShouldExpandFloor);
// Apply the values:
a_Prefab->SetAddWeightIfSame(AddWeightIfSame);
a_Prefab->SetDefaultWeight(DefaultWeight);
a_Prefab->ParseDepthWeight(DepthWeight.c_str());
auto msmap = GetMergeStrategyMap();
auto strategy = msmap.find(MergeStrategy);
if (strategy == msmap.end())
{
CONDWARNING(a_LogWarnings, "Unknown merge strategy (\"%s\") specified for piece %s in file %s. Using msSpongePrint instead.",
MergeStrategy.c_str(), a_PieceName.c_str(), a_FileName.c_str()
);
a_Prefab->SetMergeStrategy(cBlockArea::msSpongePrint);
}
else
{
a_Prefab->SetMergeStrategy(strategy->second);
}
a_Prefab->SetMoveToGround(MoveToGround != 0);
a_Prefab->SetExtendFloor(ShouldExpandFloor != 0);
return true;
}
示例3: stk
bool cPrefabPiecePool::LoadFromCubesetFileVer1(const AString & a_FileName, cLuaState & a_LuaState, bool a_LogWarnings)
{
// Load the metadata:
ApplyPoolMetadataCubesetVer1(a_FileName, a_LuaState, a_LogWarnings);
// Push the Cubeset.Pieces global value on the stack:
lua_getglobal(a_LuaState, "_G");
cLuaState::cStackValue stk(a_LuaState);
auto pieces = a_LuaState.WalkToValue("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;
}
示例4: StringSplitAndTrim
bool cPrefabPiecePool::ApplyPoolMetadataCubesetVer1(
const AString & a_FileName,
cLuaState & a_LuaState,
bool a_LogWarnings
)
{
// Push the Cubeset.Metadata table on top of the Lua stack:
lua_getglobal(a_LuaState, "_G");
auto md = a_LuaState.WalkToValue("Cubeset.Metadata");
if (!md.IsValid())
{
CONDWARNING(a_LogWarnings, "Cannot load cubeset from file %s: Cubeset.Metadata table is missing", a_FileName.c_str());
return false;
}
// Set the metadata values to defaults:
m_MinDensity = 100;
m_MaxDensity = 100;
m_VillageRoadBlockType = E_BLOCK_GRAVEL;
m_VillageRoadBlockMeta = 0;
m_VillageWaterRoadBlockType = E_BLOCK_PLANKS;
m_VillageWaterRoadBlockMeta = 0;
// Read the metadata values:
a_LuaState.GetNamedValue("IntendedUse", m_IntendedUse);
a_LuaState.GetNamedValue("MaxDensity", m_MaxDensity);
a_LuaState.GetNamedValue("MinDensity", m_MinDensity);
a_LuaState.GetNamedValue("VillageRoadBlockType", m_VillageRoadBlockType);
a_LuaState.GetNamedValue("VillageRoadBlockMeta", m_VillageRoadBlockMeta);
a_LuaState.GetNamedValue("VillageWaterRoadBlockType", m_VillageWaterRoadBlockType);
a_LuaState.GetNamedValue("VillageWaterRoadBlockMeta", m_VillageWaterRoadBlockMeta);
AString allowedBiomes;
if (a_LuaState.GetNamedValue("AllowedBiomes", allowedBiomes))
{
auto biomes = StringSplitAndTrim(allowedBiomes, ",");
for (const auto & biome: biomes)
{
EMCSBiome b = StringToBiome(biome);
if (b == biInvalidBiome)
{
CONDWARNING(a_LogWarnings, "Invalid biome (\"%s\") specified in AllowedBiomes in cubeset file %s. Skipping the biome.",
biome.c_str(), a_FileName.c_str()
);
continue;
}
m_AllowedBiomes.insert(b);
}
}
else
{
// All biomes are allowed:
for (int b = biFirstBiome; b <= biMaxBiome; b++)
{
m_AllowedBiomes.insert(static_cast<EMCSBiome>(b));
}
for (int b = biFirstVariantBiome; b <= biMaxVariantBiome; b++)
{
m_AllowedBiomes.insert(static_cast<EMCSBiome>(b));
}
}
return true;
}
示例5: if
bool cPrefabPiecePool::ReadPieceMetadataCubesetVer1(
const AString & a_FileName,
cLuaState & a_LuaState,
const AString & a_PieceName,
cPrefab * a_Prefab,
bool a_LogWarnings
)
{
// Push the Metadata table on top of the Lua stack:
auto md = a_LuaState.WalkToValue("Metadata");
if (!md.IsValid())
{
return false;
}
// Get the values:
int AddWeightIfSame = 0, DefaultWeight = 100, MoveToGround = 0;
AString DepthWeight, MergeStrategy, VerticalLimit, VerticalStrategy;
a_LuaState.GetNamedValue("AddWeightIfSame", AddWeightIfSame);
a_LuaState.GetNamedValue("DefaultWeight", DefaultWeight);
a_LuaState.GetNamedValue("DepthWeight", DepthWeight);
a_LuaState.GetNamedValue("MergeStrategy", MergeStrategy);
a_LuaState.GetNamedValue("MoveToGround", MoveToGround);
a_LuaState.GetNamedValue("VerticalLimit", VerticalLimit);
a_LuaState.GetNamedValue("VerticalStrategy", VerticalStrategy);
// Apply the values:
a_Prefab->SetAddWeightIfSame(AddWeightIfSame);
a_Prefab->SetDefaultWeight(DefaultWeight);
a_Prefab->ParseDepthWeight(DepthWeight.c_str());
auto msmap = GetMergeStrategyMap();
auto strategy = msmap.find(MergeStrategy);
if (strategy == msmap.end())
{
CONDWARNING(a_LogWarnings, "Unknown merge strategy (\"%s\") specified for piece %s in file %s. Using msSpongePrint instead.",
MergeStrategy.c_str(), a_PieceName.c_str(), a_FileName.c_str()
);
a_Prefab->SetMergeStrategy(cBlockArea::msSpongePrint);
}
else
{
a_Prefab->SetMergeStrategy(strategy->second);
}
a_Prefab->SetMoveToGround(MoveToGround != 0);
AString ExpandFloorStrategyStr;
if (!a_LuaState.GetNamedValue("ExpandFloorStrategy", ExpandFloorStrategyStr))
{
// Check the older variant for ExpandFloorStrategy, ShouldExpandFloor:
int ShouldExpandFloor;
if (a_LuaState.GetNamedValue("ShouldExpandFloor", ShouldExpandFloor))
{
LOG("Piece \"%s\" in file \"%s\" is using the old \"ShouldExpandFloor\" attribute. Use the new \"ExpandFloorStrategy\" attribute instead for more options.",
a_PieceName.c_str(), a_FileName.c_str()
);
a_Prefab->SetExtendFloorStrategy((ShouldExpandFloor != 0) ? cPrefab::efsRepeatBottomTillNonAir : cPrefab::efsNone);
}
}
else
{
auto lcExpandFloorStrategyStr = StrToLower(ExpandFloorStrategyStr);
if (lcExpandFloorStrategyStr == "repeatbottomtillnonair")
{
a_Prefab->SetExtendFloorStrategy(cPrefab::efsRepeatBottomTillNonAir);
}
else if (lcExpandFloorStrategyStr == "repeatbottomtillsolid")
{
a_Prefab->SetExtendFloorStrategy(cPrefab::efsRepeatBottomTillSolid);
}
else
{
if (lcExpandFloorStrategyStr != "none")
{
LOGWARNING("Piece \"%s\" in file \"%s\" is using an unknown \"ExpandFloorStrategy\" attribute value: \"%s\"",
a_PieceName.c_str(), a_FileName.c_str(), ExpandFloorStrategyStr.c_str()
);
}
a_Prefab->SetExtendFloorStrategy(cPrefab::efsNone);
}
}
if (!VerticalLimit.empty())
{
if (!a_Prefab->SetVerticalLimitFromString(VerticalLimit, a_LogWarnings))
{
CONDWARNING(a_LogWarnings, "Unknown VerticalLimit (\"%s\") specified for piece %s in file %s. Using no limit instead.",
VerticalLimit.c_str(), a_PieceName.c_str(), a_FileName.c_str()
);
}
}
a_Prefab->SetVerticalStrategyFromString(VerticalStrategy, a_LogWarnings);
return true;
}