File indexing completed on 2023-10-03 06:50:42
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-or-later 0003 SPDX-FileCopyrightText: 2014 Lucas Hermann Negri <lucashnegri@gmail.com> 0004 SPDX-FileCopyrightText: 2023 Alexander Semke <alexander.semke@web.de> 0005 */ 0006 0007 #ifndef _LUASESSION_H 0008 #define _LUASESSION_H 0009 0010 #include "session.h" 0011 #include <lua.hpp> 0012 0013 class LuaExpression; 0014 class QProcess; 0015 0016 class LuaSession : public Cantor::Session 0017 { 0018 Q_OBJECT 0019 0020 public: 0021 explicit LuaSession(Cantor::Backend*); 0022 ~LuaSession() override; 0023 0024 void login() override; 0025 void logout() override; 0026 0027 void interrupt() override; 0028 void runFirstExpression() override; 0029 0030 Cantor::Expression* evaluateExpression(const QString& command, Cantor::Expression::FinishingBehavior behave = Cantor::Expression::FinishingBehavior::DoNotDelete, bool internal = false) override; 0031 Cantor::CompletionObject* completionFor(const QString& cmd, int index = -1) override; 0032 QSyntaxHighlighter* syntaxHighlighter(QObject* parent) override; 0033 0034 bool isLuaJIT() const; 0035 lua_State* getState() const; 0036 0037 public Q_SLOTS: 0038 void readIntroMessage(); 0039 void readOutput(); 0040 void readError(); 0041 void processStarted(); 0042 0043 private Q_SLOTS: 0044 void expressionFinished(Cantor::Expression::Status); 0045 0046 private: 0047 void readOutputLua(); 0048 void readOutputLuaJIT(); 0049 bool isPromptString(const QString&); 0050 0051 lua_State* m_L{nullptr}; 0052 QProcess* m_process{nullptr}; 0053 LuaExpression* m_lastExpression{nullptr}; 0054 QStringList m_inputCommands; 0055 QStringList m_output; 0056 bool m_luaJIT{true}; 0057 0058 static const QString LUA_PROMPT; 0059 static const QString LUA_SUBPROMPT; 0060 }; 0061 0062 #endif /* _LUASESSION_H */