diff --git a/src/Lib/Script/LuaContext.cc b/src/Lib/Script/LuaContext.cc index 55aeff05149501021357ce0f3d875910087f7757..081b124dd15ce9482a4dcea0c40d10c7c8e92c7d 100644 --- a/src/Lib/Script/LuaContext.cc +++ b/src/Lib/Script/LuaContext.cc @@ -16,9 +16,6 @@ LuaContext::LuaContext(ScriptStore::LoggerType &out, ScriptStore::LoggerType &er , streamErr(err) { luaL_openlibs(L); - QFile libVivy(":lua/lib.lua"); - if (!libVivy.open(QIODevice::ReadOnly | QIODevice::Text)) - qFatal("Failed to find packaged libVivy (:lia/lib.lua)"); // Register this context contextList.emplace(L, this); @@ -31,7 +28,8 @@ LuaContext::LuaContext(ScriptStore::LoggerType &out, ScriptStore::LoggerType &er ModuleDeclaration::Register(L); // Load the lib - loadString(libVivy.readAll().toStdString().c_str()); + loadPackagedFile(":lua/lib.lua"); + loadPackagedFile(":lua/module.lua"); } LuaContext::~LuaContext() noexcept @@ -40,6 +38,15 @@ LuaContext::~LuaContext() noexcept contextList.erase(L); // Unregister the context } +void +LuaContext::loadPackagedFile(const QString &url) noexcept +{ + QFile libVivy(url); + if (!libVivy.open(QIODevice::ReadOnly | QIODevice::Text)) + qFatal("FATA -> failed to find packaged Vivy file %s", url.toStdString().c_str()); + loadString(libVivy.readAll().toStdString().c_str()); +} + LuaContext * LuaContext::getContext(const lua_State *const state) noexcept { @@ -79,7 +86,7 @@ LuaContext::Code LuaContext::loadString(const char *str) noexcept { if (luaL_loadstring(L, str) != LUA_OK) { - err(this) << "Error loading string\n"; + err(this) << "Error loading string: " << getLastError().toStdString() << "\n"; return Code::Error; } return exec(); @@ -89,7 +96,7 @@ LuaContext::Code LuaContext::loadFile(const char *file) noexcept { if (luaL_loadfile(L, file) != LUA_OK) { - err(this) << "Error loading file " << file << "\n"; + err(this) << "Error loading file " << file << ": " << getLastError().toStdString() << "\n"; return Code::Error; } return exec(); diff --git a/src/Lib/Script/LuaContext.hh b/src/Lib/Script/LuaContext.hh index de3dab5cdd936114aece632310e4782cfddc4f8f..651998093b548950f71e7103be48816e6cb9ef1a 100644 --- a/src/Lib/Script/LuaContext.hh +++ b/src/Lib/Script/LuaContext.hh @@ -48,6 +48,7 @@ private: Code loadString(const char *) noexcept; Code loadFile(const char *) noexcept; + void loadPackagedFile(const QString &) noexcept; // Swap the env, needed before executing a user script! void swapEnv() noexcept;