added elementary layout, clock. prototyped plugin configuration
[ego.git] / src / lib / macro.h
blob5969ba689c4c4c9909b40740a4921141e35ccf69
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_STRING(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, luaL_checkstring (L, 2)); \
143 return 0; \
146 #define FN_2STRING(EGO_FUNC, E_FUNC) \
147 static int \
148 EGO_FUNC (lua_State *L) \
150 luaobj_Object *obj = lua_touserdata (L, 1); \
151 E_FUNC ( \
152 obj->data, \
153 luaL_checkstring (L, 2), \
154 luaL_checkstring (L, 3)); \
155 return 0; \
158 #define FN_OBJ(EGO_FUNC, E_FUNC) \
159 static int \
160 EGO_FUNC (lua_State *L) \
162 luaobj_Object *obj = lua_touserdata (L, 1); \
163 luaobj_Object *tar = lua_touserdata (L, 2); \
164 E_FUNC (obj->data, tar->data); \
165 return 0; \
168 #define FN_2OBJ(EGO_FUNC, E_FUNC) \
169 static int \
170 EGO_FUNC (lua_State *L) \
172 luaobj_Object *obj = lua_touserdata (L, 1); \
173 luaobj_Object *tar1 = lua_touserdata (L, 2); \
174 luaobj_Object *tar2 = lua_touserdata (L, 3); \
175 E_FUNC (obj->data, tar1->data, tar2->data); \
176 return 0; \
180 * tab2bool macros
183 #define GET_TAB2BOOL(EGO_FUNC, E_FUNC) \
184 static int \
185 EGO_FUNC (lua_State *L) \
187 luaobj_Object *obj = lua_touserdata (L, 1); \
188 int p1, p2; \
189 E_FUNC (obj->data, &p1, &p2); \
190 lua_newtable (L); \
191 lua_pushboolean (L, p1); lua_rawseti (L, -2, 1); \
192 lua_pushboolean (L, p2); lua_rawseti (L, -2, 2); \
193 return 1; \
196 #define SET_TAB2BOOL(EGO_FUNC, E_FUNC) \
197 static int \
198 EGO_FUNC (lua_State *L) \
200 luaobj_Object *obj = lua_touserdata (L, 1); \
201 lua_rawgeti (L, 2, 1); \
202 lua_rawgeti (L, 2, 2); \
203 E_FUNC ( \
204 obj->data, \
205 lua_toboolean (L, -2),\
206 lua_toboolean (L, -1)); \
207 return 0; \
211 * tab2integer macros
214 #define GET_TAB2INTEGER(EGO_FUNC, E_FUNC) \
215 static int \
216 EGO_FUNC (lua_State *L) \
218 luaobj_Object *obj = lua_touserdata (L, 1); \
219 int p1, p2; \
220 E_FUNC (obj->data, &p1, &p2); \
221 lua_newtable (L); \
222 lua_pushnumber (L, p1); lua_rawseti (L, -2, 1); \
223 lua_pushnumber (L, p2); lua_rawseti (L, -2, 2); \
224 return 1; \
227 #define SET_TAB2INTEGER(EGO_FUNC, E_FUNC) \
228 static int \
229 EGO_FUNC (lua_State *L) \
231 luaobj_Object *obj = lua_touserdata (L, 1); \
232 lua_rawgeti (L, 2, 1); \
233 lua_rawgeti (L, 2, 2); \
234 E_FUNC ( \
235 obj->data, \
236 luaL_checkinteger (L, -2),\
237 luaL_checkinteger (L, -1)); \
238 return 0; \
242 * tab2float macros
245 #define GET_TAB2FLOAT(EGO_FUNC, E_FUNC) \
246 static int \
247 EGO_FUNC (lua_State *L) \
249 luaobj_Object *obj = lua_touserdata (L, 1); \
250 double p1, p2; \
251 E_FUNC (obj->data, &p1, &p2); \
252 lua_newtable (L); \
253 lua_pushnumber (L, p1); lua_rawseti (L, -2, 1); \
254 lua_pushnumber (L, p2); lua_rawseti (L, -2, 2); \
255 return 1; \
258 #define SET_TAB2FLOAT(EGO_FUNC, E_FUNC) \
259 static int \
260 EGO_FUNC (lua_State *L) \
262 luaobj_Object *obj = lua_touserdata (L, 1); \
263 lua_rawgeti (L, 2, 1); \
264 lua_rawgeti (L, 2, 2); \
265 E_FUNC ( \
266 obj->data, \
267 luaL_checknumber (L, -2),\
268 luaL_checknumber (L, -1)); \
269 return 0; \
273 * tab2string macros
276 #define GET_TAB2STRING(EGO_FUNC, E_FUNC) \
277 static int \
278 EGO_FUNC (lua_State *L) \
280 luaobj_Object *obj = lua_touserdata (L, 1); \
281 double p1, p2; \
282 E_FUNC (obj->data, &p1, &p2); \
283 lua_newtable (L); \
284 lua_pushstring (L, p1); lua_rawseti (L, -2, 1); \
285 lua_pushstring (L, p2); lua_rawseti (L, -2, 2); \
286 return 1; \
289 #define SET_TAB2STRING(EGO_FUNC, E_FUNC) \
290 static int \
291 EGO_FUNC (lua_State *L) \
293 luaobj_Object *obj = lua_touserdata (L, 1); \
294 lua_rawgeti (L, 2, 1); \
295 lua_rawgeti (L, 2, 2); \
296 E_FUNC ( \
297 obj->data, \
298 luaL_checkstring (L, -2),\
299 luaL_checkstring (L, -1)); \
300 return 0; \
304 * tab3integer macros
307 #define GET_TAB3INTEGER(EGO_FUNC, E_FUNC) \
308 static int \
309 EGO_FUNC (lua_State *L) \
311 luaobj_Object *obj = lua_touserdata (L, 1); \
312 int p1, p2, p3; \
313 E_FUNC (obj->data, &p1, &p2, &p3); \
314 lua_newtable (L); \
315 lua_pushnumber (L, p1); lua_rawseti (L, -2, 1); \
316 lua_pushnumber (L, p2); lua_rawseti (L, -2, 2); \
317 lua_pushnumber (L, p3); lua_rawseti (L, -2, 3); \
318 return 1; \
321 #define SET_TAB3INTEGER(EGO_FUNC, E_FUNC) \
322 static int \
323 EGO_FUNC (lua_State *L) \
325 luaobj_Object *obj = lua_touserdata (L, 1); \
326 lua_rawgeti (L, 2, 1); \
327 lua_rawgeti (L, 2, 2); \
328 lua_rawgeti (L, 2, 3); \
329 E_FUNC ( \
330 obj->data, \
331 luaL_checkinteger (L, -3),\
332 luaL_checkinteger (L, -2),\
333 luaL_checkinteger (L, -1)); \
334 return 0; \
338 * tab4integer macros
341 #define GET_TAB4INTEGER(EGO_FUNC, E_FUNC) \
342 static int \
343 EGO_FUNC (lua_State *L) \
345 luaobj_Object *obj = lua_touserdata (L, 1); \
346 int p1, p2, p3, p4; \
347 E_FUNC (obj->data, &p1, &p2, &p3, &p4); \
348 lua_newtable (L); \
349 lua_pushnumber (L, p1); lua_rawseti (L, -2, 1); \
350 lua_pushnumber (L, p2); lua_rawseti (L, -2, 2); \
351 lua_pushnumber (L, p3); lua_rawseti (L, -2, 3); \
352 lua_pushnumber (L, p4); lua_rawseti (L, -2, 4); \
353 return 1; \
356 #define SET_TAB4INTEGER(EGO_FUNC, E_FUNC) \
357 static int \
358 EGO_FUNC (lua_State *L) \
360 luaobj_Object *obj = lua_touserdata (L, 1); \
361 lua_rawgeti (L, 2, 1); \
362 lua_rawgeti (L, 2, 2); \
363 lua_rawgeti (L, 2, 3); \
364 lua_rawgeti (L, 2, 4); \
365 E_FUNC ( \
366 obj->data, \
367 luaL_checkinteger (L, -4),\
368 luaL_checkinteger (L, -3),\
369 luaL_checkinteger (L, -2),\
370 luaL_checkinteger (L, -1)); \
371 return 0; \
375 * tab4float macros
378 #define GET_TAB4FLOAT(EGO_FUNC, E_FUNC) \
379 static int \
380 EGO_FUNC (lua_State *L) \
382 luaobj_Object *obj = lua_touserdata (L, 1); \
383 double p1, p2, p3, p4; \
384 E_FUNC (obj->data, &p1, &p2, &p3, &p4); \
385 lua_newtable (L); \
386 lua_pushnumber (L, p1); lua_rawseti (L, -2, 1); \
387 lua_pushnumber (L, p2); lua_rawseti (L, -2, 2); \
388 lua_pushnumber (L, p3); lua_rawseti (L, -2, 3); \
389 lua_pushnumber (L, p4); lua_rawseti (L, -2, 4); \
390 return 1; \
393 #define SET_TAB4FLOAT(EGO_FUNC, E_FUNC) \
394 static int \
395 EGO_FUNC (lua_State *L) \
397 luaobj_Object *obj = lua_touserdata (L, 1); \
398 lua_rawgeti (L, 2, 1); \
399 lua_rawgeti (L, 2, 2); \
400 lua_rawgeti (L, 2, 3); \
401 lua_rawgeti (L, 2, 4); \
402 E_FUNC ( \
403 obj->data, \
404 luaL_checknumber (L, -4),\
405 luaL_checknumber (L, -3),\
406 luaL_checknumber (L, -2),\
407 luaL_checknumber (L, -1)); \
408 return 0; \
411 #endif