2 * Copyright (c) 2007-2008 Mauro Iazzi
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
27 #include "lqt_qt_utils.hpp"
28 #include "lqt_common.hpp"
29 #include "lqt_function.hpp"
31 static int qt_slot_from_string (lua_State
*L
) {
32 lua_pushstring(L
, "1");
38 static int qt_signal (lua_State
*L
) {
39 lua_pushstring(L
, "2");
45 static int qt_derive (lua_State
*L
) {
46 if (!lua_isuserdata(L
, 1) || !lua_getmetatable(L
, 1)) {
48 lua_pushstring(L
, "no userdata or no metatable given");
51 lua_getfield(L
, -1, "__qtype");
52 if (!lua_isstring(L
, -1)) {
54 lua_pushstring(L
, "not a Qt type");
63 lua_setfield(L
, -2, "__base");
64 lua_pushcfunction(L
, lqtL_index
);
65 lua_setfield(L
, -2, "__index");
66 lua_pushcfunction(L
, lqtL_newindex
);
67 lua_setfield(L
, -2, "__newindex");
68 lua_setmetatable(L
, 1);
72 static int qt_slot_from_function (lua_State
*L
) {
74 LuaFunction
*f
= new LuaFunction(L
);
76 lua_pushstring(L
, "1function()");
80 static int qt_slot (lua_State
*L
) {
82 if (lua_type(L
, 1)==LUA_TSTRING
) {
83 ret
= qt_slot_from_string(L
);
84 } else if (lua_type(L
, 1)==LUA_TFUNCTION
) {
85 ret
= qt_slot_from_function(L
);
90 static int qt_pick (lua_State
*L
) {
91 int nargs
= lua_gettop(L
);
94 lqtL_manageudata(L
, i
);
99 static int qt_pass (lua_State
*L
) {
100 int nargs
= lua_gettop(L
);
103 lqtL_unmanageudata(L
, i
);
109 static luaL_Reg libqt
[] = {
113 { "signal", qt_signal
},
114 { "derive", qt_derive
},
118 int luaopen_qt (lua_State
*L
) {
119 luaL_register(L
, "qt", libqt
);