separated base types and qt types definitions
[lqt.git] / generator / types.lua
blobda84e425fc87652922795e0e70f66bee347065c0
1 #!/usr/bin/lua
3 --[[
5 Copyright (c) 2007-2008 Mauro Iazzi
7 Permission is hereby granted, free of charge, to any person
8 obtaining a copy of this software and associated documentation
9 files (the "Software"), to deal in the Software without
10 restriction, including without limitation the rights to use,
11 copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the
13 Software is furnished to do so, subject to the following
14 conditions:
16 The above copyright notice and this permission notice shall be
17 included in all copies or substantial portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 OTHER DEALINGS IN THE SOFTWARE.
28 --]]
30 local base_types = (...) or {}
32 local BaseType = function(s)
33 s = tostring(s)
34 return {
35 get = function(j)
36 return 'lua_to'..s..'(L, '..tostring(j)..')', 1
37 end,
38 push = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
39 return 'lua_push'..s..'(L, '..tostring(j)..')', 1
40 end,
42 end
43 local integer_type = {
44 get = function(j)
45 return 'lua_tointeger(L, '..tostring(j)..')', 1
46 end,
47 push = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
48 return 'lua_pushinteger(L, '..tostring(j)..')', 1
49 end,
50 test = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
51 return 'lqtL_isinteger(L, '..tostring(j)..')', 1
52 end,
54 local number_type = {
55 get = function(j)
56 return 'lua_tonumber(L, '..tostring(j)..')', 1
57 end,
58 push = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
59 return 'lua_pushnumber(L, '..tostring(j)..')', 1
60 end,
61 test = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
62 return 'lqtL_isnumber(L, '..tostring(j)..')', 1
63 end,
65 local integer_type = {
66 get = function(j)
67 return 'lua_tointeger(L, '..tostring(j)..')', 1
68 end,
69 push = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
70 return 'lua_pushinteger(L, '..tostring(j)..')', 1
71 end,
72 test = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
73 return 'lqtL_isinteger(L, '..tostring(j)..')', 1
74 end,
76 local bool_type = {
77 get = function(j)
78 return 'lua_toboolean(L, '..tostring(j)..')', 1
79 end,
80 push = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
81 return 'lua_pushboolean(L, '..tostring(j)..')', 1
82 end,
83 test = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
84 return 'lqtL_isboolean(L, '..tostring(j)..')', 1
85 end,
88 base_types['char const*'] = {
89 get = function(j)
90 return 'lua_tostring(L, '..tostring(j)..')', 1
91 end,
92 push = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
93 return 'lua_pushstring(L, '..tostring(j)..')', 1
94 end,
95 test = function(j)
96 return 'lqtL_isstring(L, '..tostring(j)..')', 1
97 end,
99 base_types['char'] = integer_type
100 base_types['unsigned char'] = integer_type
101 base_types['int'] = integer_type
102 base_types['unsigned int'] = integer_type
103 base_types['short'] = integer_type
104 base_types['short int'] = integer_type
105 base_types['unsigned short'] = integer_type
106 base_types['unsigned short int'] = integer_type
107 base_types['short unsigned int'] = integer_type
108 base_types['long'] = integer_type
109 base_types['unsigned long'] = integer_type
110 base_types['long int'] = integer_type
111 base_types['unsigned long int'] = integer_type
112 base_types['long unsigned int'] = integer_type
113 base_types['long long'] = integer_type
114 base_types['unsigned long long'] = integer_type
115 base_types['long long int'] = integer_type
116 base_types['unsigned long long int'] = integer_type
117 base_types['float'] = number_type
118 base_types['double'] = number_type
119 base_types['bool'] = bool_type
121 ---[[
122 base_types['int&'] = {
123 get = function(j)
124 return '*lqtL_tointref(L, '..j..')', 1
125 end,
126 push = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
127 return 'lua_pushinteger(L, '..tostring(j)..')', 1
128 end,
129 test = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
130 return 'lqtL_isinteger(L, '..tostring(j)..')', 1
131 end,
133 base_types['char**'] = {
134 get = function(j)
135 return 'lqtL_toarguments(L, '..tostring(j)..')', 1
136 end,
137 push = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
138 return 'lqtL_pusharguments(L, '..tostring(j)..')', 1
139 end,
140 test = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
141 return 'lua_istable(L, '..tostring(j)..')', 1
142 end,
144 --]]
147 return base_types