mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-12-22 11:55:29 +01:00
improvements
This commit is contained in:
parent
0ba59e0b79
commit
52507c9996
5 changed files with 78 additions and 55 deletions
|
@ -19,6 +19,7 @@
|
|||
#include "LuaEngine.h"
|
||||
#include <QTextStream>
|
||||
#include <QMetaMethod>
|
||||
#include <QtGlobal>
|
||||
|
||||
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("disconnect", luaTriggerDisconnect_p);
|
||||
pushFunction("luaEngineVersion", luaEngineVersion_p);
|
||||
pushFunction("luaEnginePlatform", luaEnginePlatform_p);
|
||||
}
|
||||
|
||||
LuaEngine::~LuaEngine()
|
||||
|
@ -55,6 +57,30 @@ int LuaEngine::luaEngineVersion_p(lua_State *L_p)
|
|||
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)
|
||||
{
|
||||
int returnCode = luaL_dostring(L, data.data());
|
||||
|
|
|
@ -75,6 +75,7 @@ public:
|
|||
private:
|
||||
lua_State *L;
|
||||
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 luaTriggerConnect_p(lua_State *L_p);
|
||||
static int luaTriggerDisconnect_p(lua_State *L_p);
|
||||
|
|
|
@ -53,7 +53,7 @@ function main()
|
|||
layoutAddWidget(mainLayout, textEditor)
|
||||
|
||||
setWidgetSize(mainWindow, 650, 450)
|
||||
showWidget(mainWindow, ShowNormal)
|
||||
showWidget(mainWindow, ShowDefault)
|
||||
return GuiExecuted
|
||||
end
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ int main(int argc, char *argv[])
|
|||
delete luaEngineStyleFile;
|
||||
#endif
|
||||
|
||||
QFile luaScript(":/lua/app.lua");
|
||||
QFile luaScript(":/lua/edit.lua");
|
||||
|
||||
LuaEngineGui luaEngineGui;
|
||||
luaEngineGui.executeLuaScript(&luaScript);
|
||||
|
|
|
@ -76,9 +76,10 @@ void LuaEngineGui::pushClass(lua_State *L_p)
|
|||
pushFunction(L_p, "setWidgetSize", setWidgetSize);
|
||||
pushVariant(L_p, "ShowCurrent", 0);
|
||||
pushVariant(L_p, "ShowNormal", 1);
|
||||
pushVariant(L_p, "ShowMinimised", 2);
|
||||
pushVariant(L_p, "ShowMaximised", 3);
|
||||
pushVariant(L_p, "ShowFullscreen", 4);
|
||||
pushVariant(L_p, "ShowDefault", 2);
|
||||
pushVariant(L_p, "ShowMinimised", 3);
|
||||
pushVariant(L_p, "ShowMaximised", 4);
|
||||
pushVariant(L_p, "ShowFullscreen", 5);
|
||||
|
||||
// Check Box
|
||||
pushFunction(L_p, "createCheckBox", createCheckBox);
|
||||
|
@ -310,12 +311,19 @@ int LuaEngineGui::showWidget(lua_State *L_p)
|
|||
((QWidget*)pointer)->showNormal();
|
||||
break;
|
||||
case 2:
|
||||
((QWidget*)pointer)->showMinimized();
|
||||
#ifdef Q_OS_ANDROID
|
||||
((QWidget*)pointer)->showMaximized();
|
||||
#else
|
||||
((QWidget*)pointer)->showNormal();
|
||||
#endif
|
||||
break;
|
||||
case 3:
|
||||
((QWidget*)pointer)->showMaximized();
|
||||
((QWidget*)pointer)->showMinimized();
|
||||
break;
|
||||
case 4:
|
||||
((QWidget*)pointer)->showMaximized();
|
||||
break;
|
||||
case 5:
|
||||
((QWidget*)pointer)->showFullScreen();
|
||||
break;
|
||||
default:
|
||||
|
@ -499,16 +507,14 @@ int LuaEngineGui::createCentralWidget(lua_State *L_p)
|
|||
|
||||
int LuaEngineGui::createCheckBox(lua_State *L_p)
|
||||
{
|
||||
QVariantList args = getArguments(L_p);
|
||||
QWidget *parent = nullptr;
|
||||
QString labelText = "LuaEngine";
|
||||
if (args.length() >= 1) {
|
||||
labelText = args.at(0).toString();
|
||||
if (args.length() >= 2) {
|
||||
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) {
|
||||
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) {
|
||||
parent = (QWidget*)qvariant_cast<void*>(args.at(1));
|
||||
}
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
labelText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -521,16 +527,14 @@ int LuaEngineGui::createCheckBox(lua_State *L_p)
|
|||
|
||||
int LuaEngineGui::createDialog(lua_State *L_p)
|
||||
{
|
||||
QVariantList args = getArguments(L_p);
|
||||
QWidget *parent = nullptr;
|
||||
QString windowTitle = "LuaEngine";
|
||||
if (args.length() >= 1) {
|
||||
windowTitle = args.at(0).toString();
|
||||
if (args.length() >= 2) {
|
||||
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) {
|
||||
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) {
|
||||
parent = (QWidget*)qvariant_cast<void*>(args.at(1));
|
||||
}
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
windowTitle = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -548,16 +552,14 @@ int LuaEngineGui::createDialog(lua_State *L_p)
|
|||
|
||||
int LuaEngineGui::createLabel(lua_State *L_p)
|
||||
{
|
||||
QVariantList args = getArguments(L_p);
|
||||
QWidget *parent = nullptr;
|
||||
QString labelText = "LuaEngine";
|
||||
if (args.length() >= 1) {
|
||||
labelText = args.at(0).toString();
|
||||
if (args.length() >= 2) {
|
||||
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) {
|
||||
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) {
|
||||
parent = (QWidget*)qvariant_cast<void*>(args.at(1));
|
||||
}
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
labelText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -608,16 +610,14 @@ int LuaEngineGui::createLayout(lua_State *L_p)
|
|||
|
||||
int LuaEngineGui::createLineEdit(lua_State *L_p)
|
||||
{
|
||||
QVariantList args = getArguments(L_p);
|
||||
QWidget *parent = nullptr;
|
||||
QString editText = "LuaEngine";
|
||||
if (args.length() >= 1) {
|
||||
editText = args.at(0).toString();
|
||||
if (args.length() >= 2) {
|
||||
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) {
|
||||
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) {
|
||||
parent = (QWidget*)qvariant_cast<void*>(args.at(1));
|
||||
}
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
editText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -630,16 +630,14 @@ int LuaEngineGui::createLineEdit(lua_State *L_p)
|
|||
|
||||
int LuaEngineGui::createMainWindow(lua_State *L_p)
|
||||
{
|
||||
QVariantList args = getArguments(L_p);
|
||||
QWidget *parent = nullptr;
|
||||
QString windowTitle = "LuaEngine";
|
||||
if (args.length() >= 1) {
|
||||
windowTitle = args.at(0).toString();
|
||||
if (args.length() >= 2) {
|
||||
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) {
|
||||
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) {
|
||||
parent = (QWidget*)qvariant_cast<void*>(args.at(1));
|
||||
}
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
windowTitle = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -739,16 +737,14 @@ int LuaEngineGui::createPlainTextEdit(lua_State *L_p)
|
|||
|
||||
int LuaEngineGui::createPushButton(lua_State *L_p)
|
||||
{
|
||||
QVariantList args = getArguments(L_p);
|
||||
QWidget *parent = nullptr;
|
||||
QString buttonText = "LuaEngine";
|
||||
if (args.length() >= 1) {
|
||||
buttonText = args.at(0).toString();
|
||||
if (args.length() >= 2) {
|
||||
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) {
|
||||
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) {
|
||||
parent = (QWidget*)qvariant_cast<void*>(args.at(1));
|
||||
}
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
buttonText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue