From 16beb55484c20b8b1e92afdf5720fa3860d77309 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 28 Dec 2018 12:30:48 +0100 Subject: Show error line in red in the editor. --- src/codeeditor.cc | 14 ++++++++++++++ src/codeeditor.h | 2 ++ src/luascript.cc | 5 +++++ src/luascript.h | 1 + src/mainwindow.cc | 2 ++ 5 files changed, 24 insertions(+) diff --git a/src/codeeditor.cc b/src/codeeditor.cc index d639953..6d2dd2e 100644 --- a/src/codeeditor.cc +++ b/src/codeeditor.cc @@ -129,6 +129,16 @@ void CodeEditor::highlightCurrentLine() void CodeEditor::runningLine(int lineno) { lineNumber = lineno; + errorLineNumber = 0; // no error + repaint(); +} + +void CodeEditor::errorLine(QString file, int lineno, QString msg) +{ + (void)file; + (void)msg; + lineNumber = 0; + errorLineNumber = lineno; repaint(); } @@ -152,6 +162,10 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) { painter.setPen(Qt::green); } + else if(blockNumber + 1 == errorLineNumber) + { + painter.setPen(Qt::red); + } else { painter.setPen(Qt::black); diff --git a/src/codeeditor.h b/src/codeeditor.h index a470a52..f25cdbf 100644 --- a/src/codeeditor.h +++ b/src/codeeditor.h @@ -67,6 +67,7 @@ protected: public slots: void runningLine(int lineno); + void errorLine(QString file, int lineno, QString msg); private slots: void updateLineNumberAreaWidth(int newBlockCount); @@ -76,6 +77,7 @@ private slots: private: QWidget *lineNumberArea; int lineNumber; + int errorLineNumber{0}; }; class LineNumberArea diff --git a/src/luascript.cc b/src/luascript.cc index dce5e2c..0619228 100644 --- a/src/luascript.cc +++ b/src/luascript.cc @@ -448,6 +448,11 @@ void LUAScript::run() catch(Exception &e) { printf("LUA Error: %s\n", e.msg.c_str()); + QStringList pieces = QString(e.msg.c_str()).split(":"); + if(pieces.size() >= 3) + { + emit errorLine(pieces[0], pieces[1].toUInt(), pieces[2]); + } } cleanup(); lua_stopped = true; diff --git a/src/luascript.h b/src/luascript.h index b88e023..ab89a60 100644 --- a/src/luascript.h +++ b/src/luascript.h @@ -78,6 +78,7 @@ public slots: signals: void reset(); void lineChanged(int lineno); + void errorLine(QString file, int lineno, QString error); protected: lua_State *L; diff --git a/src/mainwindow.cc b/src/mainwindow.cc index cfaece1..7e08c46 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -61,6 +61,8 @@ MainWindow::MainWindow(QString p) l = new LUAScript(*out); connect(l, SIGNAL(lineChanged(int)), editor, SLOT(runningLine(int))); + connect(l, SIGNAL(errorLine(QString, int, QString)), + editor, SLOT(errorLine(QString, int, QString))); // Setup menu QMenu* fileMenu = menuBar()->addMenu(tr("&File")); -- cgit v1.2.3