luaengineapp/src/luaengineos/luaengine/LuaEngineOS.cpp

66 lines
2.2 KiB
C++
Raw Normal View History

/*****************************************************************************
* luaEngine Lua Engine for Qt
* Copyright (C) 2019 Syping
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "LuaEngine_macro.h"
#include "LuaEngineOS.h"
#include <QTextStream>
#include <QProcess>
#include <QObject>
void LuaEngineOS::pushClass(lua_State *L_p)
{
// Process
pushFunction(L_p, "executeProcess", executeProcess);
}
void LuaEngineOS::pushClass(LuaEngine *luaEngine)
{
pushClass(luaEngine->luaState());
}
int LuaEngineOS::executeProcess(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
QProcess *process = new QProcess;
if (getArgumentCount(L_p) >= 2) {
QVariantList arguments = getArguments(L_p);
QStringList processArguments;
QString processPath = arguments.first().toString();
arguments.removeFirst();
for (const QVariant &argument : arguments) {
processArguments << argument.toString();
}
process->start(processPath, processArguments, QProcess::ReadOnly);
}
else {
process->start(getVariant(L_p, 1).toString(), QProcess::ReadOnly);
}
QObject::connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
pushVariant(L_p, true);
return 1;
}
pushVariant(L_p, false);
return 1;
}
QString LuaEngineOS::nameForPointer(void *pointer)
{
QString nameStorage;
QTextStream(&nameStorage) << "LuaEngineOS" << pointer;
return nameStorage;
}