From 1682f2fbb126f01c1cd63d771ba600e891d847cd Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Mon, 16 Aug 2021 14:56:58 +0200 Subject: [PATCH] SCRIPT: Be explicit about methods to get last Lua error + only load the module file, the implementation file will be loaded after (because implementation file is setted in the module file) --- src/Lib/Script/LuaContext.cc | 9 +++++---- src/Lib/Script/LuaContext.hh | 4 +++- src/Lib/Script/ScriptStore.cc | 2 +- src/Lib/Utils.hh | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Lib/Script/LuaContext.cc b/src/Lib/Script/LuaContext.cc index bc298d9c..0b15a539 100644 --- a/src/Lib/Script/LuaContext.cc +++ b/src/Lib/Script/LuaContext.cc @@ -78,7 +78,7 @@ LuaContext::Code LuaContext::exec() noexcept { if (lua_pcall(L, 0, 0, 0) != LUA_OK) { - err(this) << getLastError().toStdString().c_str() << "\n"; + err(this) << getLastLuaError().toStdString().c_str() << "\n"; return Code::Error; } return Code::Success; @@ -88,7 +88,7 @@ LuaContext::Code LuaContext::loadString(const char *str) noexcept { if (luaL_loadstring(L, str) != LUA_OK) { - err(this) << "Error loading string: " << getLastError().toStdString() << "\n"; + err(this) << "Error loading string: " << getLastLuaError().toStdString() << "\n"; return Code::Error; } return exec(); @@ -99,7 +99,8 @@ LuaContext::loadFile(const char *file) noexcept { currentFile = file; if (luaL_loadfile(L, file) != LUA_OK) { - err(this) << "Error loading file " << file << ": " << getLastError().toStdString() << "\n"; + err(this) + << "Error loading file " << file << ": " << getLastLuaError().toStdString() << "\n"; currentFile = ""; return Code::Error; } @@ -109,7 +110,7 @@ LuaContext::loadFile(const char *file) noexcept } QString -LuaContext::getLastError() noexcept +LuaContext::getLastLuaError() noexcept { const char *error = lua_tostring(L, -1); QString ret = QString("%1").arg(error); diff --git a/src/Lib/Script/LuaContext.hh b/src/Lib/Script/LuaContext.hh index 2e165626..63abb7ca 100644 --- a/src/Lib/Script/LuaContext.hh +++ b/src/Lib/Script/LuaContext.hh @@ -41,7 +41,7 @@ public: ~LuaContext() noexcept; Code loadDocument(std::shared_ptr<ScriptDocument>) noexcept; - QString getLastError() noexcept; + QString getLastLuaError() noexcept; lua_State *getState() noexcept; auto &getOutputStream() noexcept { return streamOut; } @@ -59,6 +59,8 @@ public: const ModuleDeclaration *getModule(const std::string_view) const noexcept; const std::vector<std::string_view> getAllModuleName() const noexcept; + // Some verifications gone wrong, this is not a Lua error, this is a script + // runtime error. void setFailed(const std::string &) noexcept; bool isFailed() const noexcept; const std::string &getFailureDescription() const noexcept; diff --git a/src/Lib/Script/ScriptStore.cc b/src/Lib/Script/ScriptStore.cc index ad8e16e5..6a0d6f8f 100644 --- a/src/Lib/Script/ScriptStore.cc +++ b/src/Lib/Script/ScriptStore.cc @@ -19,7 +19,7 @@ ScriptStore::loadScriptFolder(const QString &folderPath) if (luaContext->loadDocument(doc) != Script::LuaContext::Code::Success) { const QString error = QStringLiteral("File: ") + file + QStringLiteral(" [") + doc->getUuid().toString() + QStringLiteral("]") + - luaContext->getLastError(); + luaContext->getLastLuaError(); throw std::runtime_error(error.toStdString()); } } diff --git a/src/Lib/Utils.hh b/src/Lib/Utils.hh index 8c5a483b..bf61eedb 100644 --- a/src/Lib/Utils.hh +++ b/src/Lib/Utils.hh @@ -53,7 +53,7 @@ static const QStringList audioFileSuffix = { "wave", "wav", "ogg", "mp3", "m4 static const QStringList videoFileSuffix = { "mkv", "mp4", "mov", "avi", "av1", "m4v", "flv" }; static const QStringList assFileSuffix = { "ass" }; static const QStringList vivyFileSuffix = { "vivy" }; -static const QStringList scriptFileSuffix = { "lua", "vvs" }; +static const QStringList scriptFileSuffix = { "module" }; const QString &getAudioFileSuffixFilter() noexcept; const QString &getVideoFileSuffixFilter() noexcept; -- GitLab