make_namespace can accept ids instead of names
[lqt.git] / qt_generator.lua
blob628e8a3944cda3a049cbf5929976d9afd8bf9fb4
1 #!/usr/bin/lua
3 xml = dofile'xml.lua'
4 B = dofile'binder.lua'
6 function NOINSTANCE(b, name)
7 b.types_from_stack[name] = function(i) error('cannot copy '..name) end
8 b.types_test[name] = function(i) error('cannot copy '..name) end
9 b.types_to_stack[name] = function(i) error('cannot copy '..name) end
11 b.types_from_stack[(name..' *')] = function(i) return '*static_cast<'..name..'**>(lqtL_toudata(L, '..tostring(i)..', "'..name..'"))' end
12 b.types_test[(name..' *')] = function(i) return 'lqtL_testudata(L, '..tostring(i)..', "'..name..'*")' end
13 b.types_to_stack[(name..' *')] = function(i) return 'lqtL_pushudata(L, '..tostring(i)..', "'..name..'*")' end
14 end
16 function cp_file(src, dst)
17 src = (type(src)=='string') and io.open(src, 'r') or src
18 dst = (type(dst)=='string') and io.open(dst, 'w') or dst
19 local content = src:read('*a')
20 dst:write(content)
21 src:close()
22 dst:close()
23 end
25 function BINDQT(n)
26 n = tostring(n)
27 local h, c = B:make_namespace(n, n)
28 print(n..': writing definition file')
29 f = io.open('src/lqt_bind_'..n..'.cpp', 'w')
30 f:write(c)
31 f:close()
33 print(n..': writing prototypes file')
34 f = io.open('src/lqt_bind_'..n..'.hpp', 'w')
35 f:write(h)
36 f:close()
37 end
39 function make_standard_qt(B, classlist)
41 cp_file('lqt_common.hpp', 'src/lqt_common.hpp')
42 cp_file('lqt_common.cpp', 'src/lqt_common.cpp')
45 local clist = {}
46 for s in string.gmatch(classlist, '([%u%l%d]+)') do
47 clist[s] = true
48 end
49 classlist = clist
50 end
52 local tmpfile='tmp/auto'
54 f = io.open(tmpfile..'.cpp', 'w')
55 for n in pairs(classlist) do
56 f:write('#include <'..n..'>\n')
57 end
58 f:write'\nmain() {\n'
59 for n in pairs(classlist) do
60 f:write(' '..n..' *'..string.lower(n)..';\n')
61 end
62 f:write'}\n'
63 f:close()
65 --os.execute'gccxml -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -fxml=auto.xml auto.cpp'
66 os.execute('gccxml `pkg-config QtGui QtCore --cflags` -fxml='..tmpfile..'.xml '..tmpfile..'.cpp')
68 --os.remove'auto.cpp'
70 B:init(tmpfile..'.xml')
72 B.filter = function (m)
73 local n = type(m)=='table' and type(m.attr)=='table' and m.attr.name
74 if n and string.match(n, "[_%w]*[xX]11[_%w]*$") then
75 return true, 'it is X11 specific'
76 end
77 if n and string.match(n, "[_%w]*_[_%w]*$") then
78 return true, 'it is meant to be internal'
79 end
80 return false
81 end
84 NOINSTANCE(B, 'QCoreApplication')
87 B.types_from_stack['QString'] = function(i) return 'QString::fromAscii(lua_tostring(L, '..tostring(i)..'), lua_objlen(L, '..tostring(i)..'))' end
88 B.types_test['QString'] = function(i) return '(lua_type(L, ' .. tostring(i) .. ')==LUA_TSTRING)' end
89 B.types_to_stack['QString'] = function(i) return 'lua_pushlstring(L, '..tostring(i)..'.toAscii().data(), '..tostring(i)..'.toAscii().size())' end
91 B.types_from_stack['QByteArray'] = function(i) return 'QByteArray(lua_tostring(L, '..tostring(i)..'), lua_objlen(L, '..tostring(i)..'))' end
92 B.types_test['QByteArray'] = function(i) return '(lua_type(L, ' .. tostring(i) .. ')==LUA_TSTRING)' end
93 B.types_to_stack['QByteArray'] = function(i) return 'lua_pushlstring(L, '..tostring(i)..'.data(), '..tostring(i)..'.size())' end
97 local clist = {}
98 for n in pairs(classlist) do
99 local c = B:find_name(n)
100 clist = B.set_union(clist, B:tree_of_bases(c))
102 classlist = B.set_union(classlist, clist)
105 for n in pairs(classlist) do
106 BINDQT(n)
110 make_standard_qt(B, [[
111 QObject