diff --git a/src/ai/script_ai.cpp b/src/ai/script_ai.cpp index 0a7cc96226..b622296d73 100644 --- a/src/ai/script_ai.cpp +++ b/src/ai/script_ai.cpp @@ -309,9 +309,10 @@ static int CclDefineAiHelper(lua_State *l) || value == "research" || value == "unit-limit" || value == "repair") { - DebugPrint("DefineAiHelper: Relation is computed from buttons, " - "you may remove safely the block beginning with '\"%s\"'\n", - value.data()); + LuaDebugPrint(l, + "DefineAiHelper: Relation is computed from buttons, " + "you may remove safely the block beginning with '\"%s\"'\n", + value.data()); continue; } else if (value == "unit-equiv") { } else { @@ -397,7 +398,7 @@ static int CclDefineAi(lua_State *l) #ifdef DEBUG if (GetAiTypesByName(aiName)) { - DebugPrint("Warning two or more AI's with the same name '%s'\n", aiName.data()); + LuaDebugPrint(l, "Warning two or more AI's with the same name '%s'\n", aiName.data()); } #endif AiTypes.insert(AiTypes.begin(), std::make_unique()); @@ -741,7 +742,7 @@ static int CclAiWait(lua_State *l) lua_pushboolean(l, 1); return 1; } - DebugPrint("Broken? waiting on %s which wasn't requested.\n", type->Ident.c_str()); + LuaDebugPrint(l, "Broken? waiting on %s which wasn't requested.\n", type->Ident.c_str()); lua_pushboolean(l, 0); return 1; } @@ -1606,7 +1607,7 @@ static int CclDefineAiPlayer(lua_State *l) const unsigned int playerIdx = LuaToNumber(l, 0 + 1); Assert(playerIdx <= PlayerMax); - DebugPrint("%p %d\n", (void *)Players[playerIdx].Ai.get(), Players[playerIdx].AiEnabled); + LuaDebugPrint(l, "%p %d\n", (void *)Players[playerIdx].Ai.get(), Players[playerIdx].AiEnabled); // FIXME: lose this: // Assert(!Players[playerIdx].Ai && Players[playerIdx].AiEnabled); diff --git a/src/game/trigger.cpp b/src/game/trigger.cpp index 469f4d740a..887fc54e75 100644 --- a/src/game/trigger.cpp +++ b/src/game/trigger.cpp @@ -434,7 +434,7 @@ static int CclAddTrigger(lua_State *l) lua_getglobal(l, "_triggers_"); if (lua_isnil(l, -1)) { - DebugPrint("Trigger not set, defining trigger\n"); + LuaDebugPrint(l, "Trigger not set, defining trigger\n"); lua_pop(l, 1); lua_newtable(l); lua_setglobal(l, "_triggers_"); diff --git a/src/include/script.h b/src/include/script.h index 23725cbe18..d4c1e00e99 100644 --- a/src/include/script.h +++ b/src/include/script.h @@ -83,6 +83,16 @@ extern int LuaLoadFile(const fs::path &file, const std::string &strArg = "", boo extern int LuaCall(int narg, int clear, bool exitOnError = true); extern int LuaCall(lua_State *L, int narg, int nresults, int base, bool exitOnError = true); +std::string getLuaLocation(lua_State *l); + +#define LuaDebugPrint(l, format, ...) \ + do { \ + if (EnableDebugPrint) { \ + PrintOnStdOut(getLuaLocation(l)); \ + PrintOnStdOut(Format(format, ##__VA_ARGS__)); \ + } \ + } while (0) + #define LuaError(l, format, ...) \ do { \ PrintFunction(); \ diff --git a/src/include/stratagus.h b/src/include/stratagus.h index aee334ce7a..f780dc599f 100644 --- a/src/include/stratagus.h +++ b/src/include/stratagus.h @@ -148,7 +148,6 @@ inline void PrintOnStdOut(std::string_view s) */ #define LogPrint(format, ...) \ do { \ - PrintFunction(); \ PrintOnStdOut(Format(format, ##__VA_ARGS__)); \ } while (0) diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index 76172e661d..5649129b9b 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -109,7 +109,7 @@ static int CclStratagusMap(lua_State *l) } const int subsubargs = lua_rawlen(l, -1); if (subsubargs != Map.Info.MapWidth * Map.Info.MapHeight) { - ErrorPrint("Wrong tile table length: %d\n", subsubargs); + LuaError(l, "Wrong tile table length: %d\n", subsubargs); } for (int i = 0; i < subsubargs; ++i) { lua_rawgeti(l, -1, i + 1); @@ -149,9 +149,10 @@ static int CclRevealMap(lua_State *l) } else if (revealMode == "explored") { newMode = MapRevealModes::cExplored; } else { - ErrorPrint("Unknown reveal mode: '%s'\n" - "Accessible reveal modes: \"hidden\", \"known\", \"explored\".\n", - revealMode.data()); + LuaError(l, + "Unknown reveal mode: '%s'\n" + "Accessible reveal modes: \"hidden\", \"known\", \"explored\".\n", + revealMode.data()); return 1; } @@ -233,7 +234,7 @@ static int CclShowMapLocation(lua_State *l) target->CurrentSightRange = LuaToNumber(l, 3); MapMarkUnitSight(*target); } else { - DebugPrint("Unable to allocate Unit"); + LuaDebugPrint(l, "Unable to allocate Unit"); } return 0; } @@ -369,9 +370,10 @@ static int CclSetFieldOfViewType(lua_State *l) } else if (type_name == "simple-radial") { new_type = FieldOfViewTypes::cSimpleRadial; } else { - ErrorPrint("Unknown field of view types '%s'\n" - "Accessible field of view types: \"shadow-casting\", \"simple-radial\".\n", - type_name.data()); + LuaError(l, + "Unknown field of view types '%s'\n" + "Accessible field of view types: \"shadow-casting\", \"simple-radial\".\n", + type_name.data()); return 1; } if (!IsNetworkGame()) { @@ -416,9 +418,10 @@ static int CclSetOpaqueFor(lua_State *l) } else if (flag_name == "forest") { new_flag |= MapFieldForest; } else { - ErrorPrint("Opaque can only be set for \"wall\", \"rock\" or \"forest\".\n" - "You use '%s'\n", - flag_name.data()); + LuaError(l, + "Opaque can only be set for \"wall\", \"rock\" or \"forest\".\n" + "You use '%s'\n", + flag_name.data()); return 1; } } @@ -449,9 +452,10 @@ static int CclGetIsOpaqueFor(lua_State *l) } else if (flag_name == "forest") { flagToCheck = MapFieldForest; } else { - ErrorPrint("Opaque can only be checked for \"wall\", \"rock\" or \"forest\".\n" - "You use '%s'\n", - flag_name.data()); + LuaError(l, + "Opaque can only be checked for \"wall\", \"rock\" or \"forest\".\n" + "You use '%s'\n", + flag_name.data()); } lua_pushboolean(l, FieldOfView.GetOpaqueFields() & flagToCheck); @@ -475,9 +479,10 @@ static int CclRemoveOpaqueFor(lua_State *l) } else if (flag_name == "forest") { new_flag |= MapFieldForest; } else { - ErrorPrint("Opaque can only be removed for \"wall\", \"rock\" or \"forest\".\n" - "You use '%s'\n", - flag_name.data()); + LuaError(l, + "Opaque can only be removed for \"wall\", \"rock\" or \"forest\".\n" + "You use '%s'\n", + flag_name.data()); return 1; } } @@ -518,9 +523,10 @@ static int CclSetFogOfWarType(lua_State *l) } else if (type_name == "enhanced") { new_type = FogOfWarTypes::cEnhanced; } else { - ErrorPrint("Unknown fog of war type '%s'\n" - "Accessible Fog of War types: \"tiled\", \"enhanced\" and \"fast\".\n", - type_name.data()); + LuaError(l, + "Unknown fog of war type '%s'\n" + "Accessible Fog of War types: \"tiled\", \"enhanced\" and \"fast\".\n", + type_name.data()); return 1; } FogOfWar->SetType(new_type); @@ -542,34 +548,34 @@ static int CclGetFogOfWarType(lua_State *l) ** ** @param l Lua state. ** -** @return 0 for success, 1 for wrong type; +** @return 0 */ static int CclSetFogOfWarOpacityLevels(lua_State *l) { LuaCheckArgs(l, 3); const int explored = LuaToNumber(l, 1); if (explored <= 0 || explored > 255) { - PrintFunction(); - ErrorPrint("Invalid value (%d) of opacity for Explored tiles. " - "Acceptable range is [0 <= Explored <= Known <= Hidden <= 255].\n", - explored); - return 1; + LuaError(l, + "Invalid value (%d) of opacity for Explored tiles. " + "Acceptable range is [0 <= Explored <= Known <= Hidden <= 255].\n", + explored); + return 0; } const int revealed = LuaToNumber(l, 2); if (revealed <= explored || revealed > 255) { - PrintFunction(); - ErrorPrint("Invalid value (%d) of opacity for Revealed tiles. " - "Acceptable range is [0 <= Explored <= Known <= Hidden <= 255].\n", - revealed); - return 1; + LuaError(l, + "Invalid value (%d) of opacity for Revealed tiles. " + "Acceptable range is [0 <= Explored <= Known <= Hidden <= 255].\n", + revealed); + return 0; } const int unseen = LuaToNumber(l, 3); if (unseen < revealed || unseen > 255) { - PrintFunction(); - ErrorPrint("Invalid value (%d) of opacity for Unseen tiles. " - "Acceptable range is [0 <= Explored <= Known <= Hidden <= 255].\n", - unseen); - return 1; + LuaError(l, + "Invalid value (%d) of opacity for Unseen tiles. " + "Acceptable range is [0 <= Explored <= Known <= Hidden <= 255].\n", + unseen); + return 0; } FogOfWar->SetOpacityLevels(explored, revealed, unseen); @@ -590,17 +596,17 @@ static int CclSetFogOfWarBlur(lua_State *l) const float radiusSimple = LuaToFloat(l, 1); if (radiusSimple <= 0 ) { - ErrorPrint("Radius should be a positive float number. Blur is disabled.\n"); + LuaError(l, "Radius should be a positive float number. Blur is disabled.\n"); } const float radiusBilinear = LuaToFloat(l, 2); if (radiusBilinear <= 0 ) { - ErrorPrint("Radius should be a positive float number. Blur is disabled.\n"); + LuaError(l, "Radius should be a positive float number. Blur is disabled.\n"); } const int iterations = LuaToNumber(l, 3); if (iterations <= 0 ) { - ErrorPrint("Number of box blur iterations should be greater than 0. Blur is disabled.\n"); + LuaError(l, "Number of box blur iterations should be greater than 0. Blur is disabled.\n"); } FogOfWar->InitBlurer(radiusSimple, radiusBilinear, iterations); return 0; @@ -735,34 +741,34 @@ static int CclSetFogOfWarGraphics(lua_State *l) ** ** @param l Lua state. ** -** @return 0 for success, 1 for wrong type; +** @return 0 */ static int CclSetMMFogOfWarOpacityLevels(lua_State *l) { LuaCheckArgs(l, 3); const int explored = LuaToNumber(l, 1); if (explored <= 0 || explored > 255) { - PrintFunction(); - ErrorPrint("Invalid value (%d) of opacity for Minimap's Explored tiles. " - "Acceptable range is [0 <= Explored <= Known <= Hidden <= 255].\n", - explored); - return 1; + LuaError(l, + "Invalid value (%d) of opacity for Minimap's Explored tiles. " + "Acceptable range is [0 <= Explored <= Known <= Hidden <= 255].\n", + explored); + return 0; } const int revealed = LuaToNumber(l, 2); if (revealed <= explored || revealed > 255) { - PrintFunction(); - ErrorPrint("Invalid value (%d) of opacity for Minimap's Revealed tiles. " - "Acceptable range is [0 <= Explored <= Known <= Hidden <= 255].\n", - revealed); - return 1; + LuaError(l, + "Invalid value (%d) of opacity for Minimap's Revealed tiles. " + "Acceptable range is [0 <= Explored <= Known <= Hidden <= 255].\n", + revealed); + return 0; } const int unseen = LuaToNumber(l, 3); if (unseen < revealed || unseen > 255) { - PrintFunction(); - ErrorPrint("Invalid value (%d) of opacity for Minimap's Unseen tiles. " - "Acceptable range is [0 <= Explored <= Known <= Hidden <= 255].\n", - unseen); - return 1; + LuaError(l, + "Invalid value (%d) of opacity for Minimap's Unseen tiles. " + "Acceptable range is [0 <= Explored <= Known <= Hidden <= 255].\n", + unseen); + return 0; } UI.Minimap.SetFogOpacityLevels(explored, revealed, unseen); @@ -893,7 +899,7 @@ static int CclLoadTileModels(lua_State *l) Map.TileModelsFileName = LuaToString(l, 1); const fs::path filename = LibraryFileName(Map.TileModelsFileName.string()); if (LuaLoadFile(filename) == -1) { - ErrorPrint("Load failed: \"%s\"\n", filename.u8string().c_str()); + LuaError(l, "Load failed: \"%s\"\n", filename.u8string().c_str()); } return 0; } diff --git a/src/missile/script_missile.cpp b/src/missile/script_missile.cpp index 66bfa55d1c..1d20d04879 100644 --- a/src/missile/script_missile.cpp +++ b/src/missile/script_missile.cpp @@ -115,9 +115,7 @@ void MissileType::Load(lua_State *l) } else if (value == "ChangeVariable") { const int index = UnitTypeVar.VariableNameLookup[LuaToString(l, -1)];// User variables if (index == -1) { - ErrorPrint("Bad variable name '%s'\n", LuaToString(l, -1).data()); - Exit(1); - return; + LuaError(l, "Bad variable name '%s'\n", LuaToString(l, -1).data()); } this->ChangeVariable = index; } else if (value == "ChangeAmount") { @@ -244,7 +242,7 @@ static int CclMissile(lua_State *l) PixelPos source(-1, -1); Missile *missile = nullptr; - DebugPrint("FIXME: not finished\n"); + LuaDebugPrint(l, "FIXME: not finished\n"); const int args = lua_gettop(l); for (int j = 0; j < args; ++j) { diff --git a/src/pathfinder/script_pathfinder.cpp b/src/pathfinder/script_pathfinder.cpp index b1435f5666..885b18481c 100644 --- a/src/pathfinder/script_pathfinder.cpp +++ b/src/pathfinder/script_pathfinder.cpp @@ -65,7 +65,7 @@ static int CclAStar(lua_State *l) ++j; i = LuaToNumber(l, j + 1); if (i <= 3) { - ErrorPrint("Fixed unit crossing cost must be strictly > 3\n"); + LuaError(l, "Fixed unit crossing cost must be strictly > 3\n"); } else { AStarFixedUnitCrossingCost = i; } @@ -73,7 +73,7 @@ static int CclAStar(lua_State *l) ++j; i = LuaToNumber(l, j + 1); if (i <= 3) { - ErrorPrint("Moving unit crossing cost must be strictly > 3\n"); + LuaError(l, "Moving unit crossing cost must be strictly > 3\n"); } else { AStarMovingUnitCrossingCost = i; } @@ -85,7 +85,7 @@ static int CclAStar(lua_State *l) ++j; i = LuaToNumber(l, j + 1); if (i < 0) { - ErrorPrint("Unseen Terrain Cost must be non-negative\n"); + LuaError(l, "Unseen Terrain Cost must be non-negative\n"); } else { AStarUnknownTerrainCost = i; } @@ -93,7 +93,7 @@ static int CclAStar(lua_State *l) ++j; i = LuaToNumber(l, j + 1); if (i <= 0) { - ErrorPrint("Max A* search iterations must be strictly > 0\n"); + LuaError(l, "Max A* search iterations must be strictly > 0\n"); } else { AStarMaxSearchIterations = i; } diff --git a/src/spell/script_spell.cpp b/src/spell/script_spell.cpp index ba1e6d5267..5d8514be41 100644 --- a/src/spell/script_spell.cpp +++ b/src/spell/script_spell.cpp @@ -289,8 +289,7 @@ static void CclSpellAutocast(lua_State *l, AutoCastInfo *autocast) if (var == "Distance") { index = ACP_DISTANCE; } else { - ErrorPrint("Bad variable name '%s'\n", var.data()); - Exit(1); + LuaError(l, "Bad variable name '%s'\n", var.data()); } } autocast->PriorytyVar = index; @@ -340,7 +339,7 @@ static int CclDefineSpell(lua_State *l) SpellType *spell = nullptr; if (it != SpellTypeTable.end()) { spell = it->get(); - DebugPrint("Redefining spell-type '%s'\n", identname.data()); + LuaDebugPrint(l, "Redefining spell-type '%s'\n", identname.data()); } else { SpellTypeTable.push_back(std::make_unique(SpellTypeTable.size(), std::string{identname})); spell = SpellTypeTable.back().get(); diff --git a/src/stratagus/script.cpp b/src/stratagus/script.cpp index 83c476936d..6593d7a472 100644 --- a/src/stratagus/script.cpp +++ b/src/stratagus/script.cpp @@ -1928,6 +1928,15 @@ static int CclSetDamageFormula(lua_State *l) return 0; } +std::string getLuaLocation(lua_State* l) +{ + lua_Debug ar; + lua_getstack(l, 1, &ar); + lua_getinfo(l, "nSl", &ar); + + return std::string(ar.source) + ":" + std::to_string(ar.currentline) + ": "; +} + /** ** Print debug message with info about current script name, line number and function. ** @@ -1940,13 +1949,10 @@ static int CclDebugPrint(lua_State *l) LuaCheckArgs(l, 1); #ifdef DEBUG - lua_Debug ar; - lua_getstack(l, 1, &ar); - lua_getinfo(l, "nSl", &ar); - fprintf(stdout, "%s:%d: %s: %s\n", ar.source, ar.currentline, ar.what, LuaToString(l, 1).data()); + fprintf(stdout, "%s%s\n", getLuaLocation(l).c_str(), LuaToString(l, 1).data()); #endif - return 1; + return 0; } /** diff --git a/src/stratagus/script_player.cpp b/src/stratagus/script_player.cpp index 2f12c7779a..8240bd25e8 100644 --- a/src/stratagus/script_player.cpp +++ b/src/stratagus/script_player.cpp @@ -774,10 +774,11 @@ static int CclSetRevelationType(lua_State *l) } else if (revel_type == "buildings-only") { CPlayer::SetRevelationType(RevealTypes::cBuildingsOnly); } else { - ErrorPrint("Unknown revelation type '%s'\n" - "Accessible types of revelation " - "\"no-revelation\", \"all-units\" and \"buildings-only\".\n", - revel_type.data()); + LuaError(l, + "Unknown revelation type '%s'\n" + "Accessible types of revelation " + "\"no-revelation\", \"all-units\" and \"buildings-only\".\n", + revel_type.data()); return 1; } return 0; diff --git a/src/ui/script_ui.cpp b/src/ui/script_ui.cpp index 5400e3ccec..166668924a 100644 --- a/src/ui/script_ui.cpp +++ b/src/ui/script_ui.cpp @@ -604,7 +604,7 @@ static int CclDefinePanelContents(lua_State *l) if (it == UI.InfoPanelContents.end()) { UI.InfoPanelContents.push_back(std::move(infopanel)); } else { - DebugPrint("Redefinition of Panel '%s'\n", infopanel->Name.c_str()); + LuaDebugPrint(l, "Redefinition of Panel '%s'\n", infopanel->Name.c_str()); *it = std::move(infopanel); } } @@ -654,7 +654,7 @@ static int CclDefinePopup(lua_State *l) const auto it = ranges::find(UI.ButtonPopups, popup->Ident, &CPopup::Ident); if (it != UI.ButtonPopups.end()) { - DebugPrint("Redefinition of Popup '%s'\n", popup->Ident.c_str()); + LuaDebugPrint(l, "Redefinition of Popup '%s'\n", popup->Ident.c_str()); *it = std::move(popup); } else { UI.ButtonPopups.push_back(std::move(popup)); diff --git a/src/unit/depend.cpp b/src/unit/depend.cpp index 922134b0ce..7d6083868c 100644 --- a/src/unit/depend.cpp +++ b/src/unit/depend.cpp @@ -273,12 +273,10 @@ static int CclDefineDependency(lua_State *l) } else if (starts_with(target, "upgrade-")) { // Check upgrade exists if (auto* upgrade = CUpgrade::Get(target); !upgrade) { - ErrorPrint("upgrade not found: '%s'\n", target.data()); - ExitFatal(-1); + LuaError(l, "upgrade not found: '%s'\n", target.data()); } } else { - ErrorPrint("dependency target '%s' should be unit-type or upgrade\n", target.data()); - ExitFatal(-1); + LuaError(l, "dependency target '%s' should be unit-type or upgrade\n", target.data()); } auto &or_rule = Depends[std::string(target)]; diff --git a/src/unit/script_unit.cpp b/src/unit/script_unit.cpp index 209d16ef0b..c4ff729dc2 100644 --- a/src/unit/script_unit.cpp +++ b/src/unit/script_unit.cpp @@ -575,7 +575,7 @@ static int CclUnit(lua_State *l) Assert(player != nullptr); unit->AssignToPlayer(*player); if (unit->CurrentAction() == UnitAction::Built) { - DebugPrint("HACK: the building is not ready yet\n"); + LuaDebugPrint(l, "HACK: the building is not ready yet\n"); // HACK: the building is not ready yet unit->Player->UnitTypesCount[type->Slot]--; if (unit->Active) { @@ -786,7 +786,7 @@ static int CclCreateUnit(lua_State *l) } CUnit *unit = MakeUnit(*unittype, player); if (unit == nullptr) { - DebugPrint("Unable to allocate unit"); + LuaDebugPrint(l, "Unable to allocate unit"); return 0; } else { if (UnitCanBeAt(*unit, ipos) @@ -1417,10 +1417,11 @@ static int CclSetUnitVariable(lua_State *l) } else { unit->Player->UnitTypesAiActiveCount[unit->Type->Slot]--; if (unit->Player->UnitTypesAiActiveCount[unit->Type->Slot] < 0) { // if unit AI active count is negative, something wrong happened - ErrorPrint("Player %d has a negative '%s' AI active count of %d.\n", - unit->Player->Index, - unit->Type->Ident.c_str(), - unit->Player->UnitTypesAiActiveCount[unit->Type->Slot]); + LuaError(l, + "Player %d has a negative '%s' AI active count of %d.\n", + unit->Player->Index, + unit->Type->Ident.c_str(), + unit->Player->UnitTypesAiActiveCount[unit->Type->Slot]); } } } diff --git a/src/unit/script_unittype.cpp b/src/unit/script_unittype.cpp index a9a674210e..af77faf7ca 100644 --- a/src/unit/script_unittype.cpp +++ b/src/unit/script_unittype.cpp @@ -480,7 +480,7 @@ static int CclDefineUnitType(lua_State *l) auto [type, redefined] = NewUnitTypeSlot(str); if (redefined) { - DebugPrint("Redefining unit-type '%s'\n", str.data()); + LuaDebugPrint(l, "Redefining unit-type '%s'\n", str.data()); } else { type->NumDirections = 0; type->Flip = 1; @@ -1176,7 +1176,7 @@ static int CclDefineUnitType(lua_State *l) { // make a guess Building have 1 direction and units 8 type->NumDirections = type->Building ? 1 : 8; - DebugPrint("Defaulting 'NumDirections' of %s to %d\n", str.data(), type->NumDirections); + LuaDebugPrint(l, "Defaulting 'NumDirections' of %s to %d\n", str.data(), type->NumDirections); } // FIXME: try to simplify/combine the flags instead @@ -1214,7 +1214,7 @@ static int CclCopyUnitType(lua_State *l) const std::string_view toName = LuaToString(l, 2); auto [to, redefined] = NewUnitTypeSlot(toName); if (redefined) { - DebugPrint("Redefining unit-type '%s'\n", toName.data()); + LuaDebugPrint(l, "Redefining unit-type '%s'\n", toName.data()); } to->Flip = from.Flip; @@ -1317,7 +1317,10 @@ static int CclCopyUnitType(lua_State *l) to->Building = from.Building; to->BuildingRules.clear(); if (!from.BuildingRules.empty()) { - printf("WARNING: unit type copy %s of %s does not inherit BuildingRules\n", fromName.data(), toName.data()); + printf("%sWARNING: unit type copy %s of %s does not inherit BuildingRules\n", + getLuaLocation(l).c_str(), + fromName.data(), + toName.data()); } // XXX: should copy, not share, this will crash // for (auto rule : from.BuildingRules) { @@ -1325,7 +1328,10 @@ static int CclCopyUnitType(lua_State *l) // } to->AiBuildingRules.clear(); if (!from.AiBuildingRules.empty()) { - printf("WARNING: unit type copy %s of %s does not inherit AiBuildingRules\n", fromName.data(), toName.data()); + printf("%sWARNING: unit type copy %s of %s does not inherit AiBuildingRules\n", + getLuaLocation(l).c_str(), + fromName.data(), + toName.data()); } // XXX: should copy, not share, this would crash // for (auto rule : from.AiBuildingRules) { @@ -1886,7 +1892,7 @@ static int CclDefineVariables(lua_State *l) old++; UnitTypeVar.Variable.resize(old); } else { - DebugPrint("Warning, User Variable \"%s\" redefined\n", str.c_str()); + LuaDebugPrint(l, "Warning, User Variable \"%s\" redefined\n", str.c_str()); } if (!lua_istable(l, j + 2)) { // No change => default value. continue; diff --git a/src/unit/upgrade.cpp b/src/unit/upgrade.cpp index ce32456793..2ae828970d 100644 --- a/src/unit/upgrade.cpp +++ b/src/unit/upgrade.cpp @@ -336,7 +336,7 @@ static int CclDefineUnitAllow(lua_State *l) const std::string_view ident = LuaToString(l, 0 + 1); if (!starts_with(ident, "unit-")) { - DebugPrint(" wrong ident %s\n", ident.data()); + LuaDebugPrint(l, "wrong ident %s\n", ident.data()); return 0; } int id = UnitTypeByIdent(ident).Slot; @@ -373,7 +373,7 @@ static int CclDefineAllow(lua_State *l) int n = ids.size(); if (n > PlayerMax) { - ErrorPrint("'%s': Allow string too long %d\n", ident.data(), n); + LuaError(l, "'%s': Allow string too long %d\n", ident.data(), n); n = PlayerMax; }