From 30b9a7ddb40c0c383cbb710a67d8c6491ef13782 Mon Sep 17 00:00:00 2001 From: Ablu Date: Sun, 26 Jun 2011 20:11:54 +0200 Subject: Added Lua function for logging. You can now call mana.log(loglevel, message) to log messages with scripts. For loglevel you can use the new constants defined in libmana-constants.lua Resolves: Mana-Mantis #359 --- src/scripting/lua.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/scripting/lua.cpp') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index e48a274..ab5d656 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1780,6 +1780,21 @@ static int item_drop(lua_State *s) return 0; } +/** + * Logs the given message to the log + */ +static int log(lua_State *s) +{ + const int loglevel = luaL_checkint(s, 1); + const std::string message = lua_tostring(s, 2); + + if (loglevel >= utils::Logger::Fatal && loglevel <= utils::Logger::Debug) + utils::Logger::output(message, (utils::Logger::Level) loglevel); + else + raiseScriptError(s, "log called with unknown loglevel"); + + return 0; +} static int require_loader(lua_State *s) { @@ -1879,6 +1894,7 @@ LuaScript::LuaScript(): { "npc_ask_integer", &npc_ask_integer }, { "npc_end", &npc_end }, { "npc_ask_string", &npc_ask_string }, + { "log", &log }, { NULL, NULL } }; luaL_register(mState, "mana", callbacks); -- cgit