summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-01-17 16:21:58 +0100
committerPhilipp Sehmisch <crush@themanaworld.org>2009-01-17 16:21:58 +0100
commit8b171e3a7e006aa492e2369969999a2336e2a731 (patch)
tree1642226437301217570c242038f230afd46ddb58
parent2f28f585b12880d3cddab9d634fedff2f5954485 (diff)
downloadmanaserv-8b171e3a7e006aa492e2369969999a2336e2a731.tar.gz
manaserv-8b171e3a7e006aa492e2369969999a2336e2a731.tar.bz2
manaserv-8b171e3a7e006aa492e2369969999a2336e2a731.tar.xz
manaserv-8b171e3a7e006aa492e2369969999a2336e2a731.zip
Made script error reports more informative and readable
-rw-r--r--src/scripting/lua.cpp11
-rw-r--r--src/scripting/script.cpp6
-rw-r--r--src/scripting/script.hpp5
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. */