summaryrefslogtreecommitdiffstats
path: root/src/Bindings/LuaState.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Bindings/LuaState.cpp')
-rw-r--r--src/Bindings/LuaState.cpp60
1 files changed, 30 insertions, 30 deletions
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));
}