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