From f1bf8abfb5d161c7e07faa0ed8a6c6bd19246be6 Mon Sep 17 00:00:00 2001 From: Syping Date: Fri, 3 Jul 2020 18:41:36 +0200 Subject: [PATCH] dependency system + network library --- luaengine.pro | 1 - src/luaengine/luaengine.pro | 9 +-- src/luaengine/main.cpp | 2 + src/luaengineapp/luaengineapp.pro | 9 +-- src/luaengineapp/main.cpp | 2 + src/luaengineio/luaengine/LuaEngineIO.cpp | 1 + src/luaengineio/luaengine/LuaEngineIO.h | 2 - .../luaengine/LuaEngineNetwork.cpp | 57 +++++++++++++++++ .../luaengine/LuaEngineNetwork.h | 38 ++++++++++++ .../luaengine/LuaEngineNetwork_global.h | 33 ++++++++++ src/luaenginenetwork/luaenginenetwork.pro | 62 +++++++++++++++++++ src/src.pro | 23 ++++++- 12 files changed, 226 insertions(+), 13 deletions(-) create mode 100644 src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp create mode 100644 src/luaenginenetwork/luaengine/LuaEngineNetwork.h create mode 100644 src/luaenginenetwork/luaengine/LuaEngineNetwork_global.h create mode 100644 src/luaenginenetwork/luaenginenetwork.pro diff --git a/luaengine.pro b/luaengine.pro index ee0ca1a..5721b1d 100644 --- a/luaengine.pro +++ b/luaengine.pro @@ -16,7 +16,6 @@ #*****************************************************************************/ TEMPLATE = subdirs -CONFIG += ordered SUBDIRS += src diff --git a/src/luaengine/luaengine.pro b/src/luaengine/luaengine.pro index 4e7e0be..a1e497f 100644 --- a/src/luaengine/luaengine.pro +++ b/src/luaengine/luaengine.pro @@ -15,7 +15,7 @@ #* limitations under the License. #*****************************************************************************/ -QT += widgets +QT += network widgets TARGET = luaengine CONFIG += c++11 VERSION = 0.1 @@ -29,14 +29,15 @@ unix { isEmpty(LUAENGINE_LIBDIR): LUAENGINE_LIBDIR = $$LUAENGINE_PREFIX/lib } -unix: LIBS += "-Wl,-rpath,\'$$LUAENGINE_LIBDIR\'" -L$$OUT_PWD/../luaengineos -lLuaEngineOS -L$$OUT_PWD/../luaengineio -lLuaEngineIO -L$$OUT_PWD/../luaenginegui -lLuaEngineGui -L$$OUT_PWD/../luaenginecore -lLuaEngine -CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/debug -lLuaEngineOS -L$$OUT_PWD/../luaengineio/debug -lLuaEngineIO -L$$OUT_PWD/../luaenginegui/debug -lLuaEngineGui -L$$OUT_PWD/../luaenginecore/debug -lLuaEngine -CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/release -lLuaEngineOS -L$$OUT_PWD/../luaengineio/release -lLuaEngineIO -L$$OUT_PWD/../luaenginegui/release -lLuaEngineGui -L$$OUT_PWD/../luaenginecore/release -lLuaEngine +unix: LIBS += "-Wl,-rpath,\'$$LUAENGINE_LIBDIR\'" -L$$OUT_PWD/../luaengineos -lLuaEngineOS -L$$OUT_PWD/../luaenginenetwork -lLuaEngineNetwork -L$$OUT_PWD/../luaengineio -lLuaEngineIO -L$$OUT_PWD/../luaenginegui -lLuaEngineGui -L$$OUT_PWD/../luaenginecore -lLuaEngine +CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/debug -lLuaEngineOS -L$$OUT_PWD/../luaenginenetwork/debug -lLuaEngineNetwork -L$$OUT_PWD/../luaengineio/debug -lLuaEngineIO -L$$OUT_PWD/../luaenginegui/debug -lLuaEngineGui -L$$OUT_PWD/../luaenginecore/debug -lLuaEngine +CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/release -lLuaEngineOS -L$$OUT_PWD/../luaenginenetwork/release -lLuaEngineNetwork -L$$OUT_PWD/../luaengineio/release -lLuaEngineIO -L$$OUT_PWD/../luaenginegui/release -lLuaEngineGui -L$$OUT_PWD/../luaenginecore/release -lLuaEngine INCLUDEPATH += \ ../luaenginecore/luaengine \ ../luaenginegui/luaengine \ ../luaengineio/luaengine \ + ../luaenginenetwork/luaengine \ ../luaengineos/luaengine SOURCES += \ diff --git a/src/luaengine/main.cpp b/src/luaengine/main.cpp index fa7207e..30fc821 100644 --- a/src/luaengine/main.cpp +++ b/src/luaengine/main.cpp @@ -15,6 +15,7 @@ * limitations under the License. *****************************************************************************/ +#include "LuaEngineNetwork.h" #include "LuaEngineGui.h" #include "LuaEngineIO.h" #include "LuaEngineOS.h" @@ -62,6 +63,7 @@ int main(int argc, char *argv[]) LuaEngineGui luaEngineGui; LuaEngineIO::pushClass(&luaEngineGui); + LuaEngineNetwork::pushClass(&luaEngineGui); LuaEngineOS::pushClass(&luaEngineGui); luaEngineGui.pushVariant("_LuaEngineRT", rtPath); luaEngineGui.setProperty("EngineType", "Runtime"); diff --git a/src/luaengineapp/luaengineapp.pro b/src/luaengineapp/luaengineapp.pro index 4bbde78..3208783 100644 --- a/src/luaengineapp/luaengineapp.pro +++ b/src/luaengineapp/luaengineapp.pro @@ -15,7 +15,7 @@ #* limitations under the License. #*****************************************************************************/ -QT += widgets +QT += network widgets TARGET = luaengineapp win32: TARGET = LuaEngineApp CONFIG += c++11 @@ -29,14 +29,15 @@ unix { isEmpty(LUAENGINE_LIBDIR): LUAENGINE_LIBDIR = $$LUAENGINE_PREFIX/lib } -unix: LIBS += "-Wl,-rpath,\'$$LUAENGINE_LIBDIR\'" -L$$OUT_PWD/../luaengineos -lLuaEngineOS -L$$OUT_PWD/../luaengineio -lLuaEngineIO -L$$OUT_PWD/../luaenginegui -lLuaEngineGui -L$$OUT_PWD/../luaenginecore -lLuaEngine -CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/debug -lLuaEngineOS -L$$OUT_PWD/../luaengineio/debug -lLuaEngineIO -L$$OUT_PWD/../luaenginegui/debug -lLuaEngineGui -L$$OUT_PWD/../luaenginecore/debug -lLuaEngine -CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/release -lLuaEngineOS -L$$OUT_PWD/../luaengineio/release -lLuaEngineIO -L$$OUT_PWD/../luaenginegui/release -lLuaEngineGui -L$$OUT_PWD/../luaenginecore/release -lLuaEngine +unix: LIBS += "-Wl,-rpath,\'$$LUAENGINE_LIBDIR\'" -L$$OUT_PWD/../luaengineos -lLuaEngineOS -L$$OUT_PWD/../luaenginenetwork -lLuaEngineNetwork -L$$OUT_PWD/../luaengineio -lLuaEngineIO -L$$OUT_PWD/../luaenginegui -lLuaEngineGui -L$$OUT_PWD/../luaenginecore -lLuaEngine +CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/debug -lLuaEngineOS -L$$OUT_PWD/../luaenginenetwork/debug -lLuaEngineNetwork -L$$OUT_PWD/../luaengineio/debug -lLuaEngineIO -L$$OUT_PWD/../luaenginegui/debug -lLuaEngineGui -L$$OUT_PWD/../luaenginecore/debug -lLuaEngine +CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/release -lLuaEngineOS -L$$OUT_PWD/../luaenginenetwork/release -lLuaEngineNetwork -L$$OUT_PWD/../luaengineio/release -lLuaEngineIO -L$$OUT_PWD/../luaenginegui/release -lLuaEngineGui -L$$OUT_PWD/../luaenginecore/release -lLuaEngine INCLUDEPATH += \ ../luaenginecore/luaengine \ ../luaenginegui/luaengine \ ../luaengineio/luaengine \ + ../luaenginenetwork/luaengine \ ../luaengineos/luaengine SOURCES += \ diff --git a/src/luaengineapp/main.cpp b/src/luaengineapp/main.cpp index 93f6d58..12cb84f 100644 --- a/src/luaengineapp/main.cpp +++ b/src/luaengineapp/main.cpp @@ -15,6 +15,7 @@ * limitations under the License. *****************************************************************************/ +#include "LuaEngineNetwork.h" #include "LuaEngineGui.h" #include "LuaEngineIO.h" #include "LuaEngineOS.h" @@ -77,6 +78,7 @@ int main(int argc, char *argv[]) LuaEngineGui luaEngineGui; LuaEngineIO::pushClass(&luaEngineGui); + LuaEngineNetwork::pushClass(&luaEngineGui); LuaEngineOS::pushClass(&luaEngineGui); luaEngineGui.setProperty("EngineType", "Portable"); luaEngineGui.executeLuaScript(luaScript); diff --git a/src/luaengineio/luaengine/LuaEngineIO.cpp b/src/luaengineio/luaengine/LuaEngineIO.cpp index 53ab333..ce55b31 100644 --- a/src/luaengineio/luaengine/LuaEngineIO.cpp +++ b/src/luaengineio/luaengine/LuaEngineIO.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/src/luaengineio/luaengine/LuaEngineIO.h b/src/luaengineio/luaengine/LuaEngineIO.h index ba4b391..463ce5a 100644 --- a/src/luaengineio/luaengine/LuaEngineIO.h +++ b/src/luaengineio/luaengine/LuaEngineIO.h @@ -21,8 +21,6 @@ #include "LuaEngineIO_global.h" #include "LuaEngineAddon.h" #include "LuaEngine.h" -#include -#include #include #include diff --git a/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp b/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp new file mode 100644 index 0000000..a307163 --- /dev/null +++ b/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp @@ -0,0 +1,57 @@ +/***************************************************************************** +* luaEngine Lua Engine for Qt +* Copyright (C) 2020 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 "LuaEngineNetwork.h" +#include + +void LuaEngineNetwork::pushClass(lua_State *L_p) +{ + // Local Socket + pushFunction(L_p, "createLocalSocket", createLocalSocket); +} + +void LuaEngineNetwork::pushClass(LuaEngine *luaEngine) +{ + pushClass(luaEngine->luaState()); +} + +int LuaEngineNetwork::createLocalSocket(lua_State *L_p) +{ + QObject *parent = nullptr; + QString socketPath = "LuaEngine"; + if (getArgumentCount(L_p) >= 1) { + socketPath = getVariant(L_p, 1).toString(); + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 2); + if (pointer != NULL) { + parent = (QObject*)pointer; + } + } + } + QLocalSocket *localSocket = new QLocalSocket(parent); + localSocket->setObjectName(nameForPointer(localSocket)); + localSocket->setServerName(socketPath); + pushPointer(L_p, localSocket); + return 1; +} + +QString LuaEngineNetwork::nameForPointer(void *pointer) +{ + QString nameStorage; + QTextStream(&nameStorage) << "LuaEngineNetwork" << pointer; + return nameStorage; +} diff --git a/src/luaenginenetwork/luaengine/LuaEngineNetwork.h b/src/luaenginenetwork/luaengine/LuaEngineNetwork.h new file mode 100644 index 0000000..1637452 --- /dev/null +++ b/src/luaenginenetwork/luaengine/LuaEngineNetwork.h @@ -0,0 +1,38 @@ +/***************************************************************************** +* luaEngine Lua Engine for Qt +* Copyright (C) 2020 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 LUAENGINENETWORK_H +#define LUAENGINENETWORK_H + +#include "LuaEngineNetwork_global.h" +#include "LuaEngineAddon.h" +#include "LuaEngine.h" + +class LUAENGINENETWORKSHARED_EXPORT LuaEngineNetwork : public LuaEngineAddon +{ + Q_OBJECT +public: + static void pushClass(lua_State *L_p); + static void pushClass(LuaEngine *luaEngine); + static int createLocalSocket(lua_State *L_p); + +private: + lua_State *L; + static QString nameForPointer(void *pointer); +}; + +#endif // LUAENGINENETWORK_H diff --git a/src/luaenginenetwork/luaengine/LuaEngineNetwork_global.h b/src/luaenginenetwork/luaengine/LuaEngineNetwork_global.h new file mode 100644 index 0000000..79d032e --- /dev/null +++ b/src/luaenginenetwork/luaengine/LuaEngineNetwork_global.h @@ -0,0 +1,33 @@ +/***************************************************************************** +* luaEngine Lua Engine for Qt +* Copyright (C) 2020 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 LUAENGINENETWORK_GLOBAL_H +#define LUAENGINENETWORK_GLOBAL_H + +#include + +#ifndef LUAENGINE_STATIC +#ifdef LUAENGINENETWORK_LIBRARY +#define LUAENGINENETWORKSHARED_EXPORT Q_DECL_EXPORT +#else +#define LUAENGINENETWORKSHARED_EXPORT Q_DECL_IMPORT +#endif +#else +#define LUAENGINENETWORKSHARED_EXPORT +#endif + +#endif // LUAENGINENETWORK_GLOBAL_H diff --git a/src/luaenginenetwork/luaenginenetwork.pro b/src/luaenginenetwork/luaenginenetwork.pro new file mode 100644 index 0000000..2359ba1 --- /dev/null +++ b/src/luaenginenetwork/luaenginenetwork.pro @@ -0,0 +1,62 @@ +#/***************************************************************************** +#* luaEngine Lua Engine for Qt +#* Copyright (C) 2020 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 -= gui +QT += network +TARGET = LuaEngineNetwork +TEMPLATE = lib +CONFIG += c++11 \ + skip_target_version_ext +VERSION = 0.1 + +DEFINES += LUAENGINENETWORK_LIBRARY +static: DEFINES += LUAENGINE_STATIC + +# PROJECT PREFIX +unix { + isEmpty(LUAENGINE_PREFIX): LUAENGINE_PREFIX = /usr/local + isEmpty(LUAENGINE_LIBDIR): LUAENGINE_LIBDIR = $$LUAENGINE_PREFIX/lib +} + +unix: LIBS += "-Wl,-rpath,\'$$LUAENGINE_LIBDIR\'" -L$$OUT_PWD/../luaenginecore -lLuaEngine +CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaenginecore/debug -lLuaEngine +CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaenginecore/release -lLuaEngine + +INCLUDEPATH += \ + ../luaenginecore/luaengine + +SOURCES += \ + luaengine/LuaEngineNetwork.cpp + +HEADERS += \ + luaengine/LuaEngineNetwork.h \ + luaengine/LuaEngineNetwork_global.h + +include(../luaenginecore/lua_module.pri) + +unix { + target.path = $$LUAENGINE_LIBDIR + INSTALLS += target +} + +win32 { + RC_LANG = 0x0 + QMAKE_TARGET_COMPANY = "Syping" + QMAKE_TARGET_DESCRIPTION = "LuaEngine Network Library" + QMAKE_TARGET_COPYRIGHT = "Copyright (c) 2020 Syping" + QMAKE_TARGET_PRODUCT = "LuaEngineNetwork" +} diff --git a/src/src.pro b/src/src.pro index 292ed98..a19d75b 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,6 +1,6 @@ #/***************************************************************************** #* luaEngine Lua Engine for Qt -#* Copyright (C) 2018-2019 Syping +#* Copyright (C) 2018-2020 Syping #* #* Licensed under the Apache License, Version 2.0 (the "License"); #* you may not use this file except in compliance with the License. @@ -16,13 +16,32 @@ #*****************************************************************************/ TEMPLATE = subdirs -CONFIG += ordered SUBDIRS += luaenginecore \ luaenginegui \ + luaenginenetwork \ luaengineio \ luaengineos +luaenginegui.depends = luaenginecore +luaenginenetwork.depends = luaenginecore +luaengineio.depends = luaenginecore +luaengineos.depends = luaenginecore + +luaengine.depends += luaenginecore \ + luaenginegui + luaenginenetwork + luaengineio + luaengineos + +luaengineapp.depends += luaenginecore \ + luaenginegui + luaenginenetwork + luaengineio + luaengineos + +luaenginec.depends = luaenginecore + CONFIG(WITH_LUAENGINE_RUNTIME): SUBDIRS += luaengine CONFIG(WITH_LUAENGINE_APPSTUB): SUBDIRS += luaengineapp CONFIG(WITH_LUAENGINE_COMPILER): SUBDIRS += luaenginec