From: Perttu Ahola Date: Fri, 2 Dec 2011 20:49:54 +0000 (+0200) Subject: Fix script error reporting a bit X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=581f950e10b40f2af4ede56c3fa78f13eccb610b;p=zefram%2Fminetest%2Fminetest_engine.git Fix script error reporting a bit --- diff --git a/src/script.cpp b/src/script.cpp index 16d8030d..5a6c9802 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -35,10 +35,11 @@ void script_error(lua_State *L, const char *fmt, ...) { va_list argp; va_start(argp, fmt); - vfprintf(stderr, fmt, argp); + char buf[10000]; + vsnprintf(buf, 10000, fmt, argp); va_end(argp); - lua_close(L); - exit(EXIT_FAILURE); + //errorstream<<"SCRIPT ERROR: "< +#include + +class LuaError : public std::exception +{ +public: + LuaError(const std::string &s) + { + m_s = "LuaError: "; + m_s += s; + } + virtual ~LuaError() throw() + {} + virtual const char * what() const throw() + { + return m_s.c_str(); + } + std::string m_s; +}; + typedef struct lua_State lua_State; -//#include lua_State* script_init(); void script_deinit(lua_State *L); diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index cb26fa47..db6b7e86 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -1101,7 +1101,10 @@ static int l_register_craft(lua_State *L) width = colcount; } else { if(colcount != width){ - script_error(L, "error: %s\n", "Invalid crafting recipe"); + std::string error; + error += "Invalid crafting recipe (output=\"" + + output + "\")"; + throw LuaError(error); } } // removes value, keeps key for next iteration @@ -2469,6 +2472,21 @@ void scriptapi_export(lua_State *L, Server *server) ObjectRef::Register(L); } +bool scriptapi_loadmod(lua_State *L, const std::string &scriptpath, + const std::string &modname) +{ + bool success = false; + + try{ + success = script_load(L, scriptpath.c_str()); + } + catch(LuaError &e){ + errorstream<<"Error loading mod: "< mods = getMods(m_modspaths); @@ -991,11 +991,11 @@ Server::Server( ModSpec mod = *i; infostream<<"Server: Loading mod \""<