From 4727ed20846bb3d1a9eabb27aaaa9c5524129556 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Mon, 24 Sep 2018 21:33:39 +0100 Subject: Add a formatting function for Vector3 (#4282) * Vector3: Add custom fmt compatible formatter. * cLuaState: Add fmt version of ApiParamError * Use vector formatting in manual bindings * Always log vectors with FLOG --- src/Bindings/LuaState.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/Bindings/LuaState.h') diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 2510c6f0b..362f16e21 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -820,11 +820,29 @@ public: /** Logs all items in the current stack trace to the server console */ static void LogStackTrace(lua_State * a_LuaState, int a_StartingDepth = 0); - /** Formats and prints the message, prefixed with the current function name, then logs the stack contents and raises a Lua error. + /** Prints the message, 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(...)". */ - int ApiParamError(const char * a_MsgFormat, fmt::ArgList); - FMT_VARIADIC(int, ApiParamError, const char *) + int ApiParamError(fmt::StringRef 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