add executeProcess function and OS library

This commit is contained in:
Syping 2019-09-30 19:25:02 +02:00
parent e189120982
commit 7773d84176
12 changed files with 220 additions and 12 deletions

View file

@ -0,0 +1,65 @@
/*****************************************************************************
* 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;
}

View file

@ -0,0 +1,35 @@
/*****************************************************************************
* 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.
*****************************************************************************/
#ifndef LUAENGINEOS_H
#define LUAENGINEOS_H
#include "LuaEngineOS_global.h"
#include "LuaEngine.h"
class LUAENGINEOSSHARED_EXPORT LuaEngineOS
{
public:
static void pushClass(lua_State *L_p);
static void pushClass(LuaEngine *luaEngine);
static int executeProcess(lua_State *L_p);
private:
static QString nameForPointer(void *pointer);
};
#endif // LUAENGINEOS_H

View file

@ -0,0 +1,33 @@
/*****************************************************************************
* luaEngine Lua Engine for Qt
* Copyright (C) 2018-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.
*****************************************************************************/
#ifndef LUAENGINEOS_GLOBAL_H
#define LUAENGINEOS_GLOBAL_H
#include <QtCore/qglobal.h>
#ifndef LUAENGINE_STATIC
#ifdef LUAENGINEOS_LIBRARY
#define LUAENGINEOSSHARED_EXPORT Q_DECL_EXPORT
#else
#define LUAENGINEOSSHARED_EXPORT Q_DECL_IMPORT
#endif
#else
#define LUAENGINEOSSHARED_EXPORT
#endif
#endif // LUAENGINEOS_GLOBAL_H

View file

@ -0,0 +1,39 @@
#/*****************************************************************************
#* luaEngine Lua Engine for Qt
#* Copyright (C) 2018-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.
#*****************************************************************************/
QT += core
TARGET = luaengineos
TEMPLATE = lib
CONFIG += c++11
DEFINES += LUAENGINEOS_LIBRARY
static: DEFINES += LUAENGINE_STATIC
CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/debug -lluaengine
CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/release -lluaengine
unix: LIBS += -L$$OUT_PWD/../luaengine -lluaengine
INCLUDEPATH += \
../luaengine/lua \
../luaengine/luaengine
SOURCES += \
luaengine/LuaEngineOS.cpp
HEADERS += \
luaengine/LuaEngineOS.h \
luaengine/LuaEngineOS_global.h