diff options
author | Mattes D <github@xoft.cz> | 2023-05-11 22:05:17 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2023-05-16 23:50:37 +0200 |
commit | c9522fb740200ccef6230cec452c48efb31e5394 (patch) | |
tree | 7e74d70699e13dd0a92444a1a0add7a3059ac7ca /src/Bindings | |
parent | Try a timeout for jobs. (diff) | |
download | cuberite-c9522fb740200ccef6230cec452c48efb31e5394.tar cuberite-c9522fb740200ccef6230cec452c48efb31e5394.tar.gz cuberite-c9522fb740200ccef6230cec452c48efb31e5394.tar.bz2 cuberite-c9522fb740200ccef6230cec452c48efb31e5394.tar.lz cuberite-c9522fb740200ccef6230cec452c48efb31e5394.tar.xz cuberite-c9522fb740200ccef6230cec452c48efb31e5394.tar.zst cuberite-c9522fb740200ccef6230cec452c48efb31e5394.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/BlockTypePalette.cpp | 26 | ||||
-rw-r--r-- | src/Bindings/BlockTypePalette.h | 2 | ||||
-rw-r--r-- | src/Bindings/BlockTypeRegistry.cpp | 19 | ||||
-rw-r--r-- | src/Bindings/LuaJson.cpp | 11 | ||||
-rw-r--r-- | src/Bindings/LuaState.cpp | 60 | ||||
-rw-r--r-- | src/Bindings/LuaState.h | 25 | ||||
-rw-r--r-- | src/Bindings/LuaTCPLink.cpp | 8 | ||||
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 9 | ||||
-rw-r--r-- | src/Bindings/ManualBindings_BlockArea.cpp | 81 | ||||
-rw-r--r-- | src/Bindings/ManualBindings_Network.cpp | 34 | ||||
-rw-r--r-- | src/Bindings/ManualBindings_World.cpp | 4 | ||||
-rw-r--r-- | src/Bindings/PluginLua.cpp | 4 | ||||
-rw-r--r-- | src/Bindings/PluginManager.cpp | 8 |
13 files changed, 145 insertions, 146 deletions
diff --git a/src/Bindings/BlockTypePalette.cpp b/src/Bindings/BlockTypePalette.cpp index 7759505cf..d0fa99a21 100644 --- a/src/Bindings/BlockTypePalette.cpp +++ b/src/Bindings/BlockTypePalette.cpp @@ -189,7 +189,7 @@ void BlockTypePalette::loadFromJsonString(const AString & aJsonPalette) const auto & states = (*itr)["states"]; if (states == Json::Value()) { - throw LoadFailedException(Printf("Missing \"states\" for block type \"%s\"", blockTypeName)); + throw LoadFailedException(fmt::format(FMT_STRING("Missing \"states\" for block type \"{}\""), blockTypeName)); } for (const auto & state: states) { @@ -200,7 +200,7 @@ void BlockTypePalette::loadFromJsonString(const AString & aJsonPalette) const auto & properties = state["properties"]; if (!properties.isObject()) { - throw LoadFailedException(Printf("Member \"properties\" is not a JSON object (block type \"%s\", id %u).", blockTypeName, id)); + throw LoadFailedException(fmt::format(FMT_STRING("Member \"properties\" is not a JSON object (block type \"{}\", id {})."), blockTypeName, id)); } for (const auto & key: properties.getMemberNames()) { @@ -249,7 +249,7 @@ void BlockTypePalette::loadFromTsv(const AString & aTsvPalette, bool aIsUpgrade) auto keyEnd = findNextSeparator(aTsvPalette, idx + 1); if (keyEnd == AString::npos) { - throw LoadFailedException(Printf("Invalid header key format on line %u", line)); + throw LoadFailedException(fmt::format(FMT_STRING("Invalid header key format on line {}"), line)); } if (keyEnd == idx + 1) // Empty line, end of headers { @@ -264,7 +264,7 @@ void BlockTypePalette::loadFromTsv(const AString & aTsvPalette, bool aIsUpgrade) auto valueEnd = findNextSeparator(aTsvPalette, keyEnd + 1); if ((valueEnd == AString::npos) || (aTsvPalette[valueEnd] == '\t')) { - throw LoadFailedException(Printf("Invalid header value format on line %u", line)); + throw LoadFailedException(fmt::format(FMT_STRING("Invalid header value format on line {}"), line)); } auto key = aTsvPalette.substr(keyStart, keyEnd - keyStart); if (key == "FileVersion") @@ -277,7 +277,7 @@ void BlockTypePalette::loadFromTsv(const AString & aTsvPalette, bool aIsUpgrade) } else if (version != 1) { - throw LoadFailedException(Printf("Unknown FileVersion: %u. Only version 1 is supported.", version)); + throw LoadFailedException(fmt::format(FMT_STRING("Unknown FileVersion: {}. Only version 1 is supported."), version)); } hasHadVersion = true; } @@ -304,12 +304,12 @@ void BlockTypePalette::loadFromTsv(const AString & aTsvPalette, bool aIsUpgrade) auto idEnd = findNextSeparator(aTsvPalette, lineStart); if ((idEnd == AString::npos) || (aTsvPalette[idEnd] != '\t')) { - throw LoadFailedException(Printf("Incomplete data on line %u (id)", line)); + throw LoadFailedException(fmt::format(FMT_STRING("Incomplete data on line {} (id)"), line)); } UInt32 id; if (!StringToInteger(aTsvPalette.substr(lineStart, idEnd - lineStart), id)) { - throw LoadFailedException(Printf("Failed to parse id on line %u", line)); + throw LoadFailedException(fmt::format(FMT_STRING("Failed to parse id on line {}"), line)); } size_t metaEnd = idEnd; if (isUpgrade) @@ -317,23 +317,23 @@ void BlockTypePalette::loadFromTsv(const AString & aTsvPalette, bool aIsUpgrade) metaEnd = findNextSeparator(aTsvPalette, idEnd + 1); if ((metaEnd == AString::npos) || (aTsvPalette[metaEnd] != '\t')) { - throw LoadFailedException(Printf("Incomplete data on line %u (meta)", line)); + throw LoadFailedException(fmt::format(FMT_STRING("Incomplete data on line {} (meta)"), line)); } UInt32 meta = 0; if (!StringToInteger(aTsvPalette.substr(idEnd + 1, metaEnd - idEnd - 1), meta)) { - throw LoadFailedException(Printf("Failed to parse meta on line %u", line)); + throw LoadFailedException(fmt::format(FMT_STRING("Failed to parse meta on line {}"), line)); } if (meta > 15) { - throw LoadFailedException(Printf("Invalid meta value on line %u: %u", line, meta)); + throw LoadFailedException(fmt::format(FMT_STRING("Invalid meta value on line {}: {}"), line, meta)); } id = (id * 16) | meta; } auto blockTypeEnd = findNextSeparator(aTsvPalette, metaEnd + 1); if (blockTypeEnd == AString::npos) { - throw LoadFailedException(Printf("Incomplete data on line %u (blockTypeName)", line)); + throw LoadFailedException(fmt::format(FMT_STRING("Incomplete data on line {} (blockTypeName)"), line)); } auto blockTypeName = aTsvPalette.substr(metaEnd + 1, blockTypeEnd - metaEnd - 1); auto blockStateEnd = blockTypeEnd; @@ -343,12 +343,12 @@ void BlockTypePalette::loadFromTsv(const AString & aTsvPalette, bool aIsUpgrade) auto keyEnd = findNextSeparator(aTsvPalette, blockStateEnd + 1); if ((keyEnd == AString::npos) || (aTsvPalette[keyEnd] != '\t')) { - throw LoadFailedException(Printf("Incomplete data on line %u (blockState key)", line)); + throw LoadFailedException(fmt::format(FMT_STRING("Incomplete data on line {} (blockState key)"), line)); } auto valueEnd = findNextSeparator(aTsvPalette, keyEnd + 1); if (valueEnd == AString::npos) { - throw LoadFailedException(Printf("Incomplete data on line %u (blockState value)", line)); + throw LoadFailedException(fmt::format(FMT_STRING("Incomplete data on line {} (blockState value)"), line)); } auto key = aTsvPalette.substr(blockStateEnd + 1, keyEnd - blockStateEnd - 1); auto value = aTsvPalette.substr(keyEnd + 1, valueEnd - keyEnd - 1); diff --git a/src/Bindings/BlockTypePalette.h b/src/Bindings/BlockTypePalette.h index 2aade422b..1a41d3915 100644 --- a/src/Bindings/BlockTypePalette.h +++ b/src/Bindings/BlockTypePalette.h @@ -45,7 +45,7 @@ public: public: NoSuchIndexException(UInt32 aIndex): - Super(Printf("No such palette index: %u", aIndex)) + Super(fmt::format(FMT_STRING("No such palette index: {}"), aIndex)) { } }; diff --git a/src/Bindings/BlockTypeRegistry.cpp b/src/Bindings/BlockTypeRegistry.cpp index 491e03593..62c3c580b 100644 --- a/src/Bindings/BlockTypeRegistry.cpp +++ b/src/Bindings/BlockTypeRegistry.cpp @@ -211,10 +211,11 @@ AString BlockTypeRegistry::AlreadyRegisteredException::message( const std::shared_ptr<BlockInfo> & aNewRegistration ) { - return Printf("Attempting to register BlockTypeName %s from plugin %s, while it is already registered in plugin %s", - aNewRegistration->blockTypeName().c_str(), - aNewRegistration->pluginName().c_str(), - aPreviousRegistration->pluginName().c_str() + return fmt::format( + FMT_STRING("Attempting to register BlockTypeName {} from plugin {}, while it is already registered in plugin {}"), + aNewRegistration->blockTypeName(), + aNewRegistration->pluginName(), + aPreviousRegistration->pluginName() ); } @@ -230,11 +231,11 @@ BlockTypeRegistry::NotRegisteredException::NotRegisteredException( const AString & aHintKey, const AString & aHintValue ): - Super(Printf( - "Attempting to set a hint of nonexistent BlockTypeName.\n\tBlockTypeName = %s\n\tHintKey = %s\n\tHintValue = %s", - aBlockTypeName.c_str(), - aHintKey.c_str(), - aHintValue.c_str() + Super(fmt::format( + FMT_STRING("Attempting to set a hint of nonexistent BlockTypeName.\n\tBlockTypeName = {}\n\tHintKey = {}\n\tHintValue = {}"), + aBlockTypeName, + aHintKey, + aHintValue )) { } diff --git a/src/Bindings/LuaJson.cpp b/src/Bindings/LuaJson.cpp index 1cd88cf96..1077b6e56 100644 --- a/src/Bindings/LuaJson.cpp +++ b/src/Bindings/LuaJson.cpp @@ -42,7 +42,7 @@ public: /** Constructs a new instance of the exception based on the provided values directly. */ explicit CannotSerializeException(int a_ValueIndex, const char * a_ErrorMsg): Super(a_ErrorMsg), - m_ValueName(Printf("%d", a_ValueIndex)) + m_ValueName(fmt::format(FMT_STRING("{}"), a_ValueIndex)) { } @@ -58,7 +58,7 @@ public: Used for prefixing the value name's path along the call stack that lead to the main exception. */ explicit CannotSerializeException(const CannotSerializeException & a_Parent, int a_ValueNamePrefixIndex): Super(a_Parent.what()), - m_ValueName(Printf("%d", a_ValueNamePrefixIndex) + "." + a_Parent.m_ValueName) + m_ValueName(fmt::format(FMT_STRING("{}"), a_ValueNamePrefixIndex) + "." + a_Parent.m_ValueName) { } @@ -299,7 +299,7 @@ static int tolua_cJson_Parse(lua_State * a_LuaState) AString ParseError; if (!JsonUtils::ParseString(input, root, &ParseError)) { - L.Push(cLuaState::Nil, Printf("Parsing Json failed: %s", ParseError)); + L.Push(cLuaState::Nil, fmt::format(FMT_STRING("Parsing Json failed: {}"), ParseError)); return 2; } @@ -338,7 +338,10 @@ static int tolua_cJson_Serialize(lua_State * a_LuaState) catch (const CannotSerializeException & exc) { lua_pushnil(L); - L.Push(Printf("Cannot serialize into Json, value \"%s\" caused an error \"%s\"", exc.GetValueName().c_str(), exc.what())); + L.Push(fmt::format( + FMT_STRING("Cannot serialize into Json, value \"{}\" caused an error \"{}\""), + exc.GetValueName(), exc.what() + )); return 2; } lua_pop(L, 1); diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index e4c537967..3d65045dd 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -145,7 +145,7 @@ void cLuaStateTracker::Del(cLuaState & a_LuaState) -AString cLuaStateTracker::GetStats(void) +AString cLuaStateTracker::GetStats() { auto & Instance = Get(); cCSLock Lock(Instance.m_CSLuaStates); @@ -156,15 +156,15 @@ AString cLuaStateTracker::GetStats(void) int Mem = 0; if (!state->Call("collectgarbage", "count", cLuaState::Return, Mem)) { - res.append(Printf("Cannot query memory for state \"%s\"\n", state->GetSubsystemName().c_str())); + res.append(fmt::format(FMT_STRING("Cannot query memory for state \"{}\"\n"), state->GetSubsystemName())); } else { - res.append(Printf("State \"%s\" is using %d KiB of memory\n", state->GetSubsystemName().c_str(), Mem)); + res.append(fmt::format(FMT_STRING("State \"{}\" is using {} KiB of memory\n"), state->GetSubsystemName(), Mem)); Total += Mem; } } - res.append(Printf("Total memory used by Lua: %d KiB\n", Total)); + res.append(fmt::format(FMT_STRING("Total memory used by Lua: {} KiB\n"), Total)); return res; } @@ -172,7 +172,7 @@ AString cLuaStateTracker::GetStats(void) -cLuaStateTracker & cLuaStateTracker::Get(void) +cLuaStateTracker & cLuaStateTracker::Get() { static cLuaStateTracker Inst; // The singleton return Inst; @@ -803,7 +803,7 @@ bool cLuaState::PushFunction(const cRef & a_TableRef, const char * a_FnName) // Pop the table off the stack: lua_remove(m_LuaState, -2); - Printf(m_CurrentFunctionName, "<table-callback %s>", a_FnName); + m_CurrentFunctionName = fmt::format(FMT_STRING("<table-callback {}>"), a_FnName); m_NumCurrentFunctionArgs = 0; return true; } @@ -1631,13 +1631,13 @@ bool cLuaState::CallFunction(int a_NumResults) if (s != 0) { // The error has already been printed together with the stacktrace - LOGWARNING("Error in %s calling function %s()", m_SubsystemName.c_str(), CurrentFunctionName.c_str()); + LOGWARNING("Error in %s calling function %s()", m_SubsystemName, CurrentFunctionName); // Remove the error handler and error message from the stack: auto top = lua_gettop(m_LuaState); if (top < 2) { - LogStackValues(Printf("The Lua stack is in an unexpected state, expected at least two values there, but got %d", top).c_str()); + LogStackValues(fmt::format(FMT_STRING("The Lua stack is in an unexpected state, expected at least two values there, but got {}"), top).c_str()); } lua_pop(m_LuaState, std::min(2, top)); return false; @@ -1672,7 +1672,7 @@ bool cLuaState::CheckParamUserTable(int a_StartParam, const char * a_UserTable, lua_Debug entry; VERIFY(lua_getstack(m_LuaState, 0, &entry)); VERIFY(lua_getinfo (m_LuaState, "n", &entry)); - AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != nullptr) ? entry.name : "?"); + AString ErrMsg = fmt::format(FMT_STRING("#ferror in function '{}'."), (entry.name != nullptr) ? entry.name : "?"); tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err); return false; } // for i - Param @@ -1705,7 +1705,7 @@ bool cLuaState::CheckParamUserType(int a_StartParam, const char * a_UserType, in lua_Debug entry; VERIFY(lua_getstack(m_LuaState, 0, &entry)); VERIFY(lua_getinfo (m_LuaState, "n", &entry)); - AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != nullptr) ? entry.name : "?"); + AString ErrMsg = fmt::format(FMT_STRING("#ferror in function '{}'."), (entry.name != nullptr) ? entry.name : "?"); tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err); return false; } // for i - Param @@ -1738,7 +1738,7 @@ bool cLuaState::CheckParamTable(int a_StartParam, int a_EndParam) lua_Debug entry; VERIFY(lua_getstack(m_LuaState, 0, &entry)); VERIFY(lua_getinfo (m_LuaState, "n", &entry)); - AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != nullptr) ? entry.name : "?"); + AString ErrMsg = fmt::format(FMT_STRING("#ferror in function '{}'."), (entry.name != nullptr) ? entry.name : "?"); BreakIntoDebugger(m_LuaState); @@ -1774,7 +1774,7 @@ bool cLuaState::CheckParamNumber(int a_StartParam, int a_EndParam) lua_Debug entry; VERIFY(lua_getstack(m_LuaState, 0, &entry)); VERIFY(lua_getinfo (m_LuaState, "n", &entry)); - AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != nullptr) ? entry.name : "?"); + AString ErrMsg = fmt::format(FMT_STRING("#ferror in function '{}'."), (entry.name != nullptr) ? entry.name : "?"); tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err); return false; } // for i - Param @@ -1807,7 +1807,7 @@ bool cLuaState::CheckParamBool(int a_StartParam, int a_EndParam) lua_Debug entry; VERIFY(lua_getstack(m_LuaState, 0, &entry)); VERIFY(lua_getinfo (m_LuaState, "n", &entry)); - AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != nullptr) ? entry.name : "?"); + AString ErrMsg = fmt::format(FMT_STRING("#ferror in function '{}'."), (entry.name != nullptr) ? entry.name : "?"); tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err); return false; } // for i - Param @@ -1843,7 +1843,7 @@ bool cLuaState::CheckParamString(int a_StartParam, int a_EndParam) tolua_err.array = 0; tolua_err.type = "string"; tolua_err.index = i; - AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != nullptr) ? entry.name : "?"); + AString ErrMsg = fmt::format(FMT_STRING("#ferror in function '{}'."), (entry.name != nullptr) ? entry.name : "?"); tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err); return false; } // for i - Param @@ -1938,7 +1938,7 @@ bool cLuaState::CheckParamVector3(int a_StartParam, int a_EndParam) continue; } - ApiParamError("Failed to read parameter #%d. Vector3 expected, got %s", i, GetTypeText(i).c_str()); + ApiParamError(fmt::format(FMT_STRING("Failed to read parameter #{}. Vector3 expected, got {}"), i, GetTypeText(i))); return false; } return true; @@ -1970,7 +1970,7 @@ bool cLuaState::CheckParamUUID(int a_StartParam, int a_EndParam) if (!tolua_iscppstring(m_LuaState, i, 0, &err)) { - ApiParamError("Failed to read parameter #%d. UUID expected, got %s", i, GetTypeText(i).c_str()); + ApiParamError(fmt::format(FMT_STRING("Failed to read parameter #{}. UUID expected, got {}"), i, GetTypeText(i))); return false; } @@ -1978,7 +1978,7 @@ bool cLuaState::CheckParamUUID(int a_StartParam, int a_EndParam) GetStackValue(i, tempStr); if (!tempUUID.FromString(tempStr)) { - ApiParamError("Failed to read parameter #%d. UUID expected, got non-UUID string:\n\t\"%s\"", i, tempStr.c_str()); + ApiParamError(fmt::format(FMT_STRING("Failed to read parameter #{}. UUID expected, got non-UUID string:\n\t\"{}\""), i, tempStr)); return false; } } @@ -2000,7 +2000,7 @@ bool cLuaState::CheckParamEnd(int a_Param) lua_Debug entry; VERIFY(lua_getstack(m_LuaState, 0, &entry)); VERIFY(lua_getinfo (m_LuaState, "n", &entry)); - AString ErrMsg = Printf("#ferror in function '%s': Too many arguments.", (entry.name != nullptr) ? entry.name : "?"); + AString ErrMsg = fmt::format(FMT_STRING("#ferror in function '{}': Too many arguments."), (entry.name != nullptr) ? entry.name : "?"); tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err); return false; } @@ -2021,9 +2021,9 @@ bool cLuaState::CheckParamSelf(const char * a_SelfClassName) lua_Debug entry; VERIFY(lua_getstack(m_LuaState, 0, &entry)); VERIFY(lua_getinfo (m_LuaState, "n", &entry)); - AString ErrMsg = Printf( - "Error in function '%s'. The 'self' parameter is not of the expected type, \"instance of %s\". " \ - "Make sure you're using the correct calling convention (obj:fn() instead of obj.fn()).", + AString ErrMsg = fmt::format( + FMT_STRING("Error in function '{}'. The 'self' parameter is not of the expected type, \"instance of {}\". " \ + "Make sure you're using the correct calling convention (obj:fn() instead of obj.fn())."), (entry.name != nullptr) ? entry.name : "<unknown>", a_SelfClassName ); tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err); @@ -2046,9 +2046,9 @@ bool cLuaState::CheckParamStaticSelf(const char * a_SelfClassName) lua_Debug entry; VERIFY(lua_getstack(m_LuaState, 0, &entry)); VERIFY(lua_getinfo (m_LuaState, "n", &entry)); - AString ErrMsg = Printf( - "Error in function '%s'. The 'self' parameter is not of the expected type, \"class %s\". " \ - "Make sure you're using the correct calling convention (cClassName:fn() instead of cClassName.fn() or obj:fn()).", + AString ErrMsg = fmt::format( + FMT_STRING("Error in function '{}'. The 'self' parameter is not of the expected type, \"class {}\". " \ + "Make sure you're using the correct calling convention (cClassName:fn() instead of cClassName.fn() or obj:fn())."), (entry.name != nullptr) ? entry.name : "<unknown>", a_SelfClassName ); tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err); @@ -2430,8 +2430,8 @@ void cLuaState::LogStackValues(lua_State * a_LuaState, const char * a_Header) switch (Type) { case LUA_TBOOLEAN: Value.assign((lua_toboolean(a_LuaState, i) != 0) ? "true" : "false"); break; - case LUA_TLIGHTUSERDATA: Printf(Value, "%p", lua_touserdata(a_LuaState, i)); break; - case LUA_TNUMBER: Printf(Value, "%f", static_cast<double>(lua_tonumber(a_LuaState, i))); break; + case LUA_TLIGHTUSERDATA: Value = fmt::format(FMT_STRING("{}"), lua_touserdata(a_LuaState, i)); break; + case LUA_TNUMBER: Value = fmt::format(FMT_STRING("{}"), lua_tonumber(a_LuaState, i)); break; case LUA_TSTRING: { size_t len; @@ -2439,11 +2439,11 @@ void cLuaState::LogStackValues(lua_State * a_LuaState, const char * a_Header) Value.assign(txt, std::min<size_t>(len, 50)); // Only log up to 50 characters of the string break; } - case LUA_TTABLE: Printf(Value, "%p", lua_topointer(a_LuaState, i)); break; - case LUA_TFUNCTION: Printf(Value, "%p", lua_topointer(a_LuaState, i)); break; + case LUA_TTABLE: Value = fmt::format(FMT_STRING("{}"), lua_topointer(a_LuaState, i)); break; + case LUA_TFUNCTION: Value = fmt::format(FMT_STRING("{}"), lua_topointer(a_LuaState, i)); break; case LUA_TUSERDATA: { - Printf(Value, "%p (%s)", lua_touserdata(a_LuaState, i), tolua_typename(a_LuaState, i)); + Value = fmt::format(FMT_STRING("{} ({})"), lua_touserdata(a_LuaState, i), tolua_typename(a_LuaState, i)); // tolua_typename pushes the string onto Lua stack, pop it off again: lua_pop(a_LuaState, 1); break; @@ -2480,7 +2480,7 @@ void cLuaState::LogApiCallParamFailure(const char * a_FnName, const char * a_Par void cLuaState::TrackInDeadlockDetect(cDeadlockDetect & a_DeadlockDetect) { - a_DeadlockDetect.TrackCriticalSection(m_CS, Printf("cLuaState %s", m_SubsystemName.c_str())); + a_DeadlockDetect.TrackCriticalSection(m_CS, fmt::format(FMT_STRING("cLuaState {}"), m_SubsystemName)); } diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index d579369f0..64e6cbe82 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -68,7 +68,7 @@ public: if (a_ShouldLogStack) { // DEBUG: If an unbalanced stack is reported, uncommenting the next line can help debug the imbalance - // cLuaState::LogStackValues(a_LuaState, Printf("Started checking Lua stack balance, currently %d items:", m_StackPos).c_str()); + // cLuaState::LogStackValues(a_LuaState, fmt::format(FMT_STRING("Started checking Lua stack balance, currently {} items:"), m_StackPos).c_str()); // Since LogStackValues() itself uses the balance check, we must not call it recursively } } @@ -119,14 +119,14 @@ public: if (curTop > m_Count) { // There are some leftover elements, adjust the stack: - m_LuaState.LogStackValues(Printf("Re-balancing Lua stack, expected %d values, got %d:", m_Count, curTop).c_str()); + m_LuaState.LogStackValues(fmt::format(FMT_STRING("Re-balancing Lua stack, expected {} values, got {}:"), m_Count, curTop).c_str()); lua_pop(m_LuaState, curTop - m_Count); } else if (curTop < m_Count) { // This is an irrecoverable error, rather than letting the Lua engine crash undefinedly later on, abort now: LOGERROR("Unable to re-balance Lua stack, there are elements missing. Expected at least %d elements, got %d.", m_Count, curTop); - throw std::runtime_error(Printf("Unable to re-balance Lua stack, there are elements missing. Expected at least %d elements, got %d.", m_Count, curTop)); + throw std::runtime_error(fmt::format(FMT_STRING("Unable to re-balance Lua stack, there are elements missing. Expected at least {} elements, got {}."), m_Count, curTop)); } } @@ -838,25 +838,6 @@ public: Doesn't return, but a dummy return type is provided so that Lua API functions may do "return ApiParamError(...)". */ int ApiParamError(std::string_view a_Msg); - /** Formats and prints the message using printf-style format specifiers, but prefixed with the current function name, then logs the stack contents and raises a Lua error. - To be used for bindings when they detect bad parameters. - Doesn't return, but a dummy return type is provided so that Lua API functions may do "return ApiParamError(...)". */ - template <typename... Args> - int ApiParamError(const char * a_MsgFormat, const Args & ... a_Args) - { - return ApiParamError(Printf(a_MsgFormat, a_Args...)); - } - - /** Formats and prints the message using python-style format specifiers, but prefixed with the current function name, then logs the stack contents and raises a Lua error. - To be used for bindings when they detect bad parameters. - Doesn't return, but a dummy return type is provided so that Lua API functions may do "return ApiParamError(...)". */ - template <typename... Args> - int FApiParamError(const char * a_MsgFormat, const Args & ... a_Args) - { - return ApiParamError(fmt::format(a_MsgFormat, a_Args...)); - } - - /** Returns the type of the item on the specified position in the stack */ AString GetTypeText(int a_StackPos); diff --git a/src/Bindings/LuaTCPLink.cpp b/src/Bindings/LuaTCPLink.cpp index 3933e9b36..498691806 100644 --- a/src/Bindings/LuaTCPLink.cpp +++ b/src/Bindings/LuaTCPLink.cpp @@ -179,7 +179,7 @@ AString cLuaTCPLink::StartTLSClient( auto res = ownCert->Parse(a_OwnCertData.data(), a_OwnCertData.size()); if (res != 0) { - return Printf("Cannot parse client certificate: -0x%x", res); + return fmt::format(FMT_STRING("Cannot parse client certificate: -0x{:x}"), -res); } } cCryptoKeyPtr ownPrivKey; @@ -189,7 +189,7 @@ AString cLuaTCPLink::StartTLSClient( auto res = ownPrivKey->ParsePrivate(a_OwnPrivKeyData.data(), a_OwnPrivKeyData.size(), a_OwnPrivKeyPassword); if (res != 0) { - return Printf("Cannot parse client private key: -0x%x", res); + return fmt::format(FMT_STRING("Cannot parse client private key: -0x{:x}"), -res); } } return link->StartTLSClient(ownCert, ownPrivKey); @@ -216,13 +216,13 @@ AString cLuaTCPLink::StartTLSServer( int res = OwnCert->Parse(a_OwnCertData.data(), a_OwnCertData.size()); if (res != 0) { - return Printf("Cannot parse server certificate: -0x%x", res); + return fmt::format(FMT_STRING("Cannot parse server certificate: -0x{:x}"), -res); } auto OwnPrivKey = std::make_shared<cCryptoKey>(); res = OwnPrivKey->ParsePrivate(a_OwnPrivKeyData.data(), a_OwnPrivKeyData.size(), a_OwnPrivKeyPassword); if (res != 0) { - return Printf("Cannot parse server private key: -0x%x", res); + return fmt::format(FMT_STRING("Cannot parse server private key: -0x{:x}"), -res); } return link->StartTLSServer(OwnCert, OwnPrivKey, a_StartTLSData); diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 40ab0467b..93c94fdff 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -129,8 +129,8 @@ int cManualBindings::vlua_do_error(lua_State * L, const char * a_pFormat, fmt::p // Copied from luaL_error and modified luaL_where(L, 1); - AString FmtMsg = vPrintf(msg.c_str(), a_ArgList); - lua_pushlstring(L, FmtMsg.data(), FmtMsg.size()); + auto Msg = fmt::vsprintf(msg, a_ArgList); + lua_pushlstring(L, Msg.data(), Msg.size()); lua_concat(L, 2); return lua_error(L); } @@ -1156,9 +1156,8 @@ static int tolua_cPluginManager_AddHook(lua_State * tolua_S) return tolua_cPluginManager_AddHook_DefFn(PlgMgr, S, ParamIdx); } - AString ParamDesc; - Printf(ParamDesc, "%s, %s, %s", S.GetTypeText(1).c_str(), S.GetTypeText(2).c_str(), S.GetTypeText(3).c_str()); - LOGWARNING("cPluginManager:AddHook(): bad parameters. Expected HOOK_TYPE and CallbackFunction, got %s. Hook not added.", ParamDesc.c_str()); + auto ParamDesc = fmt::format(FMT_STRING("{}, {}, {}"), S.GetTypeText(1), S.GetTypeText(2), S.GetTypeText(3)); + LOGWARNING("cPluginManager:AddHook(): bad parameters. Expected HOOK_TYPE and CallbackFunction, got %s. Hook not added.", ParamDesc); S.LogStackTrace(); return 0; } diff --git a/src/Bindings/ManualBindings_BlockArea.cpp b/src/Bindings/ManualBindings_BlockArea.cpp index c363e082f..ed6309cee 100644 --- a/src/Bindings/ManualBindings_BlockArea.cpp +++ b/src/Bindings/ManualBindings_BlockArea.cpp @@ -52,9 +52,9 @@ static int DoWithXYZ(lua_State * tolua_S) } if (!(Self->*CoordCheckFn)(BlockX, BlockY, BlockZ)) { - return L.FApiParamError("The provided coordinates ({0}) are not valid", + return L.ApiParamError(fmt::format(FMT_STRING("The provided coordinates ({0}) are not valid"), Vector3i{BlockX, BlockY, BlockZ} - ); + )); } // Call the DoWith function: @@ -134,7 +134,7 @@ static int readVector3iOverloadParams(cLuaState & a_LuaState, int a_StartParam, // Assume the 3-number version: if (!a_LuaState.GetStackValues(a_StartParam, a_Coords.x, a_Coords.y, a_Coords.z)) { - return a_LuaState.ApiParamError("Cannot read the %s, expected 3 numbers", a_ParamName); + return a_LuaState.ApiParamError(fmt::format(FMT_STRING("Cannot read the {}, expected 3 numbers"), a_ParamName)); } return a_StartParam + 3; } @@ -143,7 +143,7 @@ static int readVector3iOverloadParams(cLuaState & a_LuaState, int a_StartParam, // Assume the Vector3i version: if (!a_LuaState.GetStackValues(a_StartParam, a_Coords)) { - return a_LuaState.ApiParamError("Cannot read the %s, expected a Vector3i instance", a_ParamName); + return a_LuaState.ApiParamError(fmt::format(FMT_STRING("Cannot read the {}, expected a Vector3i instance"), a_ParamName)); } return a_StartParam + 1; } @@ -177,13 +177,13 @@ static int tolua_cBlockArea_Create(lua_State * a_LuaState) L.GetStackValue(dataTypesIdx, dataTypes); if (!cBlockArea::IsValidDataTypeCombination(dataTypes)) { - return L.ApiParamError("Invalid combination of baDataTypes specified (%d)", dataTypes); + return L.ApiParamError(fmt::format(FMT_STRING("Invalid combination of baDataTypes specified (0x{:02x})"), dataTypes)); } // Create the area: if ((size.x <= 0) || (size.y <= 0) || (size.z <= 0)) { - return L.FApiParamError("Invalid sizes, must be greater than zero, got {0}", size); + return L.ApiParamError(fmt::format(FMT_STRING("Invalid sizes, must be greater than zero, got {}"), size)); } ASSERT(self != nullptr); self->Create(size, dataTypes); @@ -221,13 +221,13 @@ static int tolua_cBlockArea_FillRelCuboid(lua_State * a_LuaState) bounds.Sort(); if (!(self->IsValidRelCoords(bounds.p1) && self->IsValidRelCoords(bounds.p2))) { - return L.FApiParamError( - "The bounds ({0} - {1}) are out of range ({2} - {3})", + return L.ApiParamError(fmt::format( + FMT_STRING("The bounds ({0} - {1}) are out of range ({2} - {3})"), bounds.p1, bounds.p2, Vector3i(0, 0, 0), (self->GetSize() - Vector3i{1, 1, 1}) - ); + )); } int dataTypes = cBlockArea::baTypes | cBlockArea::baMetas | cBlockArea::baBlockEntities; BLOCKTYPE blockType; @@ -239,7 +239,7 @@ static int tolua_cBlockArea_FillRelCuboid(lua_State * a_LuaState) L.GetStackValues(nextIdx + 2, blockMeta, blockLight, blockSkyLight); // These values are optional if (!cBlockArea::IsValidDataTypeCombination(dataTypes)) { - return L.ApiParamError("Invalid baDataTypes combination (%d)", dataTypes); + return L.ApiParamError(fmt::format(FMT_STRING("Invalid baDataTypes combination (0x{:02x})"), dataTypes)); } // Do the actual Fill: @@ -275,9 +275,9 @@ static int tolua_cBlockArea_GetBlockTypeMeta(lua_State * a_LuaState) readVector3iOverloadParams(L, 2, coords, "coords"); if (!self->IsValidCoords(coords)) { - return L.FApiParamError("Coords ({0}) out of range ({1} - {2})", + return L.ApiParamError(fmt::format(FMT_STRING("Coords ({0}) out of range ({1} - {2})"), coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1} - ); + )); } BLOCKTYPE blockType; NIBBLETYPE blockMeta; @@ -425,9 +425,9 @@ static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * a_LuaState) readVector3iOverloadParams(L, 2, coords, "coords"); if (!self->IsValidRelCoords(coords)) { - return L.FApiParamError("The coords ({0}) are out of range (max {1})", + return L.ApiParamError(fmt::format(FMT_STRING("The coords ({0}) are out of range (max {1})"), coords, (self->GetSize() - Vector3i{1, 1, 1}) - ); + )); } BLOCKTYPE blockType; NIBBLETYPE blockMeta; @@ -587,13 +587,13 @@ static int tolua_cBlockArea_Read(lua_State * a_LuaState) L.GetStackValues(dataTypesIdx, dataTypes); if (!cBlockArea::IsValidDataTypeCombination(dataTypes)) { - return L.ApiParamError("Invalid baDataTypes combination (%d)", dataTypes); + return L.ApiParamError(fmt::format(FMT_STRING("Invalid baDataTypes combination (0x{:02x})"), dataTypes)); } // Check the coords: if (!cChunkDef::IsValidHeight(bounds.p1) || !cChunkDef::IsValidHeight(bounds.p2)) { - return L.FApiParamError("Coordinates {0} - {1} exceed world bounds", bounds.p1, bounds.p2); + return L.ApiParamError(fmt::format(FMT_STRING("Coordinates {0} - {1} exceed world bounds"), bounds.p1, bounds.p2)); } bounds.Sort(); @@ -636,13 +636,14 @@ static int tolua_cBlockArea_RelLine(lua_State * a_LuaState) L.GetStackValues(idx, dataTypes, blockType, blockMeta, blockLight, blockSkyLight); if (!cBlockArea::IsValidDataTypeCombination(dataTypes)) { - return L.ApiParamError("Invalid baDataTypes combination (%d)", dataTypes); + return L.ApiParamError(fmt::format(FMT_STRING("Invalid baDataTypes combination (0x{:02x})"), dataTypes)); } if ((self->GetDataTypes() & dataTypes) != dataTypes) { - return L.ApiParamError("Requested datatypes not present in the cBlockArea. Got only 0x%02x, requested 0x%02x", + return L.ApiParamError(fmt::format( + FMT_STRING("Requested datatypes not present in the cBlockArea. Got only 0x{:02x}, requested 0x{:02x}"), self->GetDataTypes(), dataTypes - ); + )); } // Draw the line: @@ -771,13 +772,14 @@ static int tolua_cBlockArea_Write(lua_State * a_LuaState) { if (!cBlockArea::IsValidDataTypeCombination(dataTypes)) { - return L.ApiParamError("Invalid datatype combination (%d)", dataTypes); + return L.ApiParamError(fmt::format(FMT_STRING("Invalid datatype combination (0x{:02x})"), dataTypes)); } if ((self->GetDataTypes() & dataTypes) != dataTypes) { - return L.ApiParamError("Requesting datatypes not present in the cBlockArea. Got only 0x%02x, requested 0x%02x", + return L.ApiParamError(fmt::format( + FMT_STRING("Requesting datatypes not present in the cBlockArea. Got only 0x{:02x}, requested 0x{:02x}"), self->GetDataTypes(), dataTypes - ); + )); } } @@ -844,7 +846,7 @@ static int GetBlock(lua_State * a_LuaState) // Check the datatype's presence: if ((self->GetDataTypes() & DataTypeFlag) == 0) { - return L.ApiParamError("The area doesn't contain the datatype (%d)", DataTypeFlag); + return L.ApiParamError(fmt::format(FMT_STRING("The area doesn't contain the datatype (0x{:02x})"), DataTypeFlag)); } // Read the overloaded params: @@ -852,9 +854,9 @@ static int GetBlock(lua_State * a_LuaState) readVector3iOverloadParams(L, 2, coords, "coords"); if (!self->IsValidCoords(coords)) { - return L.FApiParamError("The coords ({0}) are out of range ({1} - {2})", + return L.ApiParamError(fmt::format(FMT_STRING("The coords ({0}) are out of range ({1} - {2})"), coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1} - ); + )); } // Get the block info: @@ -895,7 +897,7 @@ static int GetRelBlock(lua_State * a_LuaState) // Check the datatype's presence: if ((self->GetDataTypes() & DataTypeFlag) == 0) { - return L.ApiParamError("The area doesn't contain the datatype (%d)", DataTypeFlag); + return L.ApiParamError(fmt::format(FMT_STRING("The area doesn't contain the datatype (0x{:02x})"), DataTypeFlag)); } // Read the overloaded params: @@ -903,9 +905,9 @@ static int GetRelBlock(lua_State * a_LuaState) readVector3iOverloadParams(L, 2, coords, "coords"); if (!self->IsValidRelCoords(coords)) { - return L.FApiParamError("The coords ({0}) are out of range ({1})", + return L.ApiParamError(fmt::format(FMT_STRING("The coords ({0}) are out of range ({1})"), coords, (self->GetSize() - Vector3i(1, 1, 1)) - ); + )); } // Get the block info: @@ -946,7 +948,7 @@ static int SetBlock(lua_State * a_LuaState) // Check the datatype's presence: if ((self->GetDataTypes() & DataTypeFlag) == 0) { - return L.ApiParamError("The area doesn't contain the datatype (%d)", DataTypeFlag); + return L.ApiParamError(fmt::format(FMT_STRING("The area doesn't contain the datatype (0x{:02x})"), DataTypeFlag)); } // Read the overloaded params: @@ -954,9 +956,9 @@ static int SetBlock(lua_State * a_LuaState) auto idx = readVector3iOverloadParams(L, 2, coords, "coords"); if (!self->IsValidCoords(coords)) { - return L.FApiParamError("The coords ({0}) are out of range ({1} - {2})", + return L.ApiParamError(fmt::format(FMT_STRING("The coords ({0}) are out of range ({1} - {2})"), coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1} - ); + )); } DataType data; L.GetStackValues(idx, data); @@ -999,7 +1001,7 @@ static int SetRelBlock(lua_State * a_LuaState) // Check the datatype's presence: if ((self->GetDataTypes() & DataTypeFlag) == 0) { - return L.ApiParamError("The area doesn't contain the datatype (%d)", DataTypeFlag); + return L.ApiParamError(fmt::format(FMT_STRING("The area doesn't contain the datatype (0x{:02x})"), DataTypeFlag)); } // Read the overloaded params: @@ -1007,9 +1009,10 @@ static int SetRelBlock(lua_State * a_LuaState) auto idx = readVector3iOverloadParams(L, 2, coords, "coords"); if (!self->IsValidRelCoords(coords)) { - return L.FApiParamError("The coords ({0}) are out of range ({1})", + return L.ApiParamError(fmt::format( + FMT_STRING("The coords ({0}) are out of range ({1})"), coords, (self->GetSize() - Vector3i(1, 1, 1)) - ); + )); } DataType data; L.GetStackValues(idx, data); @@ -1050,9 +1053,9 @@ static int tolua_cBlockArea_SetBlockTypeMeta(lua_State * a_LuaState) auto idx = readVector3iOverloadParams(L, 2, coords, "coords"); if (!self->IsValidCoords(coords)) { - return L.FApiParamError("The coords ({0}) are out of range ({1} - {2})", + return L.ApiParamError(fmt::format(FMT_STRING("The coords ({0}) are out of range ({1} - {2})"), coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1} - ); + )); } BLOCKTYPE block; @@ -1090,7 +1093,7 @@ static int tolua_cBlockArea_SetRelBlockTypeMeta(lua_State * a_LuaState) // Check if block types and metas are present: if (!self->HasBlockTypes() || !self->HasBlockMetas()) { - return L.ApiParamError("The area doesn't contain the baTypes or baMetas datatypes (0x%02x)", self->GetDataTypes()); + return L.ApiParamError(fmt::format(FMT_STRING("The area doesn't contain the baTypes or baMetas datatypes (0x{:02x})"), self->GetDataTypes())); } // Read the overloaded params: @@ -1098,9 +1101,9 @@ static int tolua_cBlockArea_SetRelBlockTypeMeta(lua_State * a_LuaState) auto idx = readVector3iOverloadParams(L, 2, coords, "coords"); if (!self->IsValidRelCoords(coords)) { - return L.FApiParamError("The coords ({0}) are out of range ({1})", + return L.ApiParamError(fmt::format(FMT_STRING("The coords ({0}) are out of range ({1})"), coords, (self->GetSize() - Vector3i(1, 1, 1)) - ); + )); } BLOCKTYPE block; diff --git a/src/Bindings/ManualBindings_Network.cpp b/src/Bindings/ManualBindings_Network.cpp index 911e1a8bb..67385cce6 100644 --- a/src/Bindings/ManualBindings_Network.cpp +++ b/src/Bindings/ManualBindings_Network.cpp @@ -51,7 +51,7 @@ static int tolua_cNetwork_Connect(lua_State * L) // Check validity: if ((port < 0) || (port > 65535)) { - return S.ApiParamError("Port number out of range (%d, range 0 - 65535)", port); + return S.ApiParamError(fmt::format(FMT_STRING("Port number out of range (got {}, range 0 - 65535)"), port)); } ASSERT(callbacks != nullptr); // Invalid callbacks would have resulted in GetStackValues() returning false @@ -97,7 +97,7 @@ static int tolua_cNetwork_CreateUDPEndpoint(lua_State * L) // Check validity: if ((port < 0) || (port > 65535)) { - return S.ApiParamError("Port number out of range (%d, range 0 - 65535)", port); + return S.ApiParamError(fmt::format(FMT_STRING("Port number out of range (got {}, range 0 - 65535)"), port)); } ASSERT(callbacks != nullptr); // Invalid callbacks would have resulted in GetStackValues() returning false @@ -242,7 +242,7 @@ static int tolua_cNetwork_Listen(lua_State * L) // Check the validity: if ((port < 0) || (port > 65535)) { - return S.ApiParamError("Port number out of range (%d, range 0 - 65535)", port); + return S.ApiParamError(fmt::format(FMT_STRING("Port number out of range (got {}, range 0 - 65535)"), port)); } auto port16 = static_cast<UInt16>(port); @@ -565,7 +565,10 @@ static int tolua_cTCPLink_StartTLSClient(lua_State * L) AString res = Link->StartTLSClient(OwnCert, OwnPrivKey, OwnPrivKeyPassword); if (!res.empty()) { - S.Push(cLuaState::Nil, Printf("Cannot start TLS on link to %s:%d: %s", Link->GetRemoteIP().c_str(), Link->GetRemotePort(), res.c_str())); + S.Push(cLuaState::Nil, fmt::format( + FMT_STRING("Cannot start TLS on link to {}:{}: {}"), + Link->GetRemoteIP(), Link->GetRemotePort(), res + )); return 2; } return 1; @@ -604,7 +607,10 @@ static int tolua_cTCPLink_StartTLSServer(lua_State * L) AString res = Link->StartTLSServer(OwnCert, OwnPrivKey, OwnPrivKeyPassword, StartTLSData); if (!res.empty()) { - S.Push(cLuaState::Nil, Printf("Cannot start TLS on link to %s:%d: %s", Link->GetRemoteIP().c_str(), Link->GetRemotePort(), res.c_str())); + S.Push(cLuaState::Nil, fmt::format( + FMT_STRING("Cannot start TLS on link to {}:{}: {}"), + Link->GetRemoteIP(), Link->GetRemotePort(), res + )); return 2; } S.Push(true); @@ -773,7 +779,7 @@ static int tolua_cUDPEndpoint_Send(lua_State * L) // Check the port: if ((remotePort < 0) || (remotePort > USHRT_MAX)) { - return S.ApiParamError("Port number out of range (%d, range 0 - 65535)", remotePort); + return S.ApiParamError(fmt::format(FMT_STRING("Port number out of range (got {}, range 0 - 65535)"), remotePort)); } // Send the data: @@ -958,14 +964,14 @@ static int tolua_cUrlClient_Request_Common(lua_State * a_LuaState, const AString cLuaState::cCallbackPtr onCompleteBodyCallback; if (!L.GetStackValues(a_UrlStackIdx, url)) { - return L.ApiParamError("Cannot read URL parameter at idx %d", a_UrlStackIdx); + return L.ApiParamError(fmt::format(FMT_STRING("Cannot read URL parameter at idx {}"), a_UrlStackIdx)); } cUrlClient::cCallbacksPtr urlClientCallbacks; if (lua_istable(L, a_UrlStackIdx + 1)) { if (!L.GetStackValue(a_UrlStackIdx + 1, callbacks)) { - return L.ApiParamError("Cannot read the CallbacksTable parameter at idx %d", a_UrlStackIdx + 1); + return L.ApiParamError(fmt::format(FMT_STRING("Cannot read the CallbacksTable parameter at idx {}"), a_UrlStackIdx + 1)); } urlClientCallbacks = std::make_unique<cFullUrlClientCallbacks>(std::move(callbacks)); } @@ -973,17 +979,23 @@ static int tolua_cUrlClient_Request_Common(lua_State * a_LuaState, const AString { if (!L.GetStackValue(a_UrlStackIdx + 1, onCompleteBodyCallback)) { - return L.ApiParamError("Cannot read the CallbackFn parameter at idx %d", a_UrlStackIdx + 1); + return L.ApiParamError(fmt::format(FMT_STRING("Cannot read the CallbackFn parameter at idx {}"), a_UrlStackIdx + 1)); } urlClientCallbacks = std::make_unique<cSimpleUrlClientCallbacks>(std::move(onCompleteBodyCallback)); } else { - L.ApiParamError("Invalid Callbacks parameter at %d, expected a table or function, got %s", a_UrlStackIdx + 1, L.GetTypeText(a_UrlStackIdx + 1).c_str()); + L.ApiParamError(fmt::format( + FMT_STRING("Invalid Callbacks parameter at {}, expected a table or function, got {}"), + a_UrlStackIdx + 1, L.GetTypeText(a_UrlStackIdx + 1) + )); } if (!L.GetStackValues(a_UrlStackIdx + 2, cLuaState::cOptionalParam<AStringMap>(headers), cLuaState::cOptionalParam<AString>(requestBody), cLuaState::cOptionalParam<AStringMap>(options))) { - L.ApiParamError("Cannot read the Header, Body or Options parameter at idx %d, %d, %d.", a_UrlStackIdx + 2, a_UrlStackIdx + 3, a_UrlStackIdx + 4); + L.ApiParamError(fmt::format( + FMT_STRING("Cannot read the Header, Body or Options parameter at idx {}, {}, {}."), + a_UrlStackIdx + 2, a_UrlStackIdx + 3, a_UrlStackIdx + 4 + )); } // Make the request: diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp index 72778e2bd..7713b8823 100644 --- a/src/Bindings/ManualBindings_World.cpp +++ b/src/Bindings/ManualBindings_World.cpp @@ -105,7 +105,7 @@ static int DoWithBlockEntityAt(lua_State * tolua_S) } if (!FnRef.IsValid()) { - return L.ApiParamError("Expected a valid callback function for parameter %i", OffsetIndex); + return L.ApiParamError(fmt::format(FMT_STRING("Expected a valid callback function for parameter {}"), OffsetIndex)); } // Call the DoWith function: @@ -159,7 +159,7 @@ static int ForEachInBox(lua_State * tolua_S) L.GetStackValues(1, Self, Box, FnRef); if ((Self == nullptr) || (Box == nullptr)) { - return L.ApiParamError("Invalid world (%p) or boundingbox (%p)", static_cast<void *>(Self), static_cast<void *>(Box)); + return L.ApiParamError(fmt::format(FMT_STRING("Invalid world ({}) or boundingbox ({})"), fmt::ptr(Self), fmt::ptr(Box))); } if (!FnRef.IsValid()) { diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index caa02acf9..41e2e14f7 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -34,7 +34,7 @@ cPluginLua::cPluginLua(const AString & a_PluginDirectory, cDeadlockDetect & a_DeadlockDetect) : cPlugin(a_PluginDirectory), - m_LuaState(Printf("plugin %s", a_PluginDirectory.c_str())), + m_LuaState(fmt::format(FMT_STRING("plugin {}"), a_PluginDirectory)), m_DeadlockDetect(a_DeadlockDetect) { m_LuaState.TrackInDeadlockDetect(a_DeadlockDetect); @@ -140,7 +140,7 @@ bool cPluginLua::Load(void) AString Path = PluginPath + *itr; if (!m_LuaState.LoadFile(Path)) { - SetLoadError(Printf("Failed to load file %s.", itr->c_str())); + SetLoadError(fmt::format(FMT_STRING("Failed to load file {}."), *itr)); Close(); return false; } diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index d7d09ed5a..4f48a07ea 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -335,14 +335,14 @@ bool cPluginManager::CallHookChat(cPlayer & a_Player, AString & a_Message) case crError: { // An error in the plugin has prevented the command from executing. Report the error to the player: - a_Player.SendMessageFailure(Printf("Something went wrong while executing command \"%s\"", a_Message.c_str())); + a_Player.SendMessageFailure(fmt::format(FMT_STRING("Something went wrong while executing command \"{}\""), a_Message)); return true; } case crNoPermission: { // The player is not allowed to execute this command - a_Player.SendMessageFailure(Printf("Forbidden command; insufficient privileges: \"%s\"", a_Message.c_str())); + a_Player.SendMessageFailure(fmt::format(FMT_STRING("Forbidden command; insufficient privileges: \"{}\""), a_Message)); return true; } @@ -358,8 +358,8 @@ bool cPluginManager::CallHookChat(cPlayer & a_Player, AString & a_Message) { AStringVector Split(StringSplit(a_Message, " ")); ASSERT(!Split.empty()); // This should not happen - we know there's at least one char in the message so the split needs to be at least one item long - a_Player.SendMessageInfo(Printf("Unknown command: \"%s\"", a_Message.c_str())); - LOGINFO("Player %s issued an unknown command: \"%s\"", a_Player.GetName().c_str(), a_Message.c_str()); + a_Player.SendMessageInfo(fmt::format(FMT_STRING("Unknown command: \"{}\""), a_Message)); + LOGINFO("Player %s issued an unknown command: \"%s\"", a_Player.GetName(), a_Message); return true; // Cancel sending } |