Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 734abb00 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

SCRIPT & UI: Get the last LUA error on script document load

parent b5cfe2af
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!16Add a way to execute a Lua file with Vivy in a click-click way
......@@ -45,31 +45,32 @@ ScriptStore::resetLoadedScripts() noexcept
luaContext.reset(new Script::LuaContext(streamOut, streamErr));
}
bool
std::optional<std::tuple<int, std::string>>
ScriptStore::executeScript(Uuid id) noexcept
{
const auto script = documents.at(id);
const bool ok = luaContext->loadDocument(script) == Code::Success;
QString errorString;
std::string buffer;
std::cout << "STDOUT:\n";
while (std::getline(streamOut, buffer, '\n'))
std::cout << buffer << "\n";
std::cout << '\t' << buffer << '\n';
std::cout << "STDERR:\n";
while (std::getline(streamErr, buffer, '\n'))
std::cout << buffer << "\n";
if (!ok)
std::cout << luaContext->getLastLuaError().toStdString();
if (luaContext->isFailed()) {
std::cout << "LuaContext is in failure mode!!\n";
std::cout << luaContext->getFailureDescription() << "\n";
return false;
if (!ok) {
// /home/.../sample-spec.module:31: bad argument #1 to 'export'...
std::cout << "STDERR:\n";
QRegExp errorDetect(QStringLiteral("^([^\\:]*)\\:(\\d+)\\:(.*)\\n?$"));
while (std::getline(streamErr, buffer, '\n')) {
std::cout << '\t' << buffer << '\n';
if (errorDetect.indexIn(buffer.c_str()) != -1) {
std::string errorDesc = errorDetect.cap(3).toStdString();
return std::tuple{ QString(errorDetect.cap(2)).toInt(), Utils::trim(errorDesc) };
}
}
}
return ok;
return std::nullopt;
}
const std::vector<std::string_view>
......
......@@ -3,6 +3,7 @@
#include "../CRTPStore.hh"
#include "ScriptDocument.hh"
#include <sstream>
#include <optional>
namespace Vivy::Script
{
......@@ -27,7 +28,7 @@ public:
void resetLoadedScripts() noexcept;
void loadScriptFolder(const QString &folderPath);
std::vector<Item> getLoadedScripts() const noexcept;
bool executeScript(Uuid) noexcept;
std::optional<std::tuple<int, std::string>> executeScript(Uuid) noexcept;
// Get modules from scripts
const std::vector<std::string_view> getLoadedModules() const noexcept;
......
......@@ -265,8 +265,21 @@ MainWindow::openDocument() noexcept
(fileType == Utils::DocumentType::Audio) || (fileType == Utils::DocumentType::ASS))
addTab(new VivyDocumentView(vivyApp->documentStore.loadDocument(filename), documents));
else if (fileType == Utils::DocumentType::VivyScript)
addTab(new ScriptDocumentView(vivyApp->scriptStore.loadDocument(filename), documents));
else if (fileType == Utils::DocumentType::VivyScript) {
// FIXME: First interpretation of the file to get the error, can do better.
std::shared_ptr<ScriptDocument> scriptDocument =
vivyApp->scriptStore.loadDocument(filename);
std::optional<std::tuple<int, std::string>> errorTuple =
vivyApp->scriptStore.executeScript(scriptDocument->getUuid());
ScriptDocumentView *newView = new ScriptDocumentView(scriptDocument, documents);
if (errorTuple.has_value()) {
const auto &[line, desc] = errorTuple.value();
emit newView->luaErrorFound(line, QString{ desc.c_str() });
}
addTab(newView);
}
} catch (const std::runtime_error &e) {
qCritical() << "Failed to load document" << filename << "with error:" << e.what();
}
......
......@@ -3,6 +3,7 @@
#include "ScriptViews/ScriptHighlighter.hh"
#include "../VivyApplication.hh"
#include <QRegExp>
#include <QVBoxLayout>
using namespace Vivy;
......@@ -21,6 +22,8 @@ ScriptDocumentView::ScriptDocumentView(std::shared_ptr<ScriptDocument> ptr, QWid
editor->setPlainText(textFile.readAll());
setCentralWidget(editor);
editor->setFocus(Qt::OtherFocusReason);
connect(this, &ScriptDocumentView::luaErrorFound, editor, &ScriptEditor::updateLastLuaError);
}
void
......
......@@ -32,10 +32,15 @@ public:
QIcon getDocumentTabIcon() const noexcept override;
AbstractDocument *getDocument() const noexcept override;
signals:
void luaErrorFound(int, QString);
private:
ScriptEditor *editor{ nullptr };
ScriptHighlighter *syntax{ nullptr };
std::shared_ptr<ScriptDocument> document{ nullptr };
QString lastLuaErrorMsg{};
int lastLuaErrorLine{ -1 };
};
}
......
......@@ -131,3 +131,9 @@ ScriptEditor::lineNumberAreaPaintEvent(QPaintEvent *event) noexcept
++blockNumber;
}
}
void
ScriptEditor::updateLastLuaError(int line, QString desc)
{
qDebug() << "Update error on line" << line << "with description" << desc;
}
......@@ -38,6 +38,9 @@ public:
void lineNumberAreaPaintEvent(QPaintEvent *event) noexcept;
int lineNumberAreaWidth() noexcept;
public slots:
void updateLastLuaError(int, QString);
protected:
void resizeEvent(QResizeEvent *event) noexcept override;
void keyPressEvent(QKeyEvent *e) noexcept override;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter