diff options
author | Ablu <ablu.erikschilling@googlemail.com> | 2011-06-26 20:11:54 +0200 |
---|---|---|
committer | Philipp Sehmisch <manasource@crushnet.org> | 2011-06-27 17:30:42 +0200 |
commit | 30b9a7ddb40c0c383cbb710a67d8c6491ef13782 (patch) | |
tree | 96e2044d11e5f79b13e9b11c1b046546a27f5602 | |
parent | b4589749217c550db0849b439b6687ff4f5822d7 (diff) | |
download | manaserv-30b9a7ddb40c0c383cbb710a67d8c6491ef13782.tar.gz manaserv-30b9a7ddb40c0c383cbb710a67d8c6491ef13782.tar.bz2 manaserv-30b9a7ddb40c0c383cbb710a67d8c6491ef13782.tar.xz manaserv-30b9a7ddb40c0c383cbb710a67d8c6491ef13782.zip |
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
-rw-r--r-- | scripts/lua/libmana-constants.lua | 7 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 16 |
2 files changed, 23 insertions, 0 deletions
diff --git a/scripts/lua/libmana-constants.lua b/scripts/lua/libmana-constants.lua index 8399406b..912216c9 100644 --- a/scripts/lua/libmana-constants.lua +++ b/scripts/lua/libmana-constants.lua @@ -113,3 +113,10 @@ SKILL_WEAPON_SHOOTING = 107 SKILL_WEAPON_MACE = 108 SKILL_WEAPON_AXE = 109 SKILL_WEAPON_THROWN = 110 + +-- Loglevels +LOG_FATAL = 0 +LOG_ERROR = 1 +LOG_WARN = 2 +LOG_INFO = 3 +LOG_DEBUG = 4 diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index e48a274f..ab5d6566 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); |