added evas object box
[ego.git] / src / lib / macro.h
blob0372c40784e8b3dacb6dd5f559bc13a88262be11
1 #ifndef EGO_MACRO_H
2 #define EGO_MACRO_H
4 #include "luaobj.h"
6 /*
7 * fn macros
8 */
10 #define FN(EGO_FUNC, E_FUNC) \
11 static int \
12 EGO_FUNC (lua_State *L) \
13 { \
14 luaobj_Object *obj = lua_touserdata (L, 1); \
15 E_FUNC (obj->data); \
16 return 1; \
20 * bool macros
23 #define GET_BOOL(EGO_FUNC, E_FUNC) \
24 static int \
25 EGO_FUNC (lua_State *L) \
26 { \
27 luaobj_Object *obj = lua_touserdata (L, 1); \
28 lua_pushboolean (L, E_FUNC (obj->data)); \
29 return 1; \
32 #define SET_BOOL(EGO_FUNC, E_FUNC) \
33 static int \
34 EGO_FUNC (lua_State *L) \
35 { \
36 luaobj_Object *obj = lua_touserdata (L, 1); \
37 E_FUNC (obj->data, lua_toboolean (L, 2)); \
38 return 0; \
42 * integer macros
45 #define GET_INTEGER(EGO_FUNC, E_FUNC) \
46 static int \
47 EGO_FUNC (lua_State *L) \
48 { \
49 luaobj_Object *obj = lua_touserdata (L, 1); \
50 lua_pushnumber (L, E_FUNC (obj->data)); \
51 return 1; \
54 #define SET_INTEGER(EGO_FUNC, E_FUNC) \
55 static int \
56 EGO_FUNC (lua_State *L) \
57 { \
58 luaobj_Object *obj = lua_touserdata (L, 1); \
59 E_FUNC (obj->data, luaL_checkinteger (L, 2)); \
60 return 0; \
64 * float macros
67 #define GET_FLOAT(EGO_FUNC, E_FUNC) \
68 static int \
69 EGO_FUNC (lua_State *L) \
70 { \
71 luaobj_Object *obj = lua_touserdata (L, 1); \
72 lua_pushnumber (L, E_FUNC (obj->data)); \
73 return 1; \
76 #define SET_FLOAT(EGO_FUNC, E_FUNC) \
77 static int \
78 EGO_FUNC (lua_State *L) \
79 { \
80 luaobj_Object *obj = lua_touserdata (L, 1); \
81 E_FUNC (obj->data, luaL_checknumber (L, 2)); \
82 return 0; \
86 * string macros
89 #define GET_STRING(EGO_FUNC, E_FUNC) \
90 static int \
91 EGO_FUNC (lua_State *L) \
92 { \
93 luaobj_Object *obj = lua_touserdata (L, 1); \
94 lua_pushstring (L, (const char *) E_FUNC (obj->data)); \
95 return 1; \
98 #define SET_STRING(EGO_FUNC, E_FUNC) \
99 static int \
100 EGO_FUNC (lua_State *L) \
102 luaobj_Object *obj = lua_touserdata (L, 1); \
103 E_FUNC (obj->data, luaL_checkstring (L, 2)); \
104 return 0; \
108 * obj macros
111 #define GET_OBJ(EGO_FUNC, E_FUNC) \
112 static int \
113 EGO_FUNC (lua_State *L) \
115 luaobj_Object *obj = lua_touserdata (L, 1); \
116 Evas_Object *tar = E_FUNC (obj->data); \
117 if (tar != NULL) \
119 luaobj_Ref *ref = evas_object_data_get (tar, "luaobj"); \
120 luaobj_get_ref (L, ref); \
122 else \
123 lua_pushnil (L); \
124 return 1; \
127 #define SET_OBJ(EGO_FUNC, E_FUNC) \
128 static int \
129 EGO_FUNC (lua_State *L) \
131 luaobj_Object *obj = lua_touserdata (L, 1); \
132 luaobj_Object *tar = lua_touserdata (L, 2); \
133 E_FUNC (obj->data, tar->data); \
134 return 0; \
137 #define FN_BOOL(EGO_FUNC, E_FUNC) \
138 static int \
139 EGO_FUNC (lua_State *L) \
141 luaobj_Object *obj = lua_touserdata (L, 1); \
142 E_FUNC (obj->data, lua_toboolean (L, 2)); \
143 return 0; \
146 #define FN_INTEGER(EGO_FUNC, E_FUNC) \
147 static int \
148 EGO_FUNC (lua_State *L) \
150 luaobj_Object *obj = lua_touserdata (L, 1); \
151 E_FUNC (obj->data, luaL_checkint (L, 2)); \
152 return 0; \
155 #define FN_STRING(EGO_FUNC, E_FUNC) \
156 static int \
157 EGO_FUNC (lua_State *L) \
159 luaobj_Object *obj = lua_touserdata (L, 1); \
160 E_FUNC (obj->data, luaL_checkstring (L, 2)); \
161 return 0; \
164 #define FN_2STRING(EGO_FUNC, E_FUNC) \
165 static int \
166 EGO_FUNC (lua_State *L) \
168 luaobj_Object *obj = lua_touserdata (L, 1); \
169 E_FUNC ( \
170 obj->data, \
171 luaL_checkstring (L, 2), \
172 luaL_checkstring (L, 3)); \
173 return 0; \
176 #define FN_OBJ(EGO_FUNC, E_FUNC) \
177 static int \
178 EGO_FUNC (lua_State *L) \
180 luaobj_Object *obj = lua_touserdata (L, 1); \
181 luaobj_Object *tar = lua_touserdata (L, 2); \
182 E_FUNC (obj->data, tar->data); \
183 return 0; \
186 #define FN_2OBJ(EGO_FUNC, E_FUNC) \
187 static int \
188 EGO_FUNC (lua_State *L) \
190 luaobj_Object *obj = lua_touserdata (L, 1); \
191 luaobj_Object *tar1 = lua_touserdata (L, 2); \
192 luaobj_Object *tar2 = lua_touserdata (L, 3); \
193 E_FUNC (obj->data, tar1->data, tar2->data); \
194 return 0; \
198 * tab2bool macros
201 #define GET_TAB2BOOL(EGO_FUNC, E_FUNC) \
202 static int \
203 EGO_FUNC (lua_State *L) \
205 luaobj_Object *obj = lua_touserdata (L, 1); \
206 int p1, p2; \
207 E_FUNC (obj->data, &p1, &p2); \
208 lua_newtable (L); \
209 lua_pushboolean (L, p1); lua_rawseti (L, -2, 1); \
210 lua_pushboolean (L, p2); lua_rawseti (L, -2, 2); \
211 return 1; \
214 #define SET_TAB2BOOL(EGO_FUNC, E_FUNC) \
215 static int \
216 EGO_FUNC (lua_State *L) \
218 luaobj_Object *obj = lua_touserdata (L, 1); \
219 lua_rawgeti (L, 2, 1); \
220 lua_rawgeti (L, 2, 2); \
221 E_FUNC ( \
222 obj->data, \
223 lua_toboolean (L, -2),\
224 lua_toboolean (L, -1)); \
225 return 0; \
229 * tab2integer macros
232 #define GET_TAB2INTEGER(EGO_FUNC, E_FUNC) \
233 static int \
234 EGO_FUNC (lua_State *L) \
236 luaobj_Object *obj = lua_touserdata (L, 1); \
237 int p1, p2; \
238 E_FUNC (obj->data, &p1, &p2); \
239 lua_newtable (L); \
240 lua_pushnumber (L, p1); lua_rawseti (L, -2, 1); \
241 lua_pushnumber (L, p2); lua_rawseti (L, -2, 2); \
242 return 1; \
245 #define SET_TAB2INTEGER(EGO_FUNC, E_FUNC) \
246 static int \
247 EGO_FUNC (lua_State *L) \
249 luaobj_Object *obj = lua_touserdata (L, 1); \
250 lua_rawgeti (L, 2, 1); \
251 lua_rawgeti (L, 2, 2); \
252 E_FUNC ( \
253 obj->data, \
254 luaL_checkinteger (L, -2),\
255 luaL_checkinteger (L, -1)); \
256 return 0; \
260 * tab2float macros
263 #define GET_TAB2FLOAT(EGO_FUNC, E_FUNC) \
264 static int \
265 EGO_FUNC (lua_State *L) \
267 luaobj_Object *obj = lua_touserdata (L, 1); \
268 double p1, p2; \
269 E_FUNC (obj->data, &p1, &p2); \
270 lua_newtable (L); \
271 lua_pushnumber (L, p1); lua_rawseti (L, -2, 1); \
272 lua_pushnumber (L, p2); lua_rawseti (L, -2, 2); \
273 return 1; \
276 #define SET_TAB2FLOAT(EGO_FUNC, E_FUNC) \
277 static int \
278 EGO_FUNC (lua_State *L) \
280 luaobj_Object *obj = lua_touserdata (L, 1); \
281 lua_rawgeti (L, 2, 1); \
282 lua_rawgeti (L, 2, 2); \
283 E_FUNC ( \
284 obj->data, \
285 luaL_checknumber (L, -2),\
286 luaL_checknumber (L, -1)); \
287 return 0; \
291 * tab2string macros
294 #define GET_TAB2STRING(EGO_FUNC, E_FUNC) \
295 static int \
296 EGO_FUNC (lua_State *L) \
298 luaobj_Object *obj = lua_touserdata (L, 1); \
299 double p1, p2; \
300 E_FUNC (obj->data, &p1, &p2); \
301 lua_newtable (L); \
302 lua_pushstring (L, p1); lua_rawseti (L, -2, 1); \
303 lua_pushstring (L, p2); lua_rawseti (L, -2, 2); \
304 return 1; \
307 #define SET_TAB2STRING(EGO_FUNC, E_FUNC) \
308 static int \
309 EGO_FUNC (lua_State *L) \
311 luaobj_Object *obj = lua_touserdata (L, 1); \
312 lua_rawgeti (L, 2, 1); \
313 lua_rawgeti (L, 2, 2); \
314 E_FUNC ( \
315 obj->data, \
316 luaL_checkstring (L, -2),\
317 luaL_checkstring (L, -1)); \
318 return 0; \
322 * tab3integer macros
325 #define GET_TAB3INTEGER(EGO_FUNC, E_FUNC) \
326 static int \
327 EGO_FUNC (lua_State *L) \
329 luaobj_Object *obj = lua_touserdata (L, 1); \
330 int p1, p2, p3; \
331 E_FUNC (obj->data, &p1, &p2, &p3); \
332 lua_newtable (L); \
333 lua_pushnumber (L, p1); lua_rawseti (L, -2, 1); \
334 lua_pushnumber (L, p2); lua_rawseti (L, -2, 2); \
335 lua_pushnumber (L, p3); lua_rawseti (L, -2, 3); \
336 return 1; \
339 #define SET_TAB3INTEGER(EGO_FUNC, E_FUNC) \
340 static int \
341 EGO_FUNC (lua_State *L) \
343 luaobj_Object *obj = lua_touserdata (L, 1); \
344 lua_rawgeti (L, 2, 1); \
345 lua_rawgeti (L, 2, 2); \
346 lua_rawgeti (L, 2, 3); \
347 E_FUNC ( \
348 obj->data, \
349 luaL_checkinteger (L, -3),\
350 luaL_checkinteger (L, -2),\
351 luaL_checkinteger (L, -1)); \
352 return 0; \
356 * tab4integer macros
359 #define GET_TAB4INTEGER(EGO_FUNC, E_FUNC) \
360 static int \
361 EGO_FUNC (lua_State *L) \
363 luaobj_Object *obj = lua_touserdata (L, 1); \
364 int p1, p2, p3, p4; \
365 E_FUNC (obj->data, &p1, &p2, &p3, &p4); \
366 lua_newtable (L); \
367 lua_pushnumber (L, p1); lua_rawseti (L, -2, 1); \
368 lua_pushnumber (L, p2); lua_rawseti (L, -2, 2); \
369 lua_pushnumber (L, p3); lua_rawseti (L, -2, 3); \
370 lua_pushnumber (L, p4); lua_rawseti (L, -2, 4); \
371 return 1; \
374 #define SET_TAB4INTEGER(EGO_FUNC, E_FUNC) \
375 static int \
376 EGO_FUNC (lua_State *L) \
378 luaobj_Object *obj = lua_touserdata (L, 1); \
379 lua_rawgeti (L, 2, 1); \
380 lua_rawgeti (L, 2, 2); \
381 lua_rawgeti (L, 2, 3); \
382 lua_rawgeti (L, 2, 4); \
383 E_FUNC ( \
384 obj->data, \
385 luaL_checkinteger (L, -4),\
386 luaL_checkinteger (L, -3),\
387 luaL_checkinteger (L, -2),\
388 luaL_checkinteger (L, -1)); \
389 return 0; \
393 * tab4float macros
396 #define GET_TAB4FLOAT(EGO_FUNC, E_FUNC) \
397 static int \
398 EGO_FUNC (lua_State *L) \
400 luaobj_Object *obj = lua_touserdata (L, 1); \
401 double p1, p2, p3, p4; \
402 E_FUNC (obj->data, &p1, &p2, &p3, &p4); \
403 lua_newtable (L); \
404 lua_pushnumber (L, p1); lua_rawseti (L, -2, 1); \
405 lua_pushnumber (L, p2); lua_rawseti (L, -2, 2); \
406 lua_pushnumber (L, p3); lua_rawseti (L, -2, 3); \
407 lua_pushnumber (L, p4); lua_rawseti (L, -2, 4); \
408 return 1; \
411 #define SET_TAB4FLOAT(EGO_FUNC, E_FUNC) \
412 static int \
413 EGO_FUNC (lua_State *L) \
415 luaobj_Object *obj = lua_touserdata (L, 1); \
416 lua_rawgeti (L, 2, 1); \
417 lua_rawgeti (L, 2, 2); \
418 lua_rawgeti (L, 2, 3); \
419 lua_rawgeti (L, 2, 4); \
420 E_FUNC ( \
421 obj->data, \
422 luaL_checknumber (L, -4),\
423 luaL_checknumber (L, -3),\
424 luaL_checknumber (L, -2),\
425 luaL_checknumber (L, -1)); \
426 return 0; \
429 #endif