diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-08-22 03:41:39 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-08-22 13:11:38 +0200 |
commit | 59b889008760325845aeb04b7ac3fad5e1068c0f (patch) | |
tree | 77f42c8258f39d001cef07e5f7d039e53cec512e /src/scripting/lua.cpp | |
parent | 6f122fd544e0c77cc6c38a294a353d7bd4accf9d (diff) | |
download | manaserv-59b889008760325845aeb04b7ac3fad5e1068c0f.tar.gz manaserv-59b889008760325845aeb04b7ac3fad5e1068c0f.tar.bz2 manaserv-59b889008760325845aeb04b7ac3fad5e1068c0f.tar.xz manaserv-59b889008760325845aeb04b7ac3fad5e1068c0f.zip |
Print out a backtrace when a Lua error is raised
The backtrace is printed by using debug.traceback as error handler when
calling Lua functions. At the moment it still looks pretty ugly since
Lua is not aware of the file names of the scripts (to be fixed).
Reviewed-by: Jared Adams
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r-- | src/scripting/lua.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index c4c215d3..945392e1 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1,6 +1,7 @@ /* * The Mana Server * Copyright (C) 2007-2010 The Mana World Development Team + * Copyright (C) 2010 The Mana Developers * * This file is part of The Mana Server. * @@ -1710,12 +1711,17 @@ LuaScript::LuaScript(): { NULL, NULL } }; luaL_register(mState, "mana", callbacks); + lua_pop(mState, 1); // pop the 'mana' table // Make script object available to callback functions. lua_pushlightuserdata(mState, (void *)®istryKey); lua_pushlightuserdata(mState, this); lua_settable(mState, LUA_REGISTRYINDEX); - lua_settop(mState, 0); + // Push the error handler to first index of the stack + lua_getglobal(mState, "debug"); + lua_getfield(mState, -1, "traceback"); + lua_remove(mState, 1); // remove the 'debug' table + loadFile("scripts/lua/libmana.lua"); } |