mirror of
				https://gitlab.com/Syping/luaengineapp.git
				synced 2025-10-31 02:20:20 +01:00 
			
		
		
		
	move connect to LuaEngine
This commit is contained in:
		
							parent
							
								
									6cd4614371
								
							
						
					
					
						commit
						d277e0e8c5
					
				
					 4 changed files with 38 additions and 45 deletions
				
			
		|  | @ -34,12 +34,6 @@ LuaEngineGui::LuaEngineGui(QObject *parent, bool loadBaseLibraries) : LuaEngine( | |||
| { | ||||
|     L = luaState(); | ||||
|     pushClass(L); | ||||
|     pushEngine(L); | ||||
| } | ||||
| 
 | ||||
| void LuaEngineGui::pushEngine(lua_State *L_p) | ||||
| { | ||||
|     pushPointer(L_p, "__LuaEngineGui", (void*)this); | ||||
| } | ||||
| 
 | ||||
| void LuaEngineGui::pushClass(lua_State *L_p) | ||||
|  | @ -81,9 +75,6 @@ void LuaEngineGui::pushClass(lua_State *L_p) | |||
|     pushFunction(L_p, "createMenu", createMenu); | ||||
|     pushFunction(L_p, "createMenuBar", createMenuBar); | ||||
|     pushFunction(L_p, "createMenuEntry", createMenuEntry); | ||||
| 
 | ||||
|     // Connect
 | ||||
|     pushFunction(L_p, "connect", connect_p); | ||||
| } | ||||
| 
 | ||||
| void LuaEngineGui::pushClass(LuaEngine *luaEngine) | ||||
|  | @ -356,37 +347,6 @@ int LuaEngineGui::setWidgetLayout(lua_State *L_p) | |||
|     return 0; | ||||
| } | ||||
| 
 | ||||
| int LuaEngineGui::connect_p(lua_State *L_p) | ||||
| { | ||||
|     if (getArgumentCount(L_p) >= 3) { | ||||
|         QObject *object = (QObject*)getPointer(L_p, 1); | ||||
|         QString signalString = getVariant(L_p, 2).toString(); | ||||
|         int signalIndex = object->metaObject()->indexOfSignal(signalString.toUtf8().data()); | ||||
|         if (signalIndex != -1) { | ||||
|             LuaEngineGui *engine = (LuaEngineGui*)getPointer(L_p, "__LuaEngineGui"); | ||||
|             int slotIndex = engine->metaObject()->indexOfSlot("luaTriggerSlot()"); | ||||
|             if (slotIndex != -1) { | ||||
|                 QMetaMethod signal = object->metaObject()->method(signalIndex); | ||||
|                 QMetaMethod slot = engine->metaObject()->method(slotIndex); | ||||
|                 QString funcStorage; | ||||
|                 QTextStream(&funcStorage) << "__ConnectFunc_" << object << "_" << signal.name(); | ||||
|                 pushVariant(L_p, funcStorage.toUtf8().data(), getVariant(L_p, 3).toString()); | ||||
|                 QObject::connect(object, signal, engine, slot); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
| void LuaEngineGui::luaTriggerSlot() | ||||
| { | ||||
|     QMetaMethod signal = sender()->metaObject()->method(senderSignalIndex()); | ||||
|     QString funcStorage; | ||||
|     QTextStream(&funcStorage) << "__ConnectFunc_" << sender() << "_" << signal.name(); | ||||
|     QString luaConnectFunc = getVariant(funcStorage.toUtf8().data()).toString(); | ||||
|     executeLuaFunction(luaConnectFunc.toUtf8().data(), QVariant::fromValue((void*)sender())); | ||||
| } | ||||
| 
 | ||||
| QString LuaEngineGui::nameForPointer(void *pointer) | ||||
| { | ||||
|     QString nameStorage; | ||||
|  |  | |||
|  | @ -28,7 +28,6 @@ class LUAENGINEGUISHARED_EXPORT LuaEngineGui : public LuaEngine | |||
|     Q_OBJECT | ||||
| public: | ||||
|     LuaEngineGui(QObject *parent = nullptr, bool loadBaseLibraries = true); | ||||
|     void pushEngine(lua_State *L_p); | ||||
|     static void pushClass(lua_State *L_p); | ||||
|     static void pushClass(LuaEngine *luaEngine); | ||||
|     static int showMessageBox(lua_State *L_p); | ||||
|  | @ -43,10 +42,6 @@ public: | |||
|     static int createMenuBar(lua_State *L_p); | ||||
|     static int createMenuEntry(lua_State *L_p); | ||||
|     static int setWidgetLayout(lua_State *L_p); | ||||
|     static int connect_p(lua_State *L_p); | ||||
| 
 | ||||
| public slots: | ||||
|     void luaTriggerSlot(); | ||||
| 
 | ||||
| private: | ||||
|     lua_State *L; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue