From 8b171e3a7e006aa492e2369969999a2336e2a731 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sat, 17 Jan 2009 16:21:58 +0100 Subject: Made script error reports more informative and readable --- src/scripting/lua.cpp | 11 ++++++++--- src/scripting/script.cpp | 6 +++++- src/scripting/script.hpp | 5 ++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index e2be2d3f..aead80cb 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -93,6 +93,7 @@ class LuaScript: public Script lua_State *mState; int nbArgs; + std::string mCurFunction; }; static char const registryKey = 0; @@ -1213,6 +1214,7 @@ void LuaScript::prepare(std::string const &name) assert(nbArgs == -1); lua_getglobal(mState, name.c_str()); nbArgs = 0; + mCurFunction = name; } void LuaScript::push(int v) @@ -1244,15 +1246,18 @@ int LuaScript::execute() if (res || !(lua_isnil(mState, 1) || lua_isnumber(mState, 1))) { char const *s = lua_tostring(mState, 1); - LOG_WARN("Failure while calling Lua function: error=" << res - << ", type=" << lua_typename(mState, lua_type(mState, 1)) - << ", message=" << (s ? s : "")); + + LOG_WARN("Lua Script Error" << std::endl + << " Script : " << mScriptFile << std::endl + << " Function: " << mCurFunction << std::endl + << " Error : " << (s ? s : "") << std::endl); lua_pop(mState, 1); return 0; } res = lua_tointeger(mState, 1); lua_pop(mState, 1); return res; + mCurFunction = ""; } void LuaScript::load(char const *prog) diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp index ea1721f9..a20efb5c 100644 --- a/src/scripting/script.cpp +++ b/src/scripting/script.cpp @@ -69,14 +69,18 @@ void Script::update() execute(); } -void Script::loadFile(std::string const &name) +bool Script::loadFile(std::string const &name) { int size; char *buffer = ResourceManager::loadFile(name, size); if (buffer) { + mScriptFile = name; load(buffer); free(buffer); + return true; + } else { + return false; } } diff --git a/src/scripting/script.hpp b/src/scripting/script.hpp index fad6ad95..c87bf182 100644 --- a/src/scripting/script.hpp +++ b/src/scripting/script.hpp @@ -68,7 +68,7 @@ class Script * Loads a text file into script context and executes its global * statements. */ - virtual void loadFile(std::string const &); + virtual bool loadFile(std::string const &); /** * Loads a chunk of text and considers it as an NPC handler. This @@ -129,6 +129,9 @@ class Script virtual void processDeathEvent(Being* thing) = 0; + protected: + std::string mScriptFile; + private: MapComposite *mMap; EventListener mEventListener; /**< Tracking of being deaths. */ -- cgit v1.2.3-60-g2f50