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

@ -25,7 +25,6 @@ DEFINES += LUA_COMPAT_5_2
shared: win32: DEFINES += LUA_BUILD_AS_DLL
static: DEFINES += LUAENGINE_STATIC
linux: DEFINES += LUA_USE_LINUX
gcc: QMAKE_CFLAGS += -Wno-cast-function-type
SOURCES += \
@ -33,7 +32,8 @@ SOURCES += \
HEADERS += \
luaengine/LuaEngine.h \
luaengine/LuaEngine_global.h
luaengine/LuaEngine_global.h \
luaengine/LuaEngine_macro.h
SOURCES += \
lua/lapi.c \

View file

@ -0,0 +1,29 @@
/*****************************************************************************
* 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 LUAENGINE_MACRO_H
#define LUAENGINE_MACRO_H
#define getArguments LuaEngine::getArguments
#define getArgumentCount LuaEngine::getArgumentCount
#define getPointer LuaEngine::getPointer
#define getVariant LuaEngine::getVariant
#define pushFunction LuaEngine::pushFunction
#define pushPointer LuaEngine::pushPointer
#define pushVariant LuaEngine::pushVariant
#endif // LUAENGINE_MACRO_H

View file

@ -21,15 +21,16 @@ CONFIG += c++11
static: DEFINES += LUAENGINE_STATIC
CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/debug -lluaengine -L$$OUT_PWD/../luaenginegui/debug -lluaenginegui
CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/release -lluaengine -L$$OUT_PWD/../luaenginegui/release -lluaenginegui
unix: LIBS += -L$$OUT_PWD/../luaengine -lluaengine -L$$OUT_PWD/../luaenginegui -lluaenginegui
CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/debug -lluaengineos -L$$OUT_PWD/../luaenginegui/debug -lluaenginegui -L$$OUT_PWD/../luaengine/debug -lluaengine
CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/release -lluaengineos -L$$OUT_PWD/../luaenginegui/release -lluaenginegui -L$$OUT_PWD/../luaengine/release -lluaengine
unix: LIBS += -L$$OUT_PWD/../luaengineos -lluaengineos -L$$OUT_PWD/../luaenginegui -lluaenginegui -L$$OUT_PWD/../luaengine -lluaengine
win32: LIBS += -luser32
INCLUDEPATH += \
../luaengine/lua \
../luaengine/luaengine \
../luaenginegui/luaengine
../luaenginegui/luaengine \
../luaengineos/luaengine
SOURCES += \
main.cpp

View file

@ -16,6 +16,7 @@
*****************************************************************************/
#include "LuaEngineGui.h"
#include "LuaEngineOS.h"
#include <QApplication>
#include <QFont>
#include <QFile>
@ -54,6 +55,7 @@ int main(int argc, char *argv[])
#endif
LuaEngineGui luaEngineGui;
LuaEngineOS::pushClass(&luaEngineGui);
luaEngineGui.executeLuaScript(luaScript);
QVariantList arguments;

View file

@ -25,7 +25,7 @@ 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 -L$$OUT_PWD/../luaenginegui -lluaengine
unix: LIBS += -L$$OUT_PWD/../luaengine -lluaengine
INCLUDEPATH += \
../luaengine/lua \

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

View file

@ -21,15 +21,16 @@ CONFIG += c++11
static: DEFINES += LUAENGINE_STATIC
CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/debug -lluaengine -L$$OUT_PWD/../luaenginegui/debug -lluaenginegui
CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/release -lluaengine -L$$OUT_PWD/../luaenginegui/release -lluaenginegui
unix: LIBS += -L$$OUT_PWD/../luaengine -lluaengine -L$$OUT_PWD/../luaenginegui -lluaenginegui
CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/debug -lluaengineos -L$$OUT_PWD/../luaenginegui/debug -lluaenginegui -L$$OUT_PWD/../luaengine/debug -lluaengine
CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/release -lluaengineos -L$$OUT_PWD/../luaenginegui/release -lluaenginegui -L$$OUT_PWD/../luaengine/release -lluaengine
unix: LIBS += -L$$OUT_PWD/../luaengineos -lluaengineos -L$$OUT_PWD/../luaenginegui -lluaenginegui -L$$OUT_PWD/../luaengine -lluaengine
win32: LIBS += -luser32
INCLUDEPATH += \
../luaengine/lua \
../luaengine/luaengine \
../luaenginegui/luaengine
../luaenginegui/luaengine \
../luaengineos/luaengine
SOURCES += \
main.cpp

View file

@ -16,6 +16,7 @@
*****************************************************************************/
#include "LuaEngineGui.h"
#include "LuaEngineOS.h"
#include <QApplication>
#include <QFont>
#include <QFile>
@ -45,6 +46,7 @@ int main(int argc, char *argv[])
QFile luaScript(arguments.first().toString());
LuaEngineGui luaEngineGui;
LuaEngineOS::pushClass(&luaEngineGui);
luaEngineGui.executeLuaScript(&luaScript);
if (luaEngineGui.executeLuaFunction("main", arguments, true)) {

View file

@ -19,7 +19,8 @@ TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += luaengine \
luaenginegui
luaenginegui \
luaengineos
CONFIG(WITH_LUAENGINEAPP): SUBDIRS += luaengineapp
CONFIG(WITH_LUAENGINERUN): SUBDIRS += luaenginerun