Re-enable access to protected functions
[lqt/mk.git] / generator / signalslot.lua
blob8e41b8d64d9778a75ba965da7a99f8b6eb838b57
1 module('signalslot', package.seeall)
3 local print_slot_h = fprint(assert(io.open(module_name.._src..module_name..'_slot.hpp', 'w')))
4 local print_slot_c = fprint(assert(io.open(module_name.._src..module_name..'_slot.cpp', 'w')))
6 local signals = {}
7 local slots = {}
9 function copy_signals(functions)
10 for f in pairs(functions) do
11 if f.xarg.signal=='1' then
12 signals[f] = true
13 if f.xarg.access == 'protected' then
14 f.xarg.access = 'public'
15 end
16 end
17 end
18 end
20 function slots_for_signals()
21 for sig in pairs(signals) do
22 local args, comma = '(', ''
23 for i, a in ipairs(sig.arguments) do
24 args = args .. comma .. a.xarg.type_name .. ' arg'..i
25 comma = ', '
26 end
27 args = args .. ')'
28 local pushlines, stack = make_pushlines(sig.arguments)
29 if pushlines then
30 if not slots['void __slot '..args] then
31 slots['void __slot '..args] = 'void LqtSlotAcceptor::__slot '..args..[[ {
32 //int oldtop = lua_gettop(L);
33 //lua_getfield(L, -1, "__slot]]..string.gsub(args, ' arg.', '')..[[");
34 //if (lua_isnil(L, -1)) {
35 //lua_pop(L, 1);
36 //lua_getfield(L, -1, "__slot");
37 //}
38 //if (!lua_isfunction(L, -1)) {
39 //lua_settop(L, oldtop);
40 //return;
41 //}
42 lua_pushvalue(L, -2);
43 ]] .. pushlines .. [[
44 if (lqtL_pcall(L, ]]..stack..[[+1, 0, 0)) {
45 //lua_error(L);
46 qDebug() << lua_tostring(L, -1);
47 lua_pop(L, 1);
49 //lua_settop(L, oldtop);
52 end
53 else
54 ignore(sig.xarg.fullname, 'slot', stack)
55 end
56 end
57 end
59 function print_slots(s)
60 print_slot_h'class LqtSlotAcceptor : public QObject {'
61 print_slot_h' Q_OBJECT'
62 print_slot_h' lua_State *L;'
63 print_slot_h' public:'
64 print_slot_h(' LqtSlotAcceptor(lua_State *l, QObject *p=NULL) : QObject(p), L(l) { setObjectName("'..module_name..'"); lqtL_register(L, this); }')
65 print_slot_h' virtual ~LqtSlotAcceptor() { lqtL_unregister(L, this); }'
66 print_slot_h' public slots:'
67 for p, b in pairs(s) do
68 print_slot_h(' '..p..';')
69 print_slot_c(b)
70 end
71 print_slot_h'};\n'
72 print_slot_h('\nextern LqtSlotAcceptor *lqtSlotAcceptor_'..module_name..';')
73 print_slot_c('\nLqtSlotAcceptor *lqtSlotAcceptor_'..module_name..';')
74 end
77 -------------------------------------------------------------------------------
79 function process(functions)
80 copy_signals(functions)
81 slots_for_signals()
82 end
84 function output()
85 print_slot_h('#ifndef LQT_SLOT_'..module_name)
86 print_slot_h('#define LQT_SLOT_'..module_name)
87 print_slot_h(output_includes)
88 print_slot_c('#include "'..module_name..'_slot.hpp'..'"\n\n')
90 print_slots(slots)
92 print_slot_h('#endif')
93 end