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
16 function cp_file(src
, dst
)
18 src
= (type(src
)=='string') and io
.open(src
, 'r') or src
19 check
= (type(dst
)=='string') and io
.open(dst
, 'r') or nil
20 if type(check
)=='userdata' then
21 local a
, b
= src
:read'*a', check
:read'*a'
22 if a
==b
then check
:close() src
:close() return end
26 src
= (type(src
)=='string') and io
.open(src
, 'r') or src
27 dst
= (type(dst
)=='string') and io
.open(dst
, 'w') or dst
28 local content
= src
:read('*a')
36 local h
, c
= B
:make_namespace(n
, n
, 'QtCore', 'QtGui')
37 print(n
..': writing definition file')
38 f
= io
.open('src/lqt_bind_'..n
..'.cpp', 'w')
42 print(n
..': writing prototypes file')
43 f
= io
.open('src/lqt_bind_'..n
..'.hpp', 'w')
49 B
.filter
= function (m
)
50 local n
= type(m
)=='table' and type(m
.attr
)=='table' and m
.attr
.name
51 if n
and string.match(n
, "[_%w]*[xX]11[_%w]*$") then
52 return true, 'it is X11 specific'
54 if n
and string.match(n
, "[_%w]*_[_%w]*$") then
55 return true, 'it is meant to be internal'
61 NOINSTANCE(B
, 'QCoreApplication')
64 B
.types_from_stack
['const QString&'] = function(i
) return 'QString::fromAscii(lua_tostring(L, '..tostring(i
)..'), lua_objlen(L, '..tostring(i
)..'))' end
65 B
.types_test
['const QString&'] = function(i
) return '(lua_type(L, ' .. tostring(i
) .. ')==LUA_TSTRING)' end
66 B
.types_to_stack
['const QString&'] = function(i
) return 'lua_pushlstring(L, '..tostring(i
)..'.toAscii().data(), '..tostring(i
)..'.toAscii().size())' end
67 B
.types_from_stack
['QString'] = function(i
) return 'QString::fromAscii(lua_tostring(L, '..tostring(i
)..'), lua_objlen(L, '..tostring(i
)..'))' end
68 B
.types_test
['QString'] = function(i
) return '(lua_type(L, ' .. tostring(i
) .. ')==LUA_TSTRING)' end
69 B
.types_to_stack
['QString'] = function(i
) return 'lua_pushlstring(L, '..tostring(i
)..'.toAscii().data(), '..tostring(i
)..'.toAscii().size())' end
71 B
.types_from_stack
['QByteArray'] = function(i
) return 'QByteArray(lua_tostring(L, '..tostring(i
)..'), lua_objlen(L, '..tostring(i
)..'))' end
72 B
.types_test
['QByteArray'] = function(i
) return '(lua_type(L, ' .. tostring(i
) .. ')==LUA_TSTRING)' end
73 B
.types_to_stack
['QByteArray'] = function(i
) return 'lua_pushlstring(L, '..tostring(i
)..'.data(), '..tostring(i
)..'.size())' end
76 function make_tree (cl
, tf
)
77 f
= io
.open(tf
..'.cpp', 'w')
79 f
:write('#include <'..n
..'>\n')
83 if not ({Qt
=true})[n
] then f
:write(' '..n
..' *'..string.lower(n
)..';\n') end
87 os
.execute('gccxml `pkg-config QtGui QtCore --cflags` -fxml='..tf
..'.xml '..tf
..'.cpp')
88 --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'
92 function make_standard_qt(B
, classlist
)
93 print'copying common files'
94 cp_file('lqt_qt_utils.hpp', 'src/lqt_qt_utils.hpp')
95 cp_file('lqt_qt_utils.cpp', 'src/lqt_qt_utils.cpp')
96 cp_file('lqt_common.hpp', 'src/lqt_common.hpp')
97 cp_file('lqt_common.cpp', 'src/lqt_common.cpp')
101 for s
in string.gmatch(classlist
, '([%u%l%d]+)') do
107 local tmpfile
='tmp/auto'
109 make_tree(classlist
, tmpfile
)
111 B
:init(tmpfile
..'.xml')
116 for n
in pairs(classlist
) do
117 local c
= B
:find_name(n
)
118 clist
= B
.set_union(clist
, B
:tree_of_bases(c
))
120 classlist
= B
.set_union(classlist
, clist
)
123 for n
in pairs(classlist
) do
128 function make_single_qt(B
, class
)
129 local classlist
= { class
}
131 local tmpfile
='tmp/auto'
133 make_tree(classlist
, tmpfile
)
134 B
:init(tmpfile
..'.xml')
140 function B
:enum_push_body_plus_qt(id
, c
)
141 local enum
= (type(id
)=='string') and self
:find_id(id
) or id
142 local e_static
= (self
:find_id(enum
.attr
.context
).tag == 'Class') and 'static ' or ''
143 local e_context
= self
:context_name(enum
)
144 local e_name
= 'lqt_pushenum_' .. enum
.attr
.name
145 local e_proto
, e_def
= '', ''
147 e_proto
= e_proto
.. ' ' .. e_static
.. self
.lua_proto(e_name
) .. ';\n'
148 e_def
= e_def
.. self
.lua_proto(c
.. e_name
) .. ' '
149 e_def
= e_def
.. '{\n'
150 e_def
= e_def
.. ' int enum_table = 0;\n'
151 e_def
= e_def
.. ' lua_getfield(L, LUA_REGISTRYINDEX, LQT_ENUMS);\n'
152 e_def
= e_def
.. ' if (!lua_istable(L, -1)) {\n'
153 e_def
= e_def
.. ' lua_pop(L, 1);\n'
154 e_def
= e_def
.. ' lua_newtable(L);\n'
155 e_def
= e_def
.. ' lua_pushvalue(L, -1);\n'
156 e_def
= e_def
.. ' lua_setfield(L, LUA_REGISTRYINDEX, LQT_ENUMS);\n'
157 e_def
= e_def
.. ' }\n'
159 e_def
= e_def
.. ' lua_newtable(L);\n'
160 e_def
= e_def
.. ' enum_table = lua_gettop(L);\n'
161 for i
, e
in ipairs(enum
) do
162 if (type(e
)=='table') and (e
.tag=='EnumValue') then
163 e_def
= e_def
.. ' lua_pushstring(L, "' .. e
.attr
.name
.. '");\n'
164 e_def
= e_def
.. ' lua_rawseti(L, enum_table, ' .. e
.attr
.init
.. ');\n'
165 e_def
= e_def
.. ' lua_pushinteger(L, ' .. e
.attr
.init
.. ');\n'
166 e_def
= e_def
.. ' lua_setfield(L, enum_table, "' .. e
.attr
.name
.. '");\n'
169 e_def
= e_def
.. ' lua_pushcfunction(L, ' .. c
.. e_name
.. '_QFLAGS_CREATOR' .. ');\n'
170 e_def
= e_def
.. ' lua_setfield(L, enum_table, "QFlags");\n'
171 e_def
= e_def
.. ' lua_pushvalue(L, -1);\n'
172 e_def
= e_def
.. ' lua_setfield(L, -3, "' .. e_context
.. enum
.attr
.name
.. '");\n'
173 e_def
= e_def
.. ' lua_remove(L, -2);\n'
174 e_def
= e_def
.. ' return 1;\n'
175 e_def
= e_def
.. '}\n'
176 -- ######## QFLAGS SPECIFIC
177 e_proto
= e_proto
.. ' ' .. e_static
.. self
.lua_proto(e_name
..'_QFLAGS_CREATOR') .. ';\n'
178 e_def
= e_def
.. self
.lua_proto(c
.. e_name
.. '_QFLAGS_CREATOR') .. [[ {
179 int argn = lua_gettop(L);
181 void *p = lua_newuserdata(L, sizeof(QFlags<]]..e_context
..enum
.attr
.name
..[[>*) + sizeof(QFlags<]]..e_context
..enum
.attr
.name
..[[>));
182 QFlags<]]..e_context
..enum
.attr
.name
..[[> *fl = static_cast<QFlags<]]..e_context
..enum
.attr
.name
..[[>*>( static_cast<void*>(&static_cast<QFlags<]]..e_context
..enum
.attr
.name
..[[>**>(p)[1]) );
184 for (i=1;i<=argn;i++) {
185 *fl |= static_cast<]]..e_context
..enum
.attr
.name
..[[>(lqtL_toenum(L, i, "]]..e_context
..enum
.attr
.name
..[["));
187 if (luaL_newmetatable(L, "QFlags<]]..e_context
..enum
.attr
.name
..[[>*")) {
188 lua_pushstring(L, "QFlags<]]..e_context
..enum
.attr
.name
..[[>*");
189 lua_setfield(L, -2, "__qtype");
191 lua_setmetatable(L, -2);
196 return e_proto
, e_def
, e_name
199 B
.enum_push_body
= B
.enum_push_body_plus_qt