4 lqt
.classes
= lqt
.classes
or {}
7 -- * push - push the instance of a class onto Lua stack
8 -- * get - retrieve the instance from Lua stack
9 -- * raw_test - true if the stack index is an instance
10 -- * test - true if the stack index is an instance, or if it is convertible to the type
11 -- * bound - true for generated classes (false for native types)
12 -- * foreign - comes from other module (like QtCore)
14 local pointer_t
= function(fn
, foreign
)
15 local cn
= string.gsub(fn
, '::', '.')
17 -- the argument is a pointer to class
19 return 'lqtL_pushudata(L, '..n
..', "'..cn
..'*")', 1
22 return 'static_cast<'..fn
..'*>'
23 ..'(lqtL_toudata(L, '..n
..', "'..cn
..'*"))', 1
26 return 'lqtL_isudata(L, '..n
..', "'..cn
..'*")', 1
28 raw_test
= function(n
) return 'lqtL_isudata(L, '..n
..', "'..cn
..'*")', 1 end,
34 local pointer_const_t
= function(fn
, foreign
)
35 local cn
= string.gsub(fn
, '::', '.')
37 -- the argument is a pointer to constant class instance
39 return 'lqtL_pushudata(L, '..n
..', "'..cn
..'*")', 1
43 if typesystem
.can_convert
[cn
] then
44 val
= 'lqtL_convert(L, '..n
..', "'..cn
..'*")'
46 val
= 'lqtL_toudata(L, '..n
..', "'..cn
..'*")'
48 return 'static_cast<'..fn
..'*>('..val
..')', 1
51 if typesystem
.can_convert
[cn
] then
52 return 'lqtL_canconvert(L, '..n
..', "'..cn
..'*")', 1
54 return 'lqtL_isudata(L, '..n
..', "'..cn
..'*")', 1
57 raw_test
= function(n
) return 'lqtL_isudata(L, '..n
..', "'..cn
..'*")', 1 end,
63 local ref_t
= function(fn
, foreign
)
64 local cn
= string.gsub(fn
, '::', '.')
66 -- the argument is a reference to class
68 return 'lqtL_pushudata(L, &'..n
..', "'..cn
..'*")', 1
71 return '*static_cast<'..fn
..'*>'
72 ..'(lqtL_toudata(L, '..n
..', "'..cn
..'*"))', 1
75 return 'lqtL_isudata(L, '..n
..', "'..cn
..'*")', 1
82 local instance_t
= function(fn
, foreign
)
83 local cn
= string.gsub(fn
, '::', '.')
85 -- the argument is the class itself
87 return 'lqtL_copyudata(L, &'..n
..', "'..cn
..'*")', 1
90 return '*static_cast<'..fn
..'*>'
91 ..'(lqtL_toudata(L, '..n
..', "'..cn
..'*"))', 1
94 return 'lqtL_isudata(L, '..n
..', "'..cn
..'*")', 1
101 local const_ref_t
= function(fn
, foreign
)
102 local cn
= string.gsub(fn
, '::', '.')
104 -- the argument is a pointer to class
106 return 'lqtL_copyudata(L, &'..n
..', "'..cn
..'*")', 1, string.gsub(fn
, ' const&$', '')
110 if typesystem
.can_convert
[cn
] then
111 val
= 'lqtL_convert(L, '..n
..', "'..cn
..'*")'
113 val
= 'lqtL_toudata(L, '..n
..', "'..cn
..'*")'
115 return '*static_cast<'..fn
..'*>('..val
..')', 1
118 if typesystem
.can_convert
[cn
] then
119 return 'lqtL_canconvert(L, '..n
..', "'..cn
..'*")', 1
121 return 'lqtL_isudata(L, '..n
..', "'..cn
..'*")', 1
124 raw_test
= function(n
) return 'lqtL_isudata(L, '..n
..', "'..cn
..'*")', 1 end,
131 local const_ptr_ref_t
= pointer_const_t
133 lqt
.classes
.insert
= function(cname
, foreign
)
134 if typesystem
[cname
]==nil then
135 typesystem
[cname
..'*'] = pointer_t(cname
, foreign
)
136 typesystem
[cname
..' const*'] = pointer_const_t(cname
, foreign
)
137 typesystem
[cname
..'&'] = ref_t(cname
, foreign
)
139 typesystem
[cname
] = instance_t(cname
, foreign
)
140 typesystem
[cname
..' const'] = instance_t(cname
, foreign
)
141 typesystem
[cname
..' const&'] = const_ref_t(cname
, foreign
)
142 typesystem
[cname
..'* const&'] = const_ptr_ref_t(cname
, foreign
)