fixed getting int reference
[lqt.git] / generator / classes.lua
blob6607c41dc5140759dde3a99ad827b17ad3eafd1c
1 #!/usr/bin/lua
3 lqt = lqt or {}
4 lqt.classes = lqt.classes or {}
7 local pointer_t = function(fn)
8 local cn = string.gsub(fn, '::', '.')
9 return {
10 -- the argument is a pointer to class
11 push = function(n)
12 return 'lqtL_passudata(L, '..n..', "'..cn..'*")', 1
13 end,
14 get = function(n)
15 return 'static_cast<'..fn..'*>'
16 ..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
17 end,
18 test = function(n)
19 return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
20 end,
22 end
23 local pointer_const_t = function(fn)
24 local cn = string.gsub(fn, '::', '.')
25 return {
26 -- the argument is a pointer to constant class instance
27 push = function(n)
28 return 'lqtL_passudata(L, '..n..', "'..cn..'*")', 1
29 end,
30 get = function(n)
31 return 'static_cast<'..fn..'*>'
32 ..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
33 end,
34 test = function(n)
35 return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
36 end,
38 end
39 local ref_t = function(fn)
40 local cn = string.gsub(fn, '::', '.')
41 return {
42 -- the argument is a reference to class
43 push = function(n)
44 return 'lqtL_passudata(L, &'..n..', "'..cn..'*")', 1
45 end,
46 get = function(n)
47 return '*static_cast<'..fn..'*>'
48 ..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
49 end,
50 test = function(n)
51 return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
52 end,
54 end
55 local instance_t = function(fn)
56 local cn = string.gsub(fn, '::', '.')
57 return {
58 -- the argument is the class itself
59 push = function(n)
60 return 'lqtL_copyudata(L, &'..n..', "'..cn..'*")', 1
61 end,
62 get = function(n)
63 return '*static_cast<'..fn..'*>'
64 ..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
65 end,
66 test = function(n)
67 return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
68 end,
70 end
71 local const_ref_t = function(fn)
72 local cn = string.gsub(fn, '::', '.')
73 return {
74 -- the argument is a pointer to class
75 push = function(n)
76 return 'lqtL_copyudata(L, &'..n..', "'..cn..'*")', 1, string.gsub(fn, ' const&$', '')
77 end,
78 get = function(n)
79 return '*static_cast<'..fn..'*>'
80 ..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
81 end,
82 test = function(n)
83 return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
84 end,
86 end
88 lqt.classes.insert = function(cname, types) --, cancopy)
89 if types[cname]==nil then
90 types[cname..'*'] = pointer_t(cname)
91 types[cname..' const*'] = pointer_const_t(cname)
92 types[cname..'&'] = ref_t(cname)
93 --if cancopy then
94 types[cname] = instance_t(cname)
95 types[cname..' const&'] = const_ref_t(cname)
96 --end
97 return true
98 else
99 return nil