-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b05bd7
commit d050a1a
Showing
9 changed files
with
220 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright 2015-2020 Clément Gallet <clement.gallet@ens-lyon.org> | ||
This file is part of libTAS. | ||
libTAS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
libTAS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with libTAS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "Print.h" | ||
|
||
#include <sstream> | ||
extern "C" { | ||
#include <lua.h> | ||
// #include <lualib.h> | ||
#include <lauxlib.h> | ||
} | ||
|
||
void Lua::Print::init(lua_State *L) { | ||
lua_pushcfunction(L, print); | ||
lua_setglobal(L, "print"); | ||
} | ||
|
||
/* Redefine lua `print` function to output on a Qt window */ | ||
int Lua::Print::print(lua_State *L) { | ||
std::ostringstream oss; | ||
int nargs = lua_gettop(L); | ||
for (int i = 1; i <= nargs; ++i) { | ||
oss << luaL_tolstring(L, i, nullptr); | ||
lua_pop(L, 1); // remove the string | ||
} | ||
|
||
QString qstr(oss.str().c_str()); | ||
|
||
emit get().signalPrint(qstr); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright 2015-2020 Clément Gallet <clement.gallet@ens-lyon.org> | ||
This file is part of libTAS. | ||
libTAS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
libTAS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with libTAS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef LIBTAS_LUAPRINT_H_INCLUDED | ||
#define LIBTAS_LUAPRINT_H_INCLUDED | ||
|
||
#include <QtCore/QObject> | ||
#include <QtCore/QString> | ||
|
||
extern "C" { | ||
#include <lua.h> | ||
} | ||
|
||
namespace Lua { | ||
|
||
class Print : public QObject { | ||
Q_OBJECT | ||
|
||
protected: | ||
Print() = default; | ||
|
||
public: | ||
Print(const Print&) = delete; | ||
Print& operator=(const Print&) = delete; | ||
static void init(lua_State *L); | ||
|
||
static Print &get() { | ||
static Print p; | ||
return p; | ||
} | ||
|
||
private: | ||
static int print(lua_State *L); | ||
|
||
signals: | ||
/* Send the print string to console */ | ||
void signalPrint(QString str); | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
Copyright 2015-2020 Clément Gallet <clement.gallet@ens-lyon.org> | ||
This file is part of libTAS. | ||
libTAS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
libTAS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with libTAS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <QtWidgets/QTableView> | ||
#include <QtWidgets/QPushButton> | ||
#include <QtWidgets/QDialogButtonBox> | ||
#include <QtWidgets/QVBoxLayout> | ||
|
||
#include "LuaConsoleWindow.h" | ||
#include "../lua/Print.h" | ||
|
||
LuaConsoleWindow::LuaConsoleWindow(QWidget *parent) : QDialog(parent) | ||
{ | ||
setWindowTitle("Lua Console"); | ||
|
||
/* Text Edit */ | ||
consoleText = new QPlainTextEdit(); | ||
consoleText->setReadOnly(true); | ||
consoleText->setMaximumBlockCount(10000); | ||
connect(&Lua::Print::get(), &Lua::Print::signalPrint, this, &LuaConsoleWindow::slotAppend); | ||
|
||
/* Buttons */ | ||
QPushButton *clearButton = new QPushButton(tr("Clear")); | ||
connect(clearButton, &QAbstractButton::clicked, this, &LuaConsoleWindow::slotClear); | ||
|
||
QDialogButtonBox *buttonBox = new QDialogButtonBox(); | ||
buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole); | ||
|
||
/* Layout */ | ||
QVBoxLayout *mainLayout = new QVBoxLayout; | ||
|
||
mainLayout->addWidget(consoleText); | ||
mainLayout->addWidget(buttonBox); | ||
|
||
setLayout(mainLayout); | ||
} | ||
|
||
void LuaConsoleWindow::slotAppend(QString qstr) | ||
{ | ||
consoleText->appendPlainText(qstr); | ||
} | ||
|
||
void LuaConsoleWindow::slotClear() | ||
{ | ||
consoleText->clear(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright 2015-2020 Clément Gallet <clement.gallet@ens-lyon.org> | ||
This file is part of libTAS. | ||
libTAS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
libTAS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with libTAS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef LIBTAS_LUACONSOLEWINDOW_H_INCLUDED | ||
#define LIBTAS_LUACONSOLEWINDOW_H_INCLUDED | ||
|
||
#include <QtWidgets/QDialog> | ||
#include <QtWidgets/QPlainTextEdit> | ||
|
||
class LuaConsoleWindow : public QDialog { | ||
Q_OBJECT | ||
|
||
public: | ||
LuaConsoleWindow(QWidget *parent = Q_NULLPTR); | ||
|
||
private: | ||
QPlainTextEdit *consoleText; | ||
|
||
private slots: | ||
void slotAppend(QString qstr); | ||
void slotClear(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters