1 #include "lqt_function.hpp"
2 LuaFunction::LuaFunction(lua_State
*state
):L(state
) {
3 int functionTable
= lua_gettop(L
); // not yet but soon
4 //qDebug() << "Function" << this << "is born";
5 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
6 if (lua_isnil(L
, -1)) {
10 lua_setfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
15 lua_gettable(L
, functionTable
);
17 if (!lqtL_testudata(L
, -1, "QObject*")) {
18 //qDebug() << "not QObject* is" << luaL_typename(L, -1);
20 // top of stack is the function I want
21 //qDebug() << "to be bound is" << luaL_typename(L, -1);
22 lua_pushlightuserdata(L
, this);
24 lua_settable(L
, functionTable
);
25 // registry this is associated to this function
26 lqtL_passudata(L
, this, "QObject*");
29 lua_settable(L
, functionTable
);
31 // leave the qobject on top;
32 //qDebug() << "Function" << this << "scheduled for deletion";
35 lua_replace(L
, functionTable
);
36 lua_settop(L
, functionTable
);
38 LuaFunction::~LuaFunction() {
39 //qDebug() << "Function" << this << "is dead";
40 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
41 lua_pushlightuserdata(L
, this);
45 lua_pushlightuserdata(L
, this);
50 void LuaFunction::function () {
51 int functionTable
= lua_gettop(L
) + 1;
52 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
53 if (!lua_istable(L
, -1)) {
56 lua_pushlightuserdata(L
, this);
57 lua_gettable(L
, functionTable
);
61 void LuaFunction::function (double arg1
) {
62 int functionTable
= lua_gettop(L
) + 1;
63 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
64 if (!lua_istable(L
, -1)) {
67 lua_pushlightuserdata(L
, this);
68 lua_gettable(L
, functionTable
);
69 lua_pushnumber(L
, arg1
);
72 void LuaFunction::function (int arg1
) {
73 int functionTable
= lua_gettop(L
) + 1;
74 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
75 if (!lua_istable(L
, -1)) {
78 lua_pushlightuserdata(L
, this);
79 lua_gettable(L
, functionTable
);
80 lua_pushinteger(L
, arg1
);
83 void LuaFunction::function (const char * arg1
) {
84 int functionTable
= lua_gettop(L
) + 1;
85 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
86 if (!lua_istable(L
, -1)) {
89 lua_pushlightuserdata(L
, this);
90 lua_gettable(L
, functionTable
);
91 lua_pushstring(L
, arg1
);
94 void LuaFunction::function (bool arg1
) {
95 int functionTable
= lua_gettop(L
) + 1;
96 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
97 if (!lua_istable(L
, -1)) {
100 lua_pushlightuserdata(L
, this);
101 lua_gettable(L
, functionTable
);
102 lua_pushboolean(L
, arg1
);
105 void LuaFunction::function (int arg1
, const char * arg2
) {
106 int functionTable
= lua_gettop(L
) + 1;
107 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
108 if (!lua_istable(L
, -1)) {
111 lua_pushlightuserdata(L
, this);
112 lua_gettable(L
, functionTable
);
113 lua_pushinteger(L
, arg1
);lua_pushstring(L
, arg2
);
116 void LuaFunction::function (bool arg1
, double arg2
) {
117 int functionTable
= lua_gettop(L
) + 1;
118 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
119 if (!lua_istable(L
, -1)) {
122 lua_pushlightuserdata(L
, this);
123 lua_gettable(L
, functionTable
);
124 lua_pushboolean(L
, arg1
);lua_pushnumber(L
, arg2
);
127 void LuaFunction::function (bool arg1
, int arg2
) {
128 int functionTable
= lua_gettop(L
) + 1;
129 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
130 if (!lua_istable(L
, -1)) {
133 lua_pushlightuserdata(L
, this);
134 lua_gettable(L
, functionTable
);
135 lua_pushboolean(L
, arg1
);lua_pushinteger(L
, arg2
);
138 void LuaFunction::function (int arg1
, int arg2
) {
139 int functionTable
= lua_gettop(L
) + 1;
140 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
141 if (!lua_istable(L
, -1)) {
144 lua_pushlightuserdata(L
, this);
145 lua_gettable(L
, functionTable
);
146 lua_pushinteger(L
, arg1
);lua_pushinteger(L
, arg2
);
149 void LuaFunction::function (bool arg1
, bool arg2
) {
150 int functionTable
= lua_gettop(L
) + 1;
151 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
152 if (!lua_istable(L
, -1)) {
155 lua_pushlightuserdata(L
, this);
156 lua_gettable(L
, functionTable
);
157 lua_pushboolean(L
, arg1
);lua_pushboolean(L
, arg2
);
160 void LuaFunction::function (bool arg1
, const char * arg2
) {
161 int functionTable
= lua_gettop(L
) + 1;
162 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
163 if (!lua_istable(L
, -1)) {
166 lua_pushlightuserdata(L
, this);
167 lua_gettable(L
, functionTable
);
168 lua_pushboolean(L
, arg1
);lua_pushstring(L
, arg2
);
171 void LuaFunction::function (int arg1
, double arg2
) {
172 int functionTable
= lua_gettop(L
) + 1;
173 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
174 if (!lua_istable(L
, -1)) {
177 lua_pushlightuserdata(L
, this);
178 lua_gettable(L
, functionTable
);
179 lua_pushinteger(L
, arg1
);lua_pushnumber(L
, arg2
);
182 void LuaFunction::function (double arg1
, int arg2
) {
183 int functionTable
= lua_gettop(L
) + 1;
184 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
185 if (!lua_istable(L
, -1)) {
188 lua_pushlightuserdata(L
, this);
189 lua_gettable(L
, functionTable
);
190 lua_pushnumber(L
, arg1
);lua_pushinteger(L
, arg2
);
193 void LuaFunction::function (const char * arg1
, bool arg2
) {
194 int functionTable
= lua_gettop(L
) + 1;
195 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
196 if (!lua_istable(L
, -1)) {
199 lua_pushlightuserdata(L
, this);
200 lua_gettable(L
, functionTable
);
201 lua_pushstring(L
, arg1
);lua_pushboolean(L
, arg2
);
204 void LuaFunction::function (int arg1
, bool arg2
) {
205 int functionTable
= lua_gettop(L
) + 1;
206 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
207 if (!lua_istable(L
, -1)) {
210 lua_pushlightuserdata(L
, this);
211 lua_gettable(L
, functionTable
);
212 lua_pushinteger(L
, arg1
);lua_pushboolean(L
, arg2
);
215 void LuaFunction::function (double arg1
, double arg2
) {
216 int functionTable
= lua_gettop(L
) + 1;
217 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
218 if (!lua_istable(L
, -1)) {
221 lua_pushlightuserdata(L
, this);
222 lua_gettable(L
, functionTable
);
223 lua_pushnumber(L
, arg1
);lua_pushnumber(L
, arg2
);
226 void LuaFunction::function (const char * arg1
, double arg2
) {
227 int functionTable
= lua_gettop(L
) + 1;
228 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
229 if (!lua_istable(L
, -1)) {
232 lua_pushlightuserdata(L
, this);
233 lua_gettable(L
, functionTable
);
234 lua_pushstring(L
, arg1
);lua_pushnumber(L
, arg2
);
237 void LuaFunction::function (const char * arg1
, int arg2
) {
238 int functionTable
= lua_gettop(L
) + 1;
239 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
240 if (!lua_istable(L
, -1)) {
243 lua_pushlightuserdata(L
, this);
244 lua_gettable(L
, functionTable
);
245 lua_pushstring(L
, arg1
);lua_pushinteger(L
, arg2
);
248 void LuaFunction::function (double arg1
, bool arg2
) {
249 int functionTable
= lua_gettop(L
) + 1;
250 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
251 if (!lua_istable(L
, -1)) {
254 lua_pushlightuserdata(L
, this);
255 lua_gettable(L
, functionTable
);
256 lua_pushnumber(L
, arg1
);lua_pushboolean(L
, arg2
);
259 void LuaFunction::function (double arg1
, const char * arg2
) {
260 int functionTable
= lua_gettop(L
) + 1;
261 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
262 if (!lua_istable(L
, -1)) {
265 lua_pushlightuserdata(L
, this);
266 lua_gettable(L
, functionTable
);
267 lua_pushnumber(L
, arg1
);lua_pushstring(L
, arg2
);
270 void LuaFunction::function (const char * arg1
, const char * arg2
) {
271 int functionTable
= lua_gettop(L
) + 1;
272 lua_getfield(L
, LUA_REGISTRYINDEX
, LUA_FUNCTION_REGISTRY
);
273 if (!lua_istable(L
, -1)) {
276 lua_pushlightuserdata(L
, this);
277 lua_gettable(L
, functionTable
);
278 lua_pushstring(L
, arg1
);lua_pushstring(L
, arg2
);