aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api
diff options
context:
space:
mode:
authorrubenwardy <rubenwardy@gmail.com>2015-03-02 18:26:20 +0000
committerest31 <MTest31@outlook.com>2015-06-29 04:47:35 +0200
commit0d65ee878c5301afdbd163aa2274e73588f88ed3 (patch)
tree52b99028770dcbeb7cbb6a6f3f3030a83e5549f5 /src/script/cpp_api
parent1455267c9e66f64cd49e01aac782060c95bb925e (diff)
downloadminetest-0d65ee878c5301afdbd163aa2274e73588f88ed3.tar.gz
minetest-0d65ee878c5301afdbd163aa2274e73588f88ed3.tar.bz2
minetest-0d65ee878c5301afdbd163aa2274e73588f88ed3.zip
Add Lua errors to error dialog
Diffstat (limited to 'src/script/cpp_api')
-rw-r--r--src/script/cpp_api/s_base.cpp22
-rw-r--r--src/script/cpp_api/s_base.h4
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);