Make typesystem global variable
[lqt/mk.git] / generator / signalslot.lua
blob7437ce46c5319d53c076628ac1bab2870fbd4361
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 end
14 end
15 end
17 function slots_for_signals()
18 for sig in pairs(signals) do
19 local args, comma = '(', ''
20 for i, a in ipairs(sig.arguments) do
21 args = args .. comma .. a.xarg.type_name .. ' arg'..i
22 comma = ', '
23 end
24 args = args .. ')'
25 local pushlines, stack = make_pushlines(sig.arguments)
26 if pushlines then
27 if not slots['void __slot '..args] then
28 slots['void __slot '..args] = 'void LqtSlotAcceptor::__slot '..args..[[ {
29 //int oldtop = lua_gettop(L);
30 //lua_getfield(L, -1, "__slot]]..string.gsub(args, ' arg.', '')..[[");
31 //if (lua_isnil(L, -1)) {
32 //lua_pop(L, 1);
33 //lua_getfield(L, -1, "__slot");
34 //}
35 //if (!lua_isfunction(L, -1)) {
36 //lua_settop(L, oldtop);
37 //return;
38 //}
39 lua_pushvalue(L, -2);
40 ]] .. pushlines .. [[
41 if (lqtL_pcall(L, ]]..stack..[[+1, 0, 0)) {
42 //lua_error(L);
43 qDebug() << lua_tostring(L, -1);
44 lua_pop(L, 1);
46 //lua_settop(L, oldtop);
49 end
50 else
51 ignore(sig.xarg.fullname, 'slot', stack)
52 end
53 end
54 end
56 function print_slots(s)
57 print_slot_h'class LqtSlotAcceptor : public QObject {'
58 print_slot_h' Q_OBJECT'
59 print_slot_h' lua_State *L;'
60 print_slot_h' public:'
61 print_slot_h(' LqtSlotAcceptor(lua_State *l, QObject *p=NULL) : QObject(p), L(l) { setObjectName("'..module_name..'"); lqtL_register(L, this); }')
62 print_slot_h' virtual ~LqtSlotAcceptor() { lqtL_unregister(L, this); }'
63 print_slot_h' public slots:'
64 for p, b in pairs(s) do
65 print_slot_h(' '..p..';')
66 print_slot_c(b)
67 end
68 print_slot_h'};\n'
69 print_slot_h('\nextern LqtSlotAcceptor *lqtSlotAcceptor_'..module_name..';')
70 print_slot_c('\nLqtSlotAcceptor *lqtSlotAcceptor_'..module_name..';')
71 end
74 -------------------------------------------------------------------------------
76 function process(functions)
77 copy_signals(functions)
78 slots_for_signals()
79 end
81 function output()
82 print_slot_h('#ifndef LQT_SLOT_'..module_name)
83 print_slot_h('#define LQT_SLOT_'..module_name)
84 print_slot_h(output_includes)
85 print_slot_c('#include "'..module_name..'_slot.hpp'..'"\n\n')
87 print_slots(slots)
89 print_slot_h('#endif')
90 end