aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_base.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2019-11-08 20:01:47 +0100
committersfan5 <sfan5@live.de>2019-11-09 16:08:38 +0100
commit82a2e02323615473fc3039508b4c4529591e27d9 (patch)
tree3d66f3bf530df8403cdf77199d15a1a9a3fea384 /src/script/cpp_api/s_base.cpp
parent5ab546f99bf3f438a8d19a3582798b5ab98476d6 (diff)
downloaddragonfireclient-82a2e02323615473fc3039508b4c4529591e27d9.tar.xz
Load client mods into memory before execution.
Preperation for server-sent CSM which will eventually need this.
Diffstat (limited to 'src/script/cpp_api/s_base.cpp')
-rw-r--r--src/script/cpp_api/s_base.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp
index caa335d76..1f40bb06a 100644
--- a/src/script/cpp_api/s_base.cpp
+++ b/src/script/cpp_api/s_base.cpp
@@ -197,18 +197,22 @@ void ScriptApiBase::loadModFromMemory(const std::string &mod_name)
{
ModNameStorer mod_name_storer(getStack(), mod_name);
- const std::string *init_filename = getClient()->getModFile(mod_name + ":init.lua");
- const std::string display_filename = mod_name + ":init.lua";
- if(init_filename == NULL)
- throw ModError("Mod:\"" + mod_name + "\" lacks init.lua");
+ sanity_check(m_type == ScriptingType::Client);
- verbosestream << "Loading and running script " << display_filename << std::endl;
+ const std::string init_filename = mod_name + ":init.lua";
+ const std::string chunk_name = "@" + init_filename;
+
+ const std::string *contents = getClient()->getModFile(init_filename);
+ if (!contents)
+ throw ModError("Mod \"" + mod_name + "\" lacks init.lua");
+
+ verbosestream << "Loading and running script " << chunk_name << std::endl;
lua_State *L = getStack();
int error_handler = PUSH_ERROR_HANDLER(L);
- bool ok = ScriptApiSecurity::safeLoadFile(L, init_filename->c_str(), display_filename.c_str());
+ bool ok = ScriptApiSecurity::safeLoadString(L, *contents, chunk_name.c_str());
if (ok)
ok = !lua_pcall(L, 0, 0, error_handler);
if (!ok) {