Update BUILD
[lqt/mk.git] / generator / qtypes.lua
blobcc05b1c0ee00ae3efa671bb72e09184b03ebd7cb
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 qt_types = (...) or {}
32 --[[
33 qt_types['QSizeF'] = {
34 get = function(i) return 'QSizeF(lua_tonumber(L, '..i..'), lua_tonumber(L, '..i..'+1))', 2, 'QSizeF' end,
35 push = function(i) return 'lua_pushnumber(L, '..i..'.width()), lua_pushnumber(L, '..i..'.height())', 2 end,
36 test = function(i) return '(lqtL_isnumber(L, '..i..') && lqtL_isnumber(L, '..i..'+1))', 2 end,
37 onstack = 'number,number,',
39 qt_types['QSizeF const&'] = qt_types['QSizeF']
41 qt_types['QSize'] = {
42 get = function(i) return 'QSize(lua_tointeger(L, '..i..'), lua_tointeger(L, '..i..'+1))', 2, 'QSize' end,
43 push = function(i) return 'lua_pushinteger(L, '..i..'.width()), lua_pushinteger(L, '..i..'.height())', 2 end,
44 test = function(i) return '(lqtL_isinteger(L, '..i..') && lqtL_isinteger(L, '..i..'+1))', 2 end,
45 onstack = 'integer,integer,',
47 qt_types['QSize const&'] = qt_types['QSize']
49 qt_types['QPoint'] = {
50 get = function(i) return 'QPoint(lua_tointeger(L, '..i..'), lua_tointeger(L, '..i..'+1))', 2, 'QPoint' end,
51 push = function(i) return 'lua_pushinteger(L, '..i..'.x()), lua_pushinteger(L, '..i..'.y())', 2 end,
52 test = function(i) return '(lqtL_isinteger(L, '..i..') && lqtL_isinteger(L, '..i..'+1))', 2 end,
53 onstack = 'integer,integer,',
55 qt_types['QPoint const&'] = qt_types['QPoint']
57 qt_types['QPointF'] = {
58 get = function(i) return 'QPointF(lua_tonumber(L, '..i..'), lua_tonumber(L, '..i..'+1))', 2, 'QPointF' end,
59 push = function(i) return 'lua_pushnumber(L, '..i..'.x()), lua_pushnumber(L, '..i..'.y())', 2 end,
60 test = function(i) return '(lqtL_isnumber(L, '..i..') && lqtL_isnumber(L, '..i..'+1))', 2 end,
61 onstack = 'number,number,',
63 qt_types['QPointF const&'] = qt_types['QPointF']
65 qt_types['QRect'] = {
66 get = function(i) return 'QRect(lua_tointeger(L, '..i..'), lua_tointeger(L, '..i..'+1), lua_tointeger(L, '..i..'+2), lua_tointeger(L, '..i..'+3))', 4, 'QRect' end,
67 push = function(i) return 'lua_pushinteger(L, '..i..'.x()), lua_pushinteger(L, '..i..'.y()), lua_pushinteger(L, '..i..'.width()), lua_pushinteger(L, '..i..'.height())', 4 end,
68 test = function(i) return '(lqtL_isinteger(L, '..i..') && lqtL_isinteger(L, '..i..'+1) && lqtL_isinteger(L, '..i..'+2) && lqtL_isinteger(L, '..i..'+3))', 4 end,
69 onstack = 'integer,integer,integer,integer,',
71 qt_types['QRect const&'] = qt_types['QRect']
73 qt_types['QRectF'] = {
74 get = function(i) return 'QRectF(lua_tonumber(L, '..i..'), lua_tonumber(L, '..i..'+1), lua_tonumber(L, '..i..'+2), lua_tonumber(L, '..i..'+3))', 4, 'QRectF' end,
75 push = function(i) return 'lua_pushnumber(L, '..i..'.x()), lua_pushnumber(L, '..i..'.y()), lua_pushnumber(L, '..i..'.width()), lua_pushnumber(L, '..i..'.height())', 4 end,
76 test = function(i) return '(lqtL_isnumber(L, '..i..') && lqtL_isnumber(L, '..i..'+1) && lqtL_isnumber(L, '..i..'+2) && lqtL_isnumber(L, '..i..'+3))', 4 end,
77 onstack = 'number,number,number,number,',
79 qt_types['QRectF const&'] = qt_types['QRectF']
82 qt_types['QByteArray'] = {
83 get = function(i) return 'QByteArray(lua_tostring(L, '..i..'), lua_objlen(L, '..i..'))', 1, 'QByteArray' end,
84 push = function(i) return 'lua_pushlstring(L, '..i..'.constData(), '..i..'.size())', 1 end,
85 test = function(i) return 'lqtL_isstring(L, '..i..')', 1 end,
86 onstack = 'string,',
88 qt_types['QByteArray const&'] = qt_types['QByteArray']
90 qt_types['QList<QByteArray>'] = {
91 get = function(i) return 'lqtL_getStringList(L, '..i..')', 1, 'QList<QByteArray>' end,
92 push = function(i) return 'lqtL_pushStringList(L, '..i..')', 1 end,
93 test = function(i) return 'lua_istable(L, '..i..')', 1 end,
94 onstack = 'table,',
97 if not getmetatable(qt_types) then
98 setmetatable(qt_types, {
99 __index = function(t, k)
100 if type(k)=='string'
101 and string.match(k, '^QFlags<[%w:]+>$') then
102 local e = string.match(k, '^QFlags<([%w:]+)>$')
103 if not qt_types[e] then return nil end
104 e = string.gsub(e, '::', '.')
105 local ret = {
106 get = function(i)
107 return '('..k..'(lqtL_getflags(L, '..i..', "'..e..'")))', 1
108 end,
109 push = function(i)
110 return 'lqtL_pushflags(L, '..i..', "'..e..'")', 1
111 end,
112 test = function(i)
113 return 'lqtL_isflags(L, '..i..')', 1
114 end,
115 onstack = 'table,',
117 return ret
119 end,
123 return qt_types