summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/script/cpp_api/s_base.cpp22
-rw-r--r--src/script/cpp_api/s_base.h4
-rw-r--r--src/server.cpp32
3 files changed, 29 insertions, 29 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);
diff --git a/src/server.cpp b/src/server.cpp
index 0e3d94fae..f69c5a935 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -239,11 +239,9 @@ Server::Server(
m_mods = modconf.getMods();
std::vector<ModSpec> unsatisfied_mods = modconf.getUnsatisfiedMods();
// complain about mods with unsatisfied dependencies
- if(!modconf.isConsistent())
- {
+ if(!modconf.isConsistent()) {
for(std::vector<ModSpec>::iterator it = unsatisfied_mods.begin();
- it != unsatisfied_mods.end(); ++it)
- {
+ it != unsatisfied_mods.end(); ++it) {
ModSpec mod = *it;
errorstream << "mod \"" << mod.name << "\" has unsatisfied dependencies: ";
for(std::set<std::string>::iterator dep_it = mod.unsatisfied_depends.begin();
@@ -259,8 +257,7 @@ Server::Server(
std::vector<std::string> names = worldmt_settings.getNames();
std::set<std::string> load_mod_names;
for(std::vector<std::string>::iterator it = names.begin();
- it != names.end(); ++it)
- {
+ it != names.end(); ++it) {
std::string name = *it;
if(name.compare(0,9,"load_mod_")==0 && worldmt_settings.getBool(name))
load_mod_names.insert(name.substr(9));
@@ -272,8 +269,7 @@ Server::Server(
for(std::vector<ModSpec>::iterator it = unsatisfied_mods.begin();
it != unsatisfied_mods.end(); ++it)
load_mod_names.erase((*it).name);
- if(!load_mod_names.empty())
- {
+ if(!load_mod_names.empty()) {
errorstream << "The following mods could not be found:";
for(std::set<std::string>::iterator it = load_mod_names.begin();
it != load_mod_names.end(); ++it)
@@ -296,15 +292,16 @@ Server::Server(
m_script = new GameScripting(this);
std::string script_path = getBuiltinLuaPath() + DIR_DELIM "init.lua";
+ std::string error_msg;
- if (!m_script->loadMod(script_path, BUILTIN_MOD_NAME)) {
- throw ModError("Failed to load and run " + script_path);
- }
+ if (!m_script->loadMod(script_path, BUILTIN_MOD_NAME, &error_msg))
+ throw ModError("Failed to load and run " + script_path
+ + "\nError from Lua:\n" + error_msg);
// Print mods
infostream << "Server: Loading mods: ";
for(std::vector<ModSpec>::iterator i = m_mods.begin();
- i != m_mods.end(); i++){
+ i != m_mods.end(); i++) {
const ModSpec &mod = *i;
infostream << mod.name << " ";
}
@@ -314,18 +311,21 @@ Server::Server(
i != m_mods.end(); i++) {
const ModSpec &mod = *i;
if (!string_allowed(mod.name, MODNAME_ALLOWED_CHARS)) {
- errorstream << "Error loading mod \"" << mod.name
+ std::ostringstream err;
+ err << "Error loading mod \"" << mod.name
<< "\": mod_name does not follow naming conventions: "
<< "Only chararacters [a-z0-9_] are allowed." << std::endl;
- throw ModError("Mod \"" + mod.name + "\" does not follow naming conventions.");
+ errorstream << err.str().c_str();
+ throw ModError(err.str());
}
std::string script_path = mod.path + DIR_DELIM "init.lua";
infostream << " [" << padStringRight(mod.name, 12) << "] [\""
<< script_path << "\"]" << std::endl;
- if (!m_script->loadMod(script_path, mod.name)) {
+ if (!m_script->loadMod(script_path, mod.name, &error_msg)) {
errorstream << "Server: Failed to load and run "
<< script_path << std::endl;
- throw ModError("Failed to load and run " + script_path);
+ throw ModError("Failed to load and run " + script_path
+ + "\nError from Lua:\n" + error_msg);
}
}