From 525e108b83a6a47bde3a4259fb3d06f33a044170 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Mon, 15 Dec 2014 16:15:33 +0200 Subject: [PATCH] Implement log print functions --- GlobalMethods.h | 41 +++++++++++++++++++++++++++++++++++++++++ LuaFunctions.cpp | 3 +++ 2 files changed, 44 insertions(+) diff --git a/GlobalMethods.h b/GlobalMethods.h index cd7b731..c179582 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -2279,5 +2279,46 @@ namespace LuaGlobalFunctions Eluna::Push(E->L, ElunaUtil::GetTimeDiff(oldtimems)); return 1; } + + std::string GetStackAsString(Eluna* E) + { + std::ostringstream oss; + for (int i = 1; i <= lua_gettop(E->L); ++i) + oss << luaL_tolstring(E->L, i, NULL); + return oss.str(); + } + + /** + * Prints given parameters to the info log + * + * @param ... variableArguments + */ + int PrintInfo(Eluna* E) + { + ELUNA_LOG_INFO("%s", GetStackAsString(E).c_str()); + return 0; + } + + /** + * Prints given parameters to the error log + * + * @param ... variableArguments + */ + int PrintError(Eluna* E) + { + ELUNA_LOG_ERROR("%s", GetStackAsString(E).c_str()); + return 0; + } + + /** + * Prints given parameters to the debug log + * + * @param ... variableArguments + */ + int PrintDebug(Eluna* E) + { + ELUNA_LOG_DEBUG("%s", GetStackAsString(E).c_str()); + return 0; + } } #endif diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index a0a84cd..29cc80a 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -87,6 +87,9 @@ ElunaGlobal::ElunaRegister GlobalMethods[] = { "GetMapById", &LuaGlobalFunctions::GetMapById }, { "GetCurrTime", &LuaGlobalFunctions::GetCurrTime }, { "GetTimeDiff", &LuaGlobalFunctions::GetTimeDiff }, + { "PrintInfo", &LuaGlobalFunctions::PrintInfo }, + { "PrintError", &LuaGlobalFunctions::PrintError }, + { "PrintDebug", &LuaGlobalFunctions::PrintDebug }, // Boolean { "IsInventoryPos", &LuaGlobalFunctions::IsInventoryPos },