Implement log print functions

This commit is contained in:
Rochet2
2014-12-15 16:15:33 +02:00
parent e683f48fbb
commit 525e108b83
2 changed files with 44 additions and 0 deletions

View File

@@ -2279,5 +2279,46 @@ namespace LuaGlobalFunctions
Eluna::Push(E->L, ElunaUtil::GetTimeDiff(oldtimems)); Eluna::Push(E->L, ElunaUtil::GetTimeDiff(oldtimems));
return 1; 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 #endif

View File

@@ -87,6 +87,9 @@ ElunaGlobal::ElunaRegister GlobalMethods[] =
{ "GetMapById", &LuaGlobalFunctions::GetMapById }, { "GetMapById", &LuaGlobalFunctions::GetMapById },
{ "GetCurrTime", &LuaGlobalFunctions::GetCurrTime }, { "GetCurrTime", &LuaGlobalFunctions::GetCurrTime },
{ "GetTimeDiff", &LuaGlobalFunctions::GetTimeDiff }, { "GetTimeDiff", &LuaGlobalFunctions::GetTimeDiff },
{ "PrintInfo", &LuaGlobalFunctions::PrintInfo },
{ "PrintError", &LuaGlobalFunctions::PrintError },
{ "PrintDebug", &LuaGlobalFunctions::PrintDebug },
// Boolean // Boolean
{ "IsInventoryPos", &LuaGlobalFunctions::IsInventoryPos }, { "IsInventoryPos", &LuaGlobalFunctions::IsInventoryPos },