diff options
Diffstat (limited to 'src/script/cpp_api')
-rw-r--r-- | src/script/cpp_api/s_base.cpp | 22 | ||||
-rw-r--r-- | src/script/cpp_api/s_base.h | 4 |
2 files changed, 13 insertions, 13 deletions
diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index 8b0b16bfb..e02a6aa0d 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -119,14 +119,14 @@ ScriptApiBase::~ScriptApiBase() } bool ScriptApiBase::loadMod(const std::string &script_path, - const std::string &mod_name) + const std::string &mod_name, std::string *error) { ModNameStorer mod_name_storer(getStack(), mod_name); - return loadScript(script_path); + return loadScript(script_path, error); } -bool ScriptApiBase::loadScript(const std::string &script_path) +bool ScriptApiBase::loadScript(const std::string &script_path, std::string *error) { verbosestream << "Loading and running script from " << script_path << std::endl; @@ -140,13 +140,14 @@ bool ScriptApiBase::loadScript(const std::string &script_path) } ok = ok && !lua_pcall(L, 0, 0, m_errorhandler); if (!ok) { - errorstream << "========== ERROR FROM LUA ===========" << std::endl; - errorstream << "Failed to load and run script from " << std::endl; - errorstream << script_path << ":" << std::endl; - errorstream << std::endl; - errorstream << lua_tostring(L, -1) << std::endl; - errorstream << std::endl; - errorstream << "======= END OF ERROR FROM LUA ========" << std::endl; + std::string error_msg = lua_tostring(L, -1); + if (error) + (*error) = error_msg; + errorstream << "========== ERROR FROM LUA ===========" << std::endl + << "Failed to load and run script from " << std::endl + << script_path << ":" << std::endl << std::endl + << error_msg << std::endl << std::endl + << "======= END OF ERROR FROM LUA ========" << std::endl; lua_pop(L, 1); // Pop error message from stack return false; } @@ -268,4 +269,3 @@ void ScriptApiBase::objectrefGet(lua_State *L, u16 id) lua_remove(L, -2); // object_refs lua_remove(L, -2); // core } - diff --git a/src/script/cpp_api/s_base.h b/src/script/cpp_api/s_base.h index cf9b7b934..ee2835da2 100644 --- a/src/script/cpp_api/s_base.h +++ b/src/script/cpp_api/s_base.h @@ -51,8 +51,8 @@ public: ScriptApiBase(); virtual ~ScriptApiBase(); - bool loadMod(const std::string &script_path, const std::string &mod_name); - bool loadScript(const std::string &script_path); + bool loadMod(const std::string &script_path, const std::string &mod_name, std::string *error=NULL); + bool loadScript(const std::string &script_path, std::string *error=NULL); /* object */ void addObjectReference(ServerActiveObject *cobj); |