improvements

This commit is contained in:
Syping 2018-09-14 04:45:57 +02:00
parent 0ba59e0b79
commit 52507c9996
5 changed files with 78 additions and 55 deletions

View file

@ -19,6 +19,7 @@
#include "LuaEngine.h" #include "LuaEngine.h"
#include <QTextStream> #include <QTextStream>
#include <QMetaMethod> #include <QMetaMethod>
#include <QtGlobal>
LuaEngine::LuaEngine(QObject *parent, bool loadBaseLibraries) : QObject(parent) LuaEngine::LuaEngine(QObject *parent, bool loadBaseLibraries) : QObject(parent)
{ {
@ -32,6 +33,7 @@ LuaEngine::LuaEngine(QObject *parent, bool loadBaseLibraries) : QObject(parent)
pushFunction("connect", luaTriggerConnect_p); pushFunction("connect", luaTriggerConnect_p);
pushFunction("disconnect", luaTriggerDisconnect_p); pushFunction("disconnect", luaTriggerDisconnect_p);
pushFunction("luaEngineVersion", luaEngineVersion_p); pushFunction("luaEngineVersion", luaEngineVersion_p);
pushFunction("luaEnginePlatform", luaEnginePlatform_p);
} }
LuaEngine::~LuaEngine() LuaEngine::~LuaEngine()
@ -55,6 +57,30 @@ int LuaEngine::luaEngineVersion_p(lua_State *L_p)
return 1; return 1;
} }
int LuaEngine::luaEnginePlatform_p(lua_State *L_p)
{
#ifdef Q_OS_ANDROID
pushVariant(L_p, "Android");
#elif defined(Q_OS_LINUX)
pushVariant(L_p, "Linux");
#elif defined(Q_OS_FREEBSD)
pushVariant(L_p, "FreeBSD");
#elif defined(Q_OS_OPENBSD)
pushVariant(L_p, "OpenBSD");
#elif defined(Q_OS_MACOS)
pushVariant(L_p, "macOS");
#elif defined(Q_OS_DARWIN)
pushVariant(L_p, "Darwin");
#elif defined(Q_OS_UNIX)
pushVariant(L_p, "Unix");
#elif defined(Q_OS_WIN)
pushVariant(L_p, "Windows");
#else
pushVariant(L_p, "Unknown");
#endif
return 1;
}
bool LuaEngine::executeLuaScript(const QByteArray &data) bool LuaEngine::executeLuaScript(const QByteArray &data)
{ {
int returnCode = luaL_dostring(L, data.data()); int returnCode = luaL_dostring(L, data.data());

View file

@ -75,6 +75,7 @@ public:
private: private:
lua_State *L; lua_State *L;
static int luaEngineVersion_p(lua_State *L_p); static int luaEngineVersion_p(lua_State *L_p);
static int luaEnginePlatform_p(lua_State *L_p);
static int luaDeletePointer_p(lua_State *L_p); static int luaDeletePointer_p(lua_State *L_p);
static int luaTriggerConnect_p(lua_State *L_p); static int luaTriggerConnect_p(lua_State *L_p);
static int luaTriggerDisconnect_p(lua_State *L_p); static int luaTriggerDisconnect_p(lua_State *L_p);

View file

@ -53,7 +53,7 @@ function main()
layoutAddWidget(mainLayout, textEditor) layoutAddWidget(mainLayout, textEditor)
setWidgetSize(mainWindow, 650, 450) setWidgetSize(mainWindow, 650, 450)
showWidget(mainWindow, ShowNormal) showWidget(mainWindow, ShowDefault)
return GuiExecuted return GuiExecuted
end end

View file

@ -56,7 +56,7 @@ int main(int argc, char *argv[])
delete luaEngineStyleFile; delete luaEngineStyleFile;
#endif #endif
QFile luaScript(":/lua/app.lua"); QFile luaScript(":/lua/edit.lua");
LuaEngineGui luaEngineGui; LuaEngineGui luaEngineGui;
luaEngineGui.executeLuaScript(&luaScript); luaEngineGui.executeLuaScript(&luaScript);

View file

@ -76,9 +76,10 @@ void LuaEngineGui::pushClass(lua_State *L_p)
pushFunction(L_p, "setWidgetSize", setWidgetSize); pushFunction(L_p, "setWidgetSize", setWidgetSize);
pushVariant(L_p, "ShowCurrent", 0); pushVariant(L_p, "ShowCurrent", 0);
pushVariant(L_p, "ShowNormal", 1); pushVariant(L_p, "ShowNormal", 1);
pushVariant(L_p, "ShowMinimised", 2); pushVariant(L_p, "ShowDefault", 2);
pushVariant(L_p, "ShowMaximised", 3); pushVariant(L_p, "ShowMinimised", 3);
pushVariant(L_p, "ShowFullscreen", 4); pushVariant(L_p, "ShowMaximised", 4);
pushVariant(L_p, "ShowFullscreen", 5);
// Check Box // Check Box
pushFunction(L_p, "createCheckBox", createCheckBox); pushFunction(L_p, "createCheckBox", createCheckBox);
@ -310,12 +311,19 @@ int LuaEngineGui::showWidget(lua_State *L_p)
((QWidget*)pointer)->showNormal(); ((QWidget*)pointer)->showNormal();
break; break;
case 2: case 2:
((QWidget*)pointer)->showMinimized(); #ifdef Q_OS_ANDROID
((QWidget*)pointer)->showMaximized();
#else
((QWidget*)pointer)->showNormal();
#endif
break; break;
case 3: case 3:
((QWidget*)pointer)->showMaximized(); ((QWidget*)pointer)->showMinimized();
break; break;
case 4: case 4:
((QWidget*)pointer)->showMaximized();
break;
case 5:
((QWidget*)pointer)->showFullScreen(); ((QWidget*)pointer)->showFullScreen();
break; break;
default: default:
@ -499,16 +507,14 @@ int LuaEngineGui::createCentralWidget(lua_State *L_p)
int LuaEngineGui::createCheckBox(lua_State *L_p) int LuaEngineGui::createCheckBox(lua_State *L_p)
{ {
QVariantList args = getArguments(L_p);
QWidget *parent = nullptr; QWidget *parent = nullptr;
QString labelText = "LuaEngine"; QString labelText = "LuaEngine";
if (args.length() >= 1) { if (getArgumentCount(L_p) >= 1) {
labelText = args.at(0).toString(); labelText = getVariant(L_p, 1).toString();
if (args.length() >= 2) { if (getArgumentCount(L_p) >= 2) {
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) { void *pointer = getPointer(L_p, 2);
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) { if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)qvariant_cast<void*>(args.at(1)); parent = (QWidget*)pointer;
}
} }
} }
} }
@ -521,16 +527,14 @@ int LuaEngineGui::createCheckBox(lua_State *L_p)
int LuaEngineGui::createDialog(lua_State *L_p) int LuaEngineGui::createDialog(lua_State *L_p)
{ {
QVariantList args = getArguments(L_p);
QWidget *parent = nullptr; QWidget *parent = nullptr;
QString windowTitle = "LuaEngine"; QString windowTitle = "LuaEngine";
if (args.length() >= 1) { if (getArgumentCount(L_p) >= 1) {
windowTitle = args.at(0).toString(); windowTitle = getVariant(L_p, 1).toString();
if (args.length() >= 2) { if (getArgumentCount(L_p) >= 2) {
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) { void *pointer = getPointer(L_p, 2);
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) { if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)qvariant_cast<void*>(args.at(1)); parent = (QWidget*)pointer;
}
} }
} }
} }
@ -548,16 +552,14 @@ int LuaEngineGui::createDialog(lua_State *L_p)
int LuaEngineGui::createLabel(lua_State *L_p) int LuaEngineGui::createLabel(lua_State *L_p)
{ {
QVariantList args = getArguments(L_p);
QWidget *parent = nullptr; QWidget *parent = nullptr;
QString labelText = "LuaEngine"; QString labelText = "LuaEngine";
if (args.length() >= 1) { if (getArgumentCount(L_p) >= 1) {
labelText = args.at(0).toString(); labelText = getVariant(L_p, 1).toString();
if (args.length() >= 2) { if (getArgumentCount(L_p) >= 2) {
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) { void *pointer = getPointer(L_p, 2);
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) { if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)qvariant_cast<void*>(args.at(1)); parent = (QWidget*)pointer;
}
} }
} }
} }
@ -608,16 +610,14 @@ int LuaEngineGui::createLayout(lua_State *L_p)
int LuaEngineGui::createLineEdit(lua_State *L_p) int LuaEngineGui::createLineEdit(lua_State *L_p)
{ {
QVariantList args = getArguments(L_p);
QWidget *parent = nullptr; QWidget *parent = nullptr;
QString editText = "LuaEngine"; QString editText = "LuaEngine";
if (args.length() >= 1) { if (getArgumentCount(L_p) >= 1) {
editText = args.at(0).toString(); editText = getVariant(L_p, 1).toString();
if (args.length() >= 2) { if (getArgumentCount(L_p) >= 2) {
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) { void *pointer = getPointer(L_p, 2);
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) { if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)qvariant_cast<void*>(args.at(1)); parent = (QWidget*)pointer;
}
} }
} }
} }
@ -630,16 +630,14 @@ int LuaEngineGui::createLineEdit(lua_State *L_p)
int LuaEngineGui::createMainWindow(lua_State *L_p) int LuaEngineGui::createMainWindow(lua_State *L_p)
{ {
QVariantList args = getArguments(L_p);
QWidget *parent = nullptr; QWidget *parent = nullptr;
QString windowTitle = "LuaEngine"; QString windowTitle = "LuaEngine";
if (args.length() >= 1) { if (getArgumentCount(L_p) >= 1) {
windowTitle = args.at(0).toString(); windowTitle = getVariant(L_p, 1).toString();
if (args.length() >= 2) { if (getArgumentCount(L_p) >= 2) {
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) { void *pointer = getPointer(L_p, 2);
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) { if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)qvariant_cast<void*>(args.at(1)); parent = (QWidget*)pointer;
}
} }
} }
} }
@ -739,16 +737,14 @@ int LuaEngineGui::createPlainTextEdit(lua_State *L_p)
int LuaEngineGui::createPushButton(lua_State *L_p) int LuaEngineGui::createPushButton(lua_State *L_p)
{ {
QVariantList args = getArguments(L_p);
QWidget *parent = nullptr; QWidget *parent = nullptr;
QString buttonText = "LuaEngine"; QString buttonText = "LuaEngine";
if (args.length() >= 1) { if (getArgumentCount(L_p) >= 1) {
buttonText = args.at(0).toString(); buttonText = getVariant(L_p, 1).toString();
if (args.length() >= 2) { if (getArgumentCount(L_p) >= 2) {
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) { void *pointer = getPointer(L_p, 2);
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) { if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)qvariant_cast<void*>(args.at(1)); parent = (QWidget*)pointer;
}
} }
} }
} }