From c9522fb740200ccef6230cec452c48efb31e5394 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 11 May 2023 22:05:17 +0200 Subject: Removed all Printf-family functions from StringUtils. Replaced them with fmt::format calls, including changes to the format strings. Also changed the format strings to use FMT_STRING, so that the format is checked compile-time against the arguments. Also fixed code-style violations already present in the code. --- src/Bindings/LuaState.h | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) (limited to 'src/Bindings/LuaState.h') 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 - 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 - 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); -- cgit v1.2.3