From fa45ba2779d63d2850db879c1f46f116aa4a18c4 Mon Sep 17 00:00:00 2001 From: Michal Kottman Date: Mon, 1 Mar 2010 12:18:21 +0100 Subject: [PATCH] use separate slot implementation for each module --- common/lqt_qt.cpp | 46 +++++++++++++++++++--------------------------- common/lqt_qt.hpp | 3 +-- generator/generator.lua | 20 ++++++++++++++------ 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/common/lqt_qt.cpp b/common/lqt_qt.cpp index 910c796..c5938a5 100644 --- a/common/lqt_qt.cpp +++ b/common/lqt_qt.cpp @@ -1,36 +1,28 @@ #include "lqt_qt.hpp" -int lqtL_qt_metacall (lua_State *L, QObject *self, +int lqtL_qt_metacall (lua_State *L, QObject *self, QObject *acceptor, QMetaObject::Call call, const char *name, int index, void **args) { - QObject *call_helper = (QObject*)NULL; - lua_getfield(L, LUA_REGISTRYINDEX, LQT_METACALLER); - if (lua_isuserdata(L, -1)) { - call_helper = (QObject*)lqtL_toudata(L, -1, "QObject*"); + int callindex = 0, oldtop = 0; + oldtop = lua_gettop(L); + lqtL_pushudata(L, self, name); // (1) + lua_getfield(L, -1, LQT_OBJSIGS); // (2) + //qDebug() << lua_gettop(L) << luaL_typename(L, -1); + lua_rawgeti(L, -1, index + 1); // (3) + if (!lua_isstring(L, -1)) { + lua_pop(L, 3); // (0) + lua_settop(L, oldtop); // (0) + QMetaObject::activate(self, self->metaObject(), index, args); + } else { + callindex = acceptor->metaObject()->indexOfSlot(lua_tostring(L, -1)); + // qDebug() << "Found slot" << name << lua_tostring(L,-1) << "on" << acceptor->objectName() << "with index" << callindex; + lua_pop(L, 2); // (1) + lua_getfield(L, -1, LQT_OBJSLOTS); // (2) + lua_rawgeti(L, -1, index+1); // (3) + lua_remove(L, -2); // (2) + index = acceptor->qt_metacall(call, callindex, args); } - lua_pop(L, 1); - if (call_helper!=NULL) { - int callindex = 0, oldtop = 0; - oldtop = lua_gettop(L); - lqtL_pushudata(L, self, name); // (1) - lua_getfield(L, -1, LQT_OBJSIGS); // (2) - //qDebug() << lua_gettop(L) << luaL_typename(L, -1); - lua_rawgeti(L, -1, index + 1); // (3) - if (!lua_isstring(L, -1)) { - lua_pop(L, 3); // (0) - lua_settop(L, oldtop); // (0) - QMetaObject::activate(self, self->metaObject(), index, args); - } else { - callindex = call_helper->metaObject()->indexOfSlot(lua_tostring(L, -1)); - lua_pop(L, 2); // (1) - lua_getfield(L, -1, LQT_OBJSLOTS); // (2) - lua_rawgeti(L, -1, index+1); // (3) - lua_remove(L, -2); // (2) - index = call_helper->qt_metacall(call, callindex, args); - } - } - //qDebug() << "no call_helper found"; return -1; } diff --git a/common/lqt_qt.hpp b/common/lqt_qt.hpp index 5661352..945f885 100644 --- a/common/lqt_qt.hpp +++ b/common/lqt_qt.hpp @@ -24,8 +24,7 @@ #include #include - -int lqtL_qt_metacall (lua_State *, QObject *, QMetaObject::Call, const char *, int, void **); +int lqtL_qt_metacall (lua_State *, QObject *, QObject *, QMetaObject::Call, const char *, int, void **); void lqtL_pushaddmethod (lua_State *); diff --git a/generator/generator.lua b/generator/generator.lua index 9ef56d8..b19acd3 100644 --- a/generator/generator.lua +++ b/generator/generator.lua @@ -592,7 +592,7 @@ local virtual_overload = function(v, types) lua_insert(L, -2); ]] .. pushlines .. [[ if (!]]..luacall..[[) { - return lua_error(L); + lua_error(L); } } lua_settop(L, oldtop); @@ -682,6 +682,7 @@ local print_shell_classes = function(classes) --print_head('#include <'..string.match(c.xarg.fullname, '^[^:]+')..'>') print_head'' if c.shell then + print_head('#include "'..module_name..'_slot.hpp'..'"\n\n') if c then print_head(c.shell_class) else @@ -897,7 +898,7 @@ int lqt_shell_]]..n..[[::qt_metacall(QMetaObject::Call call, int index, void **a //qDebug() << "fake calling!"; index = ]]..c.xarg.fullname..[[::qt_metacall(call, index, args); if (index < 0) return index; - return lqtL_qt_metacall(L, this, call, "QWidget*", index, args); + return lqtL_qt_metacall(L, this, lqtSlotAcceptor_]]..module_name..[[, call, "]]..c.xarg.fullname..[[*", index, args); } ]]) end @@ -912,7 +913,7 @@ local print_merged_build = function() merged:write('#include "'..p..'"\n') end local pro_file = assert(io.open(path..mergename..'.pro', 'w')) - + local print_pro= function(...) pro_file:write(...) pro_file:write'\n' @@ -980,8 +981,9 @@ local add_class = lqt.classes.insert or error('module lqt.classes not loaded') end print_meta('\t//lua_pushlightuserdata(L, (void*)&LqtSlotAcceptor::staticMetaObject);') print_meta('\t//lua_setfield(L, LUA_REGISTRYINDEX, LQT_METAOBJECT);') - print_meta('\tlqtL_passudata(L, (void*)(new LqtSlotAcceptor(L)), "QObject*");') - print_meta('\tlua_setfield(L, LUA_REGISTRYINDEX, LQT_METACALLER);') + print_meta('\t//lqtL_passudata(L, (void*)(new LqtSlotAcceptor(L)), "QObject*");') + print_meta('\t//lua_setfield(L, LUA_REGISTRYINDEX, LQT_METACALLER);') + print_meta('\tlqtSlotAcceptor_'..module_name..' = new LqtSlotAcceptor(L);') print_meta('\treturn 0;\n}') if fmeta then fmeta:close() end return classes @@ -1093,16 +1095,18 @@ local print_slots = function(s) print_slot_h' Q_OBJECT' print_slot_h' lua_State *L;' print_slot_h' public:' - print_slot_h' LqtSlotAcceptor(lua_State *l, QObject *p=NULL) : QObject(p), L(l) { lqtL_register(L, this); }' + print_slot_h(' LqtSlotAcceptor(lua_State *l, QObject *p=NULL) : QObject(p), L(l) { setObjectName("'..module_name..'"); lqtL_register(L, this); }') print_slot_h' virtual ~LqtSlotAcceptor() { lqtL_unregister(L, this); }' print_slot_h' public slots:' for p, b in pairs(s) do print_slot_h(' '..p..';') end print_slot_h'};\n' + print_slot_h('\nextern LqtSlotAcceptor *lqtSlotAcceptor_'..module_name..';') for p, b in pairs(s) do print_slot_c(b) end + print_slot_c('\nLqtSlotAcceptor *lqtSlotAcceptor_'..module_name..';') end @@ -1162,6 +1166,8 @@ local slots = slots_for_signals(signals, typesystem) print_enum(output_includes) +print_slot_h('#ifndef LQT_SLOT_'..module_name) +print_slot_h('#define LQT_SLOT_'..module_name) print_slot_h(output_includes) print_slot_c('#include "'..module_name..'_slot.hpp'..'"\n\n') @@ -1176,5 +1182,7 @@ local classes = print_class_list(classes) -- does that + prints everything relat local slots = print_slots(slots) +print_slot_h('#endif') + --print_openmodule(module_name) -- does that -- 2.11.4.GIT