added "install" instruction
[Leditor.git] / src / lqt_function.cpp
blob57d9141befccd602814cc55509ce59ec8b601348
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)) {
7 lua_pop(L, 1);
8 lua_newtable(L);
9 lua_pushvalue(L, -1);
10 lua_setfield(L, LUA_REGISTRYINDEX, LUA_FUNCTION_REGISTRY);
12 lua_insert(L, -2);
14 lua_pushvalue(L, -1);
15 lua_gettable(L, functionTable);
17 if (!lqtL_testudata(L, -1, "QObject*")) {
18 //qDebug() << "not QObject* is" << luaL_typename(L, -1);
19 lua_pop(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);
23 lua_pushvalue(L, -2);
24 lua_settable(L, functionTable);
25 // registry this is associated to this function
26 lqtL_passudata(L, this, "QObject*");
27 lua_insert(L, -2);
28 lua_pushvalue(L, -2);
29 lua_settable(L, functionTable);
30 } else {
31 // leave the qobject on top;
32 //qDebug() << "Function" << this << "scheduled for deletion";
33 this->deleteLater();
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);
42 lua_gettable(L, -2);
43 lua_pushnil(L);
44 lua_settable(L, -3);
45 lua_pushlightuserdata(L, this);
46 lua_pushnil(L);
47 lua_settable(L, -3);
48 lua_pop(L, 1);
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)) {
54 return;
56 lua_pushlightuserdata(L, this);
57 lua_gettable(L, functionTable);
59 lua_call(L,0, 0);
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)) {
65 return;
67 lua_pushlightuserdata(L, this);
68 lua_gettable(L, functionTable);
69 lua_pushnumber(L, arg1);
70 lua_call(L,1, 0);
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)) {
76 return;
78 lua_pushlightuserdata(L, this);
79 lua_gettable(L, functionTable);
80 lua_pushinteger(L, arg1);
81 lua_call(L,1, 0);
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)) {
87 return;
89 lua_pushlightuserdata(L, this);
90 lua_gettable(L, functionTable);
91 lua_pushstring(L, arg1);
92 lua_call(L,1, 0);
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)) {
98 return;
100 lua_pushlightuserdata(L, this);
101 lua_gettable(L, functionTable);
102 lua_pushboolean(L, arg1);
103 lua_call(L,1, 0);
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)) {
109 return;
111 lua_pushlightuserdata(L, this);
112 lua_gettable(L, functionTable);
113 lua_pushinteger(L, arg1);lua_pushstring(L, arg2);
114 lua_call(L,2, 0);
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)) {
120 return;
122 lua_pushlightuserdata(L, this);
123 lua_gettable(L, functionTable);
124 lua_pushboolean(L, arg1);lua_pushnumber(L, arg2);
125 lua_call(L,2, 0);
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)) {
131 return;
133 lua_pushlightuserdata(L, this);
134 lua_gettable(L, functionTable);
135 lua_pushboolean(L, arg1);lua_pushinteger(L, arg2);
136 lua_call(L,2, 0);
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)) {
142 return;
144 lua_pushlightuserdata(L, this);
145 lua_gettable(L, functionTable);
146 lua_pushinteger(L, arg1);lua_pushinteger(L, arg2);
147 lua_call(L,2, 0);
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)) {
153 return;
155 lua_pushlightuserdata(L, this);
156 lua_gettable(L, functionTable);
157 lua_pushboolean(L, arg1);lua_pushboolean(L, arg2);
158 lua_call(L,2, 0);
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)) {
164 return;
166 lua_pushlightuserdata(L, this);
167 lua_gettable(L, functionTable);
168 lua_pushboolean(L, arg1);lua_pushstring(L, arg2);
169 lua_call(L,2, 0);
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)) {
175 return;
177 lua_pushlightuserdata(L, this);
178 lua_gettable(L, functionTable);
179 lua_pushinteger(L, arg1);lua_pushnumber(L, arg2);
180 lua_call(L,2, 0);
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)) {
186 return;
188 lua_pushlightuserdata(L, this);
189 lua_gettable(L, functionTable);
190 lua_pushnumber(L, arg1);lua_pushinteger(L, arg2);
191 lua_call(L,2, 0);
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)) {
197 return;
199 lua_pushlightuserdata(L, this);
200 lua_gettable(L, functionTable);
201 lua_pushstring(L, arg1);lua_pushboolean(L, arg2);
202 lua_call(L,2, 0);
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)) {
208 return;
210 lua_pushlightuserdata(L, this);
211 lua_gettable(L, functionTable);
212 lua_pushinteger(L, arg1);lua_pushboolean(L, arg2);
213 lua_call(L,2, 0);
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)) {
219 return;
221 lua_pushlightuserdata(L, this);
222 lua_gettable(L, functionTable);
223 lua_pushnumber(L, arg1);lua_pushnumber(L, arg2);
224 lua_call(L,2, 0);
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)) {
230 return;
232 lua_pushlightuserdata(L, this);
233 lua_gettable(L, functionTable);
234 lua_pushstring(L, arg1);lua_pushnumber(L, arg2);
235 lua_call(L,2, 0);
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)) {
241 return;
243 lua_pushlightuserdata(L, this);
244 lua_gettable(L, functionTable);
245 lua_pushstring(L, arg1);lua_pushinteger(L, arg2);
246 lua_call(L,2, 0);
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)) {
252 return;
254 lua_pushlightuserdata(L, this);
255 lua_gettable(L, functionTable);
256 lua_pushnumber(L, arg1);lua_pushboolean(L, arg2);
257 lua_call(L,2, 0);
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)) {
263 return;
265 lua_pushlightuserdata(L, this);
266 lua_gettable(L, functionTable);
267 lua_pushnumber(L, arg1);lua_pushstring(L, arg2);
268 lua_call(L,2, 0);
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)) {
274 return;
276 lua_pushlightuserdata(L, this);
277 lua_gettable(L, functionTable);
278 lua_pushstring(L, arg1);lua_pushstring(L, arg2);
279 lua_call(L,2, 0);