summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/lua/libmana-constants.lua7
-rw-r--r--src/scripting/lua.cpp16
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);