Changeset View
Changeset View
Standalone View
Standalone View
src/backends/lua/luasession.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
42 | void LuaSession::login() | 42 | void LuaSession::login() | ||
43 | { | 43 | { | ||
44 | /* | 44 | /* | ||
45 | * setup Qprocess here | 45 | * setup Qprocess here | ||
46 | * load the autoscripts | 46 | * load the autoscripts | ||
47 | */ | 47 | */ | ||
48 | 48 | | |||
49 | m_process = new QProcess(this); | 49 | m_process = new QProcess(this); | ||
50 | m_process->setProgram(QLatin1String("/usr/bin/lua")); | 50 | m_process->setProgram(QLatin1String("/usr/bin/lua")); | ||
filipesaraiva: I must ask to Lucas Negri (the original author of this backend) if it is more interesting to… | |||||
51 | m_process->setArguments(QStringList() << QLatin1String("-i")); | 51 | m_process->setArguments(QStringList() << QLatin1String("-i")); | ||
52 | 52 | | |||
53 | m_process->setProcessChannelMode(QProcess::SeparateChannels); | 53 | m_process->setProcessChannelMode(QProcess::SeparateChannels); | ||
54 | 54 | | |||
55 | connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readIntroMessage())); | 55 | connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readIntroMessage())); | ||
56 | connect(m_process, SIGNAL(started()), this, SLOT(processStarted())); | 56 | connect(m_process, SIGNAL(started()), this, SLOT(processStarted())); | ||
57 | m_process->start(); | 57 | m_process->start(); | ||
58 | 58 | | |||
59 | // we need this for tab completion | 59 | // we need this for tab completion | ||
60 | m_L = luaL_newstate(); | 60 | m_L = luaL_newstate(); | ||
61 | luaL_openlibs(m_L); | 61 | luaL_openlibs(m_L); | ||
62 | } | 62 | } | ||
63 | 63 | | |||
64 | void LuaSession::readIntroMessage() | 64 | void LuaSession::readIntroMessage() | ||
65 | { | 65 | { | ||
66 | while(m_process->bytesAvailable()) { | 66 | while(m_process->bytesAvailable()) { | ||
67 | m_output.append(QString::fromLocal8Bit(m_process->readLine())); | 67 | m_output.append(QString::fromLocal8Bit(m_process->readLine())); | ||
68 | } | 68 | } | ||
69 | 69 | | |||
70 | if(!m_output.isEmpty() && m_output.trimmed().endsWith(QLatin1String(">"))) { | 70 | if(!m_output.isEmpty() && m_output.trimmed().endsWith(QLatin1String(">"))) { | ||
71 | qDebug() << " reading the intro message " << m_output ; | 71 | qDebug() << " reading the intro message " << m_output ; | ||
72 | m_output.clear(); | 72 | m_output.clear(); | ||
filipesaraiva: Do you have an example where `readIntroMessage` will be used? | |||||
'Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio', this is the initial message produced when Lua is started. rishabhg: 'Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio', this is the initial message produced… | |||||
filipesaraiva: Ah ok! :) | |||||
73 | 73 | | |||
74 | disconnect(m_process, SIGNAL(readyReadStandardOutput()), this , SLOT(readIntroMessage())); | 74 | disconnect(m_process, SIGNAL(readyReadStandardOutput()), this , SLOT(readIntroMessage())); | ||
75 | connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput())); | 75 | connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput())); | ||
76 | connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readError())); | 76 | connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readError())); | ||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | 79 | | |||
80 | } | 80 | } | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 141 | { | |||
142 | /* | 142 | /* | ||
143 | * get the current command | 143 | * get the current command | ||
144 | * format it and write to m_process | 144 | * format it and write to m_process | ||
145 | */ | 145 | */ | ||
146 | QString command = currentExpression->command(); | 146 | QString command = currentExpression->command(); | ||
147 | 147 | | |||
148 | command += QLatin1String("\n"); | 148 | command += QLatin1String("\n"); | ||
149 | 149 | | |||
150 | if(command.count(QLatin1String("\n")) == 1) | ||||
151 | command.prepend(QLatin1String("return ")); | ||||
152 | | ||||
150 | qDebug() << "final command to be executed " << command << endl; | 153 | qDebug() << "final command to be executed " << command << endl; | ||
151 | 154 | | |||
152 | m_process->write(command.toLocal8Bit()); | 155 | m_process->write(command.toLocal8Bit()); | ||
153 | } | 156 | } | ||
154 | 157 | | |||
155 | Cantor::CompletionObject* LuaSession::completionFor(const QString& command, int index) | 158 | Cantor::CompletionObject* LuaSession::completionFor(const QString& command, int index) | ||
156 | { | 159 | { | ||
157 | return new LuaCompletionObject(command, index, this); | 160 | return new LuaCompletionObject(command, index, this); | ||
Show All 29 Lines |
I must ask to Lucas Negri (the original author of this backend) if it is more interesting to use Lua or Luajit.