diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/edje/src/lib/edje_lua2.c | 4129 |
1 files changed, 4129 insertions, 0 deletions
diff --git a/libraries/edje/src/lib/edje_lua2.c b/libraries/edje/src/lib/edje_lua2.c new file mode 100644 index 0000000..2318af9 --- /dev/null +++ b/libraries/edje/src/lib/edje_lua2.c | |||
@@ -0,0 +1,4129 @@ | |||
1 | // FIXME: Some error checking would be nice. | ||
2 | |||
3 | |||
4 | #include "edje_private.h" | ||
5 | #include <ctype.h> | ||
6 | |||
7 | #define RASTER_FORGOT_WHY "this is here." | ||
8 | |||
9 | #ifdef _WIN32 | ||
10 | # define FMT_SIZE_T "%Iu" | ||
11 | #else | ||
12 | # define FMT_SIZE_T "%zu" | ||
13 | #endif | ||
14 | |||
15 | //--------------------------------------------------------------------------// | ||
16 | #define MAX_LUA_MEM (4 * (1024 * 1024)) | ||
17 | #define ELO "|-ELO" | ||
18 | |||
19 | #define LC(...) EINA_LOG_DOM_CRIT(_log_domain, __VA_ARGS__) | ||
20 | #define LE(...) EINA_LOG_DOM_ERR(_log_domain, __VA_ARGS__) | ||
21 | #define LW(...) EINA_LOG_DOM_WARN(_log_domain, __VA_ARGS__) | ||
22 | #define LI(...) EINA_LOG_DOM_INFO(_log_domain, __VA_ARGS__) | ||
23 | #define LD(...) EINA_LOG_DOM_DBG(_log_domain, __VA_ARGS__) | ||
24 | |||
25 | /** | ||
26 | @page luaref Edje Lua scripting | ||
27 | |||
28 | @section intro Introduction | ||
29 | |||
30 | Lua is intended for script-only objects at this point (with embryo left | ||
31 | for augmenting standard programs). Since script-only objects effectively | ||
32 | define objects entirely via Lua script (resize handling, event handling | ||
33 | etc. etc.) this places many more demands on them, and thus a more powerful | ||
34 | language is in order. Lua is that language. | ||
35 | |||
36 | To get you started, here's an example that uses most of this lua API: | ||
37 | @ref lua_script.edc | ||
38 | |||
39 | Most of these lua functions are wrappers around various evas, ecore, and edje C | ||
40 | functions. Refer to their documentation for more in depth details and up to | ||
41 | date documentation. A lot of this documentation is simple copied from the C | ||
42 | functions it wraps. | ||
43 | |||
44 | @section args Lua function argument and return syntax | ||
45 | |||
46 | Some of the lua functions can accept a table as well as separate arguments. | ||
47 | Some of them return tables. | ||
48 | |||
49 | @section classes Lua classes | ||
50 | |||
51 | */ | ||
52 | |||
53 | /* | ||
54 | Lua functions stack usage. | ||
55 | |||
56 | In the definition of the lua functions provided, always mention the stack usage, | ||
57 | using the same notation that is used in the Lua 5.1 Reference Manual. | ||
58 | http://www.lua.org/manual/5.1/manual.html#3.7 describes that notation. | ||
59 | |||
60 | On the other hand, lua discards excess stack entries when control passes back to | ||
61 | it, but it's good to maintain proper discipline. | ||
62 | |||
63 | Should do the same for the support functions. These ARE more important to check. | ||
64 | */ | ||
65 | |||
66 | //--------------------------------------------------------------------------// | ||
67 | typedef struct _Edje_Lua_Alloc Edje_Lua_Alloc; | ||
68 | typedef struct _Edje_Lua_Obj Edje_Lua_Obj; | ||
69 | typedef struct _Edje_Lua_Animator Edje_Lua_Animator; | ||
70 | typedef struct _Edje_Lua_Timer Edje_Lua_Timer; | ||
71 | typedef struct _Edje_Lua_Transition Edje_Lua_Transition; | ||
72 | typedef struct _Edje_Lua_Evas_Object Edje_Lua_Evas_Object; | ||
73 | typedef struct _Edje_Lua_Map Edje_Lua_Map; | ||
74 | |||
75 | struct _Edje_Lua_Alloc | ||
76 | { | ||
77 | size_t max, cur; | ||
78 | }; | ||
79 | |||
80 | struct _Edje_Lua_Obj | ||
81 | { | ||
82 | EINA_INLIST; | ||
83 | |||
84 | Edje *ed; | ||
85 | void (*free_func) (void *obj); | ||
86 | const char *meta; | ||
87 | }; | ||
88 | |||
89 | struct _Edje_Lua_Animator | ||
90 | { | ||
91 | Edje_Lua_Obj obj; | ||
92 | Ecore_Animator *animator; | ||
93 | int fn_ref; | ||
94 | }; | ||
95 | |||
96 | struct _Edje_Lua_Timer | ||
97 | { | ||
98 | Edje_Lua_Obj obj; | ||
99 | Ecore_Timer *timer; | ||
100 | int fn_ref; | ||
101 | }; | ||
102 | |||
103 | struct _Edje_Lua_Transition | ||
104 | { | ||
105 | Edje_Lua_Obj obj; | ||
106 | Ecore_Animator *animator; | ||
107 | double transition, start; | ||
108 | int fn_ref; | ||
109 | }; | ||
110 | |||
111 | struct _Edje_Lua_Evas_Object | ||
112 | { | ||
113 | Edje_Lua_Obj obj; | ||
114 | Evas_Object *evas_obj; | ||
115 | int x, y; | ||
116 | }; | ||
117 | |||
118 | struct _Edje_Lua_Map | ||
119 | { | ||
120 | Edje_Lua_Obj obj; | ||
121 | Evas_Map *map; | ||
122 | }; | ||
123 | |||
124 | |||
125 | static void _elua_add_functions(lua_State *L, const char *api, const luaL_Reg *funcs, const char *meta, const char *parent, const char *base); | ||
126 | static Eina_Bool _elua_isa(Edje_Lua_Obj *obj, const char *type); | ||
127 | |||
128 | //--------------------------------------------------------------------------// | ||
129 | #ifndef RASTER_FORGOT_WHY | ||
130 | static lua_State *lstate = NULL; | ||
131 | #endif | ||
132 | static const char *_elua_key = "key"; | ||
133 | static const char *_elua_objs = "objs"; | ||
134 | /* This is not needed, pcalls don't longjmp(), that's why they are protected. | ||
135 | static jmp_buf panic_jmp; | ||
136 | */ | ||
137 | static int panics = 0; | ||
138 | static int _log_domain = -1; | ||
139 | static int _log_count = 0; | ||
140 | |||
141 | // FIXME: methods lua script can provide that edje will call (not done yet): | ||
142 | // // scale set | ||
143 | // // key down | ||
144 | // // key up | ||
145 | // // get dragable pos | ||
146 | // // set dragable pos | ||
147 | // // set drag size, step, page | ||
148 | // // get drag size, step, page | ||
149 | // // dragable step | ||
150 | // // dragable page | ||
151 | // // get part text | ||
152 | // // set part text | ||
153 | // // get swallow part | ||
154 | // // set swallow part | ||
155 | // // unswallow part | ||
156 | // // textclass change | ||
157 | // // colorclass change | ||
158 | // // min size get <- ?? maybe set fn | ||
159 | // // max size get <- ?? maybe set fn | ||
160 | // // min size caclc (min/max restriction) | ||
161 | // // preload | ||
162 | // // preload cancel | ||
163 | // // play set | ||
164 | // // animation set | ||
165 | // // parts extends calc | ||
166 | // // part object get | ||
167 | // // part geometry get | ||
168 | // | ||
169 | // // LATER: all the entry calls | ||
170 | // // LATER: box and table calls | ||
171 | // // LATER: perspective stuff change | ||
172 | // | ||
173 | |||
174 | // Grumble, pre-declare these. | ||
175 | static const char *_elua_edje_meta = "edje_meta"; | ||
176 | static const char *_elua_evas_meta = "evas_meta"; | ||
177 | static const char *_elua_evas_edje_meta = "evas_edje_meta"; | ||
178 | static const char *_elua_evas_image_meta = "evas_image_meta"; | ||
179 | static const char *_elua_evas_line_meta = "evas_line_meta"; | ||
180 | static const char *_elua_evas_map_meta = "evas_map_meta"; | ||
181 | static const char *_elua_evas_polygon_meta = "evas_polygon_meta"; | ||
182 | static const char *_elua_evas_text_meta = "evas_text_meta"; | ||
183 | static const char *_elua_ecore_animator_meta = "ecore_animator_meta"; | ||
184 | static const char *_elua_ecore_timer_meta = "ecore_timer_meta"; | ||
185 | |||
186 | static int _elua_obj_gc(lua_State *L); | ||
187 | |||
188 | static const struct luaL_reg _elua_edje_gc_funcs [] = | ||
189 | { | ||
190 | {"__gc", _elua_obj_gc}, // garbage collector func for edje objects | ||
191 | |||
192 | {NULL, NULL} // end | ||
193 | }; | ||
194 | |||
195 | static const luaL_Reg _elua_libs[] = | ||
196 | { | ||
197 | {"", luaopen_base}, | ||
198 | // {LUA_LOADLIBNAME, luaopen_package}, // disable this lib - don't want | ||
199 | {LUA_TABLIBNAME, luaopen_table}, | ||
200 | // {LUA_IOLIBNAME, luaopen_io}, // disable this lib - don't want | ||
201 | // {LUA_OSLIBNAME, luaopen_os}, // FIXME: audit os lib - maybe not provide or only provide specific calls | ||
202 | {LUA_STRLIBNAME, luaopen_string}, | ||
203 | {LUA_MATHLIBNAME, luaopen_math}, | ||
204 | // {LUA_DBLIBNAME, luaopen_debug}, // disable this lib - don't want | ||
205 | |||
206 | {NULL, NULL} // end | ||
207 | }; | ||
208 | |||
209 | //--------------------------------------------------------------------------// | ||
210 | static void * | ||
211 | _elua_alloc(void *ud, void *ptr, size_t osize, size_t nsize) | ||
212 | { | ||
213 | Edje_Lua_Alloc *ela = ud; | ||
214 | void *ptr2; | ||
215 | |||
216 | ela->cur += nsize - osize; | ||
217 | if (ela->cur > ela->max) | ||
218 | { | ||
219 | ERR("Lua memory limit of " FMT_SIZE_T " bytes reached (" FMT_SIZE_T " allocated)", | ||
220 | ela->max, ela->cur); | ||
221 | return NULL; | ||
222 | } | ||
223 | if (nsize == 0) | ||
224 | { | ||
225 | free(ptr); | ||
226 | return NULL; | ||
227 | } | ||
228 | |||
229 | ptr2 = realloc(ptr, nsize); | ||
230 | if (ptr2) return ptr2; | ||
231 | ERR("Lua cannot re-allocate " FMT_SIZE_T " bytes", nsize); | ||
232 | return ptr2; | ||
233 | } | ||
234 | |||
235 | static int | ||
236 | _elua_custom_panic(lua_State *L) // Stack usage [-0, +0, m] | ||
237 | { | ||
238 | // If we somehow manage to have multiple panics, it's likely due to being out | ||
239 | // of memory in the following lua_tostring() call. | ||
240 | panics++; | ||
241 | if (panics) | ||
242 | { | ||
243 | EINA_LOG_DOM_CRIT(_edje_default_log_dom, "Lua PANICS!!!!!"); | ||
244 | } | ||
245 | else | ||
246 | { | ||
247 | EINA_LOG_DOM_CRIT(_edje_default_log_dom, | ||
248 | "Lua PANIC!!!!!: %s", lua_tostring(L, -1)); // Stack usage [-0, +0, m] | ||
249 | } | ||
250 | // The docs say that this will cause an exit(EXIT_FAILURE) if we return, | ||
251 | // and that we we should long jump some where to avoid that. This is only | ||
252 | // called for things not called from a protected environment. We always | ||
253 | // use pcalls though, except for the library load calls. If we can't load | ||
254 | // the standard libraries, then perhaps a crash is the right thing. | ||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | // Really only used to manage the pointer to our edje. | ||
259 | static void | ||
260 | _elua_table_ptr_set(lua_State *L, const void *key, const void *val) // Stack usage [-2, +2, e] | ||
261 | { | ||
262 | lua_pushlightuserdata(L, (void *)key); // Stack usage [-0, +1, -] | ||
263 | lua_pushlightuserdata(L, (void *)val); // Stack usage [-0, +1, -] | ||
264 | lua_settable(L, LUA_REGISTRYINDEX); // Stack usage [-2, +0, e] | ||
265 | } | ||
266 | |||
267 | static const void * | ||
268 | _elua_table_ptr_get(lua_State *L, const void *key) // Stack usage [-2, +2, e] | ||
269 | { | ||
270 | const void *ptr; | ||
271 | lua_pushlightuserdata(L, (void *)key); // Stack usage [-0, +1, -] | ||
272 | lua_gettable(L, LUA_REGISTRYINDEX); // Stack usage [-1, +1, e] | ||
273 | ptr = lua_topointer(L, -1); // Stack usage [-0, +0, -] | ||
274 | lua_pop(L, 1); // Stack usage [-n, +0, -] | ||
275 | return ptr; | ||
276 | } | ||
277 | |||
278 | /* XXX: not used | ||
279 | static void | ||
280 | _elua_table_ptr_del(lua_State *L, const void *key) // Stack usage [-2, +2, e] | ||
281 | { | ||
282 | lua_pushlightuserdata(L, (void *)key); // Stack usage [-0, +1, -] | ||
283 | lua_pushnil(L); // Stack usage [-0, +1, -] | ||
284 | lua_settable(L, LUA_REGISTRYINDEX); // Stack usage [-2, +0, e] | ||
285 | } | ||
286 | */ | ||
287 | |||
288 | /* | ||
289 | * Cori: Assumes object to be saved on top of stack | ||
290 | */ | ||
291 | static void | ||
292 | _elua_ref_set(lua_State *L, void *key) // Stack usage [-4, +4, m] | ||
293 | { | ||
294 | lua_pushlightuserdata(L, &_elua_objs); // Stack usage [-0, +1, -] | ||
295 | lua_rawget(L, LUA_REGISTRYINDEX); // Stack usage [-1, +1, -] | ||
296 | lua_pushlightuserdata(L, key); // Stack usage [-0, +1, -] | ||
297 | lua_pushvalue(L,-3); // Stack usage [-0, +1, -] | ||
298 | lua_rawset(L, -3); // Stack usage [-2, +0, m] | ||
299 | lua_pop(L, 1); // Stack usage [-n, +0, -] | ||
300 | } | ||
301 | |||
302 | /* | ||
303 | * Cori: Get an object from the object table | ||
304 | */ | ||
305 | static void * | ||
306 | _elua_ref_get(lua_State *L, void *key) // Stack usage [-3, +4, -] | ||
307 | { | ||
308 | lua_pushlightuserdata(L, &_elua_objs); // Stack usage [-0, +1, -] | ||
309 | lua_rawget(L, LUA_REGISTRYINDEX); // Stack usage [-1, +1, -] | ||
310 | lua_pushlightuserdata(L, key); // Stack usage [-0, +1, -] | ||
311 | lua_rawget(L, -2); // Stack usage [-1, +1, -] | ||
312 | lua_remove(L, -2); // Stack usage [-1, +0, -] | ||
313 | return lua_touserdata(L, -2); // Stack usage [-0, +0, -] | ||
314 | } | ||
315 | |||
316 | static Edje_Lua_Obj * | ||
317 | _elua_obj_new(lua_State *L, Edje *ed, int size, const char *metatable) // Stack usage [-5, +6, m] | ||
318 | { | ||
319 | Edje_Lua_Obj *obj; | ||
320 | |||
321 | obj = (Edje_Lua_Obj *)lua_newuserdata(L, size); // Stack usage [-0, +1, m] | ||
322 | memset(obj, 0, size); | ||
323 | ed->lua_objs = eina_inlist_append(ed->lua_objs, EINA_INLIST_GET(obj)); | ||
324 | |||
325 | luaL_getmetatable(L, metatable); // Stack usage [-0, +1, -] | ||
326 | lua_setmetatable(L, -2); // Stack usage [-1, +0, -] | ||
327 | obj->ed = ed; | ||
328 | obj->meta = metatable; | ||
329 | |||
330 | _elua_ref_set(L, obj); // Stack usage [-4, +4, m] | ||
331 | return obj; | ||
332 | } | ||
333 | |||
334 | static void | ||
335 | _elua_obj_free(lua_State *L __UNUSED__, Edje_Lua_Obj *obj) | ||
336 | { | ||
337 | if (!obj->free_func) return; | ||
338 | obj->free_func(obj); | ||
339 | obj->ed->lua_objs = eina_inlist_remove(obj->ed->lua_objs, EINA_INLIST_GET(obj)); | ||
340 | obj->free_func = NULL; | ||
341 | obj->ed = NULL; | ||
342 | } | ||
343 | |||
344 | static int | ||
345 | _elua_obj_gc(lua_State *L) // Stack usage [-0, +0, -] | ||
346 | { | ||
347 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
348 | if (!obj) return 0; | ||
349 | _elua_obj_free(L, obj); | ||
350 | return 0; | ||
351 | } | ||
352 | |||
353 | static int | ||
354 | _elua_obj_del(lua_State *L) // Stack usage [-0, +0, -] | ||
355 | { | ||
356 | return _elua_obj_gc(L); // Stack usage [-0, +0, -] | ||
357 | } | ||
358 | |||
359 | static void | ||
360 | _elua_gc(lua_State *L) // Stack usage [-0, +0, e] | ||
361 | { | ||
362 | lua_gc(L, LUA_GCCOLLECT, 0); // Stack usage [-0, +0, e] | ||
363 | } | ||
364 | |||
365 | // These are what the various symbols are for each type - | ||
366 | // int % | ||
367 | // num # | ||
368 | // str $ | ||
369 | // bool ! | ||
370 | // FIXME: Still to do, if we ever use them - | ||
371 | // func & | ||
372 | // userdata + | ||
373 | // lightuserdata * | ||
374 | // table @ | ||
375 | // thread ^ | ||
376 | // nil ~ | ||
377 | |||
378 | static char * | ||
379 | _elua_push_name(lua_State *L, char *q, int index) // Stack usage [-0, +1, e or m] | ||
380 | { | ||
381 | char *p = q; | ||
382 | char temp = '\0'; | ||
383 | |||
384 | // A simplistic scan through an identifier, it's wrong, but it's quick, | ||
385 | // and we don't mind that it's wrong, coz this is only internal. | ||
386 | while (isalnum((int)*q)) | ||
387 | q++; | ||
388 | temp = *q; | ||
389 | *q = '\0'; | ||
390 | if (index > 0) | ||
391 | lua_getfield(L, index, p); // Stack usage [-0, +1, e] | ||
392 | else | ||
393 | lua_pushstring(L, p); // Stack usage [-0, +1, m] | ||
394 | *q = temp; | ||
395 | |||
396 | return q; | ||
397 | } | ||
398 | |||
399 | static int | ||
400 | _elua_scan_params(lua_State *L, int i, char *params, ...) // Stack usage - | ||
401 | // if i is a table | ||
402 | // [-n, +n, e] | ||
403 | // else | ||
404 | // [-0, +0, -] | ||
405 | { | ||
406 | va_list vl; | ||
407 | char *f = strdup(params); | ||
408 | char *p = f; | ||
409 | int n = 0, j = i, count = 0; | ||
410 | Eina_Bool table = EINA_FALSE; | ||
411 | |||
412 | if (!f) return -1; | ||
413 | va_start(vl, params); | ||
414 | |||
415 | if (lua_istable(L, i)) // Stack usage [-0, +0, -] | ||
416 | { | ||
417 | j = -1; | ||
418 | table = EINA_TRUE; | ||
419 | } | ||
420 | |||
421 | while (*p) | ||
422 | { | ||
423 | char *q; | ||
424 | Eina_Bool get = EINA_TRUE; | ||
425 | |||
426 | while (isspace((int)*p)) | ||
427 | p++; | ||
428 | q = p + 1; | ||
429 | switch (*p) | ||
430 | { | ||
431 | case '%': | ||
432 | { | ||
433 | if (table) | ||
434 | { | ||
435 | q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e] | ||
436 | } | ||
437 | if (lua_isnumber(L, j)) // Stack usage [-0, +0, -] | ||
438 | { | ||
439 | int *v = va_arg(vl, int *); | ||
440 | *v = lua_tointeger(L, j); // Stack usage [-0, +0, -] | ||
441 | n++; | ||
442 | } | ||
443 | break; | ||
444 | } | ||
445 | case '#': | ||
446 | { | ||
447 | if (table) | ||
448 | { | ||
449 | q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e] | ||
450 | } | ||
451 | if (lua_isnumber(L, j)) // Stack usage [-0, +0, -] | ||
452 | { | ||
453 | double *v = va_arg(vl, double *); | ||
454 | *v = lua_tonumber(L, j); // Stack usage [-0, +0, -] | ||
455 | n++; | ||
456 | } | ||
457 | break; | ||
458 | } | ||
459 | case '$': | ||
460 | { | ||
461 | if (table) | ||
462 | { | ||
463 | q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e] | ||
464 | } | ||
465 | if (lua_isstring(L, j)) // Stack usage [-0, +0, -] | ||
466 | { | ||
467 | char **v = va_arg(vl, char **); | ||
468 | size_t len; | ||
469 | char *temp = (char *) lua_tolstring(L, j, &len); // Stack usage [-0, +0, m] | ||
470 | |||
471 | len++; // Cater for the null at the end. | ||
472 | *v = malloc(len); | ||
473 | if (*v) | ||
474 | { | ||
475 | memcpy(*v, temp, len); | ||
476 | n++; | ||
477 | } | ||
478 | } | ||
479 | break; | ||
480 | } | ||
481 | case '!': | ||
482 | { | ||
483 | if (table) | ||
484 | { | ||
485 | q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e] | ||
486 | } | ||
487 | if (lua_isboolean(L, j)) // Stack usage [-0, +0, -] | ||
488 | { | ||
489 | int *v = va_arg(vl, int *); | ||
490 | *v = lua_toboolean(L, j); // Stack usage [-0, +0, -] | ||
491 | n++; | ||
492 | } | ||
493 | break; | ||
494 | } | ||
495 | default: | ||
496 | { | ||
497 | get = EINA_FALSE; | ||
498 | break; | ||
499 | } | ||
500 | } | ||
501 | |||
502 | if (get) | ||
503 | { | ||
504 | if (table) | ||
505 | { | ||
506 | // If this is a table, then we pushed a value on the stack, pop it off. | ||
507 | lua_pop(L, 1); // Stack usage [-n, +0, -] | ||
508 | } | ||
509 | else | ||
510 | j++; | ||
511 | count++; | ||
512 | } | ||
513 | p = q; | ||
514 | } | ||
515 | |||
516 | free(f); | ||
517 | va_end(vl); | ||
518 | if (count > n) | ||
519 | n = 0; | ||
520 | else if (table) | ||
521 | n = 1; | ||
522 | return n; | ||
523 | } | ||
524 | |||
525 | static int | ||
526 | _elua_ret(lua_State *L, char *params, ...) // Stack usage [-(2*n), +(2*n+1), em] | ||
527 | { | ||
528 | va_list vl; | ||
529 | char *f = strdup(params); | ||
530 | char *p = f; | ||
531 | int n = 0; | ||
532 | |||
533 | if (!f) return -1; | ||
534 | |||
535 | lua_newtable(L); // Stack usage [-0, +1, m] | ||
536 | va_start(vl, params); | ||
537 | |||
538 | while (*p) | ||
539 | { | ||
540 | char *q; | ||
541 | Eina_Bool set = EINA_TRUE; | ||
542 | |||
543 | while (isspace((int)*p)) | ||
544 | p++; | ||
545 | q = p + 1; | ||
546 | switch (*p) | ||
547 | { | ||
548 | case '%': | ||
549 | { | ||
550 | q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m] | ||
551 | lua_pushinteger(L, va_arg(vl, int)); // Stack usage [-0, +1, -] | ||
552 | break; | ||
553 | } | ||
554 | case '#': | ||
555 | { | ||
556 | q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m] | ||
557 | lua_pushnumber(L, va_arg(vl, double)); // Stack usage [-0, +1, -] | ||
558 | break; | ||
559 | } | ||
560 | case '$': | ||
561 | { | ||
562 | q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m] | ||
563 | lua_pushstring(L, va_arg(vl, char *)); // Stack usage [-0, +1, m] | ||
564 | break; | ||
565 | } | ||
566 | case '!': | ||
567 | { | ||
568 | q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m] | ||
569 | lua_pushboolean(L, va_arg(vl, int)); // Stack usage [-0, +1, -] | ||
570 | break; | ||
571 | } | ||
572 | default: | ||
573 | { | ||
574 | set = EINA_FALSE; | ||
575 | break; | ||
576 | } | ||
577 | } | ||
578 | |||
579 | if (set) | ||
580 | { | ||
581 | lua_settable(L, -3); // Stack usage [-2, +0, e] | ||
582 | n++; | ||
583 | } | ||
584 | p = q; | ||
585 | } | ||
586 | |||
587 | free(f); | ||
588 | va_end(vl); | ||
589 | return n; | ||
590 | } | ||
591 | |||
592 | static void | ||
593 | _elua_color_fix(int *r, int *g, int *b, int *a) | ||
594 | { | ||
595 | if (*r > *a) *r = *a; | ||
596 | if (*g > *a) *g = *a; | ||
597 | if (*b > *a) *b = *a; | ||
598 | } | ||
599 | |||
600 | //--------------------------------------------------------------------------// | ||
601 | |||
602 | /** | ||
603 | @page luaref | ||
604 | @subsection edje Edje class. | ||
605 | |||
606 | The lua edje class includes functions for dealing with the lua script only group | ||
607 | as an edje object, basic functions, and functions to create other objects. | ||
608 | |||
609 | In the following, "edje" is the actual global table used to access these edje functions. | ||
610 | */ | ||
611 | |||
612 | static int _elua_echo(lua_State *L); | ||
613 | |||
614 | static int _elua_date(lua_State *L); | ||
615 | static int _elua_looptime(lua_State *L); | ||
616 | static int _elua_seconds(lua_State *L); | ||
617 | |||
618 | static int _elua_objgeom(lua_State *L); | ||
619 | static int _elua_objpos(lua_State *L); | ||
620 | static int _elua_objsize(lua_State *L); | ||
621 | |||
622 | static int _elua_emit(lua_State *L); | ||
623 | static int _elua_messagesend(lua_State *L); | ||
624 | |||
625 | static int _elua_animator(lua_State *L); | ||
626 | static int _elua_timer(lua_State *L); | ||
627 | static int _elua_transition(lua_State *L); | ||
628 | |||
629 | static int _elua_color_class(lua_State *L); | ||
630 | static int _elua_text_class(lua_State *L); | ||
631 | |||
632 | static int _elua_edje(lua_State *L); | ||
633 | static int _elua_image(lua_State *L); | ||
634 | static int _elua_line(lua_State *L); | ||
635 | static int _elua_map(lua_State *L); | ||
636 | static int _elua_polygon(lua_State *L); | ||
637 | static int _elua_rect(lua_State *L); | ||
638 | static int _elua_text(lua_State *L); | ||
639 | //static int _elua_textblock(lua_State *L); /* XXX: disabled until there are enough textblock functions implemented to make it actually useful | ||
640 | |||
641 | static const char *_elua_edje_api = "edje"; | ||
642 | static const struct luaL_reg _elua_edje_funcs [] = | ||
643 | { | ||
644 | // add an echo too to make it more shelly | ||
645 | {"echo", _elua_echo}, // test func - echo (i know we have print. test) | ||
646 | // FIXME: add logging functions here, probably to it's own domain, or even a script defined domain. | ||
647 | |||
648 | // system information (time, date blah blah) | ||
649 | {"date", _elua_date}, // get date in a table | ||
650 | {"looptime", _elua_looptime}, // get loop time | ||
651 | {"seconds", _elua_seconds}, // get seconds | ||
652 | |||
653 | // query edje - size, pos | ||
654 | {"geom", _elua_objgeom}, // get while edje object geometry in canvas | ||
655 | {"pos", _elua_objpos}, // get while edje object pos in canvas | ||
656 | {"size", _elua_objsize}, // get while edje object pos in canvas | ||
657 | |||
658 | // talk to application/caller | ||
659 | {"emit", _elua_emit}, // emit signal + src | ||
660 | {"messagesend", _elua_messagesend}, // send a structured message | ||
661 | |||
662 | // time based "callback" systems | ||
663 | {"animator", _elua_animator}, // add animator | ||
664 | {"timer", _elua_timer}, // add timer | ||
665 | {"transition", _elua_transition}, // add transition | ||
666 | // FIXME: need poller | ||
667 | |||
668 | // set and query color / text class | ||
669 | {"color_class", _elua_color_class}, | ||
670 | {"text_class", _elua_text_class}, | ||
671 | |||
672 | // create new objects | ||
673 | {"edje", _elua_edje}, | ||
674 | {"image", _elua_image}, // defaults to a filled image. | ||
675 | {"line", _elua_line}, | ||
676 | {"map", _elua_map}, | ||
677 | {"polygon", _elua_polygon}, | ||
678 | {"rect", _elua_rect}, | ||
679 | {"text", _elua_text}, | ||
680 | // {"textblock", _elua_textblock}, /* XXX: disabled until there are enough textblock functions implemented to make it actually useful | ||
681 | |||
682 | // FIXME: add the new sound stuff. | ||
683 | |||
684 | {NULL, NULL} // end | ||
685 | }; | ||
686 | |||
687 | /** | ||
688 | @page luaref | ||
689 | @subsubsection edje_echo edje:echo(text) | ||
690 | |||
691 | Make lua a bit shelly. Prints a string to the console | ||
692 | |||
693 | @param text The string to print. | ||
694 | */ | ||
695 | static int | ||
696 | _elua_echo(lua_State *L) // Stack usage [-0, +0, v] | ||
697 | { | ||
698 | const char *string = luaL_checkstring(L, 1); // Stack usage [-0, +0, v] | ||
699 | LD("%s\n", string); | ||
700 | return 0; | ||
701 | } | ||
702 | |||
703 | //------------- | ||
704 | /** | ||
705 | @page luaref | ||
706 | @subsubsection edje_date edje:date() | ||
707 | |||
708 | Retrieves the current time and date. | ||
709 | |||
710 | Wraps gettimeofday(), as passed through localtime(). | ||
711 | |||
712 | @return A table with these fields: | ||
713 | - integer year: Year. | ||
714 | - integer month: Month of the year. | ||
715 | - integer day: Day of the month. | ||
716 | - integer yearday: Day of the year. | ||
717 | - integer weekday: Day of the week. | ||
718 | - integer hour: Hour of the day (24 hour format). | ||
719 | - integer min: Minute of the hour. | ||
720 | - number sec: Seconds as a number. | ||
721 | |||
722 | */ | ||
723 | static int | ||
724 | _elua_date(lua_State *L) // Stack usage [-16, +17, em] | ||
725 | { | ||
726 | static time_t last_tzset = 0; | ||
727 | struct timeval timev; | ||
728 | struct tm *tm; | ||
729 | time_t tt; | ||
730 | |||
731 | gettimeofday(&timev, NULL); | ||
732 | tt = (time_t)(timev.tv_sec); | ||
733 | if ((tt > (last_tzset + 1)) || (tt < (last_tzset - 1))) | ||
734 | { | ||
735 | last_tzset = tt; | ||
736 | tzset(); | ||
737 | } | ||
738 | tm = localtime(&tt); | ||
739 | if (tm) | ||
740 | { // Stack usage [-16, +17, em] | ||
741 | _elua_ret(L, "%year %month %day %yearday %weekday %hour %min #sec", | ||
742 | (int)(tm->tm_year + 1900), | ||
743 | (int)(tm->tm_mon + 1), | ||
744 | (int)(tm->tm_mday), | ||
745 | (int)(tm->tm_yday), | ||
746 | (int)((tm->tm_wday + 6) % 7), | ||
747 | (int)(tm->tm_hour), | ||
748 | (int)(tm->tm_min), | ||
749 | (double)((double)tm->tm_sec + (((double)timev.tv_usec) / 1000000)) | ||
750 | ); | ||
751 | |||
752 | |||
753 | } | ||
754 | return 1; | ||
755 | } | ||
756 | |||
757 | /** | ||
758 | @page luaref | ||
759 | @subsubsection edje_looptime edje:looptime() | ||
760 | |||
761 | Retrieves the time at which the last loop stopped waiting for timeouts or events. | ||
762 | |||
763 | This gets the time that the main loop ceased waiting for timouts and/or events | ||
764 | to come in or for signals or any other interrupt source. This should be | ||
765 | considered a reference point for all time based activity that should calculate | ||
766 | its timepoint from the return of edje:looptime(). Use this UNLESS you absolutely | ||
767 | must get the current actual timepoint - then use edje:seconds(). Note that this | ||
768 | time is meant to be used as relative to other times obtained on this run. | ||
769 | |||
770 | Wraps ecore_loop_time_get(). | ||
771 | |||
772 | @returns A number of seconds. | ||
773 | */ | ||
774 | static int | ||
775 | _elua_looptime(lua_State *L) // Stack usage [-0, +1, -] | ||
776 | { | ||
777 | double t = ecore_loop_time_get(); | ||
778 | lua_pushnumber(L, t); // Stack usage [-0, +1, -] | ||
779 | return 1; | ||
780 | } | ||
781 | |||
782 | /** | ||
783 | @page luaref | ||
784 | @subsubsection edje_seconds edje:seconds() | ||
785 | |||
786 | Retrieves the current system time as a floating point value in seconds. | ||
787 | |||
788 | This uses a monotonic clock and thus never goes back in time while machine is | ||
789 | live (even if user changes time or timezone changes, however it may be reset | ||
790 | whenever the machine is restarted). | ||
791 | |||
792 | Wraps ecore_time_get(). | ||
793 | |||
794 | @returns A number of seconds. | ||
795 | */ | ||
796 | static int | ||
797 | _elua_seconds(lua_State *L) // Stack usage [-0, +1, -] | ||
798 | { | ||
799 | double t = ecore_time_get(); | ||
800 | lua_pushnumber(L, t); // Stack usage [-0, +1, -] | ||
801 | return 1; | ||
802 | } | ||
803 | |||
804 | //------------- | ||
805 | /** | ||
806 | @page luaref | ||
807 | @subsubsection edje_geom edje:geom() | ||
808 | |||
809 | Retrieves the position and size of the edje object that this lua group is in. | ||
810 | |||
811 | @returns A table with these fields: | ||
812 | - integer x: The edjes X position. | ||
813 | - integer y: The edjes Y position. | ||
814 | - integer w: The edjes width. | ||
815 | - integer h: The edjes height. | ||
816 | */ | ||
817 | static int | ||
818 | _elua_objgeom(lua_State *L) // Stack usage [-10, +11, em] | ||
819 | { | ||
820 | Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e] | ||
821 | _elua_ret(L, "%x %y %w %h", ed->x, ed->y, ed->w, ed->h); // Stack usage [-8, +9, em] | ||
822 | return 1; | ||
823 | } | ||
824 | |||
825 | /** | ||
826 | @page luaref | ||
827 | @subsubsection edje_pos edje:pos() | ||
828 | |||
829 | |||
830 | Retrieves the position of the edje object that this lua group is in. | ||
831 | |||
832 | @returns A table with these fields: | ||
833 | - integer x: The edjes X position. | ||
834 | - integer y: The edjes Y position. | ||
835 | */ | ||
836 | static int | ||
837 | _elua_objpos(lua_State *L) // Stack usage [-6, +7, em] | ||
838 | { | ||
839 | Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e] | ||
840 | _elua_ret(L, "%x %y", ed->x, ed->y); // Stack usage [-4, +5, em] | ||
841 | return 1; | ||
842 | } | ||
843 | |||
844 | /** | ||
845 | @page luaref | ||
846 | @subsubsection edje_size edje:size() | ||
847 | |||
848 | |||
849 | Retrieves the size of the edje object that this lua group is in. | ||
850 | |||
851 | @returns A table with these fields: | ||
852 | - integer w: The edjes width. | ||
853 | - integer h: The edjes height. | ||
854 | */ | ||
855 | static int | ||
856 | _elua_objsize(lua_State *L) // Stack usage [-6, +7, em] | ||
857 | { | ||
858 | Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e] | ||
859 | _elua_ret(L, "%w %h", ed->w, ed->h); // Stack usage [-4, +5, em] | ||
860 | return 1; | ||
861 | } | ||
862 | |||
863 | //------------- | ||
864 | /** | ||
865 | @page luaref | ||
866 | @subsubsection edje_emit edje:emit(signal, source) | ||
867 | |||
868 | Emit a signal. | ||
869 | |||
870 | Wraps edje_object_signal_emit(). | ||
871 | |||
872 | @param signal The signal string to send. | ||
873 | @param source The source string of the signal. | ||
874 | |||
875 | NOTE: The source string will have a name and a colon prepended to in when it is | ||
876 | delivered to things that are not this edje, like C and other edje groups. | ||
877 | If this edje is a top level edje, then it will be the name of the group (I think). | ||
878 | If this edje is swallowed into some other part, then it will be the name of the | ||
879 | part: | ||
880 | |||
881 | group_name:source | ||
882 | |||
883 | FIXME: I actually have no idea what happens if it's swallowed into another lua | ||
884 | edje group. | ||
885 | */ | ||
886 | static int | ||
887 | _elua_emit(lua_State *L) // Stack usage [-2, +2, ev] | ||
888 | { | ||
889 | Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e] | ||
890 | const char *sig = luaL_checkstring(L, 1); // Stack usage [-0, +0, v] | ||
891 | const char *src = luaL_checkstring(L, 2); // Stack usage [-0, +0, v] | ||
892 | if ((!sig) || (!src)) return 0; | ||
893 | _edje_emit(ed, sig, src); | ||
894 | return 0; | ||
895 | } | ||
896 | |||
897 | /** | ||
898 | @page luaref | ||
899 | @subsubsection edje_message_send edje:messagesend(id, type, ...) | ||
900 | |||
901 | Send a message to this edje, and all it's child objects. | ||
902 | |||
903 | Wraps edje_object_message_send(). | ||
904 | |||
905 | @param id An identification integer for the message. | ||
906 | @param type The type of message to send. | ||
907 | @param ... Zero or more things to send as part of the message, depending on the type. | ||
908 | |||
909 | The type can be one of: | ||
910 | - none: No msg. | ||
911 | - sig: The msg is two strings (signal, source), sent as a signal. | ||
912 | - str: The msg is a C string. | ||
913 | - int: The message is a C integer. | ||
914 | - float: The message is a C float. | ||
915 | - strset: The message is an array of C strings. | ||
916 | - intset: The message is an array of C integers. | ||
917 | - floatset: The message is an array of C floats. | ||
918 | - strint: The message is a C stnring and a C integer. | ||
919 | - strfloat: The message is a C string and a C float. | ||
920 | - strintset: The message is a C string and an array of C integers. | ||
921 | - strfloatset: The message is a G string and an array of C floats. | ||
922 | |||
923 | For the array types, the lua caller passes a table. | ||
924 | */ | ||
925 | static int | ||
926 | _elua_messagesend(lua_State *L) // Stack usage [-2, +2, ev] plus [-2, +2] for every element if it's an array message. | ||
927 | { | ||
928 | Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e] | ||
929 | int id = luaL_checkinteger(L, 1); // Stack usage [-0, +0, v] | ||
930 | const char *type = luaL_checkstring(L, 2); // Stack usage [-0, +0, v] | ||
931 | if (!type) return 0; | ||
932 | if (!strcmp(type, "none")) | ||
933 | { | ||
934 | _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_NONE, id, NULL); | ||
935 | } | ||
936 | else if (!strcmp(type, "sig")) | ||
937 | { | ||
938 | const char *sig = luaL_checkstring(L, 3); // Stack usage [-0, +0, v] | ||
939 | const char *src = luaL_checkstring(L, 4); // Stack usage [-0, +0, v] | ||
940 | _edje_emit(ed, sig, src); | ||
941 | } | ||
942 | else if (!strcmp(type, "str")) | ||
943 | { | ||
944 | Edje_Message_String *emsg; | ||
945 | const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v] | ||
946 | emsg = alloca(sizeof(Edje_Message_String)); | ||
947 | emsg->str = (char *)str; | ||
948 | _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING, id, emsg); | ||
949 | } | ||
950 | else if (!strcmp(type, "int")) | ||
951 | { | ||
952 | Edje_Message_Int *emsg; | ||
953 | int val = luaL_checkinteger(L, 3); // Stack usage [-0, +0, v] | ||
954 | emsg = alloca(sizeof(Edje_Message_Int)); | ||
955 | emsg->val = val; | ||
956 | _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_INT, id, emsg); | ||
957 | } | ||
958 | else if (!strcmp(type, "float")) | ||
959 | { | ||
960 | Edje_Message_Float *emsg; | ||
961 | float val = luaL_checknumber(L, 3); // Stack usage [-0, +0, v] | ||
962 | emsg = alloca(sizeof(Edje_Message_Float)); | ||
963 | emsg->val = val; | ||
964 | _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_FLOAT, id, emsg); | ||
965 | } | ||
966 | else if (!strcmp(type, "strset")) | ||
967 | { | ||
968 | Edje_Message_String_Set *emsg; | ||
969 | int i, n; | ||
970 | const char *str; | ||
971 | luaL_checktype(L, 3, LUA_TTABLE); // Stack usage [-0, +0, v] | ||
972 | n = lua_objlen(L, 3); // Stack usage [-0, +0, -] | ||
973 | emsg = alloca(sizeof(Edje_Message_String_Set) + ((n - 1) * sizeof(char *))); | ||
974 | emsg->count = n; | ||
975 | for (i = 1; i <= n; i ++) | ||
976 | { | ||
977 | lua_pushinteger(L, i); // Stack usage [-0, +1, -] | ||
978 | lua_gettable(L, 3); // Stack usage [-1, +1, e] | ||
979 | str = lua_tostring(L, -1); // Stack usage [-0, +0, m] | ||
980 | lua_pop(L, 1); // Stack usage [-n, +0, -] | ||
981 | emsg->str[i - 1] = (char *)str; | ||
982 | } | ||
983 | _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_SET, id, emsg); | ||
984 | } | ||
985 | else if (!strcmp(type, "intset")) | ||
986 | { | ||
987 | Edje_Message_Int_Set *emsg; | ||
988 | int i, n; | ||
989 | luaL_checktype(L, 3, LUA_TTABLE); // Stack usage [-0, +0, v] | ||
990 | n = lua_objlen(L, 3); // Stack usage [-0, +0, -] | ||
991 | emsg = alloca(sizeof(Edje_Message_Int_Set) + ((n - 1) * sizeof(int))); | ||
992 | emsg->count = n; | ||
993 | for (i = 1; i <= n; i ++) | ||
994 | { | ||
995 | lua_pushinteger(L, i); // Stack usage [-0, +1, -] | ||
996 | lua_gettable(L, 3); // Stack usage [-1, +1, e] | ||
997 | emsg->val[i - 1] = lua_tointeger(L, -1); // Stack usage [-0, +0, -] | ||
998 | lua_pop(L, 1); // Stack usage [-n, +0, -] | ||
999 | } | ||
1000 | _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_INT_SET, id, emsg); | ||
1001 | } | ||
1002 | else if (!strcmp(type, "floatset")) | ||
1003 | { | ||
1004 | Edje_Message_Float_Set *emsg; | ||
1005 | int i, n; | ||
1006 | luaL_checktype(L, 3, LUA_TTABLE); // Stack usage [-0, +0, v] | ||
1007 | n = lua_objlen(L, 3); // Stack usage [-0, +0, -] | ||
1008 | emsg = alloca(sizeof(Edje_Message_Float_Set) + ((n - 1) * sizeof(double))); | ||
1009 | emsg->count = n; | ||
1010 | for (i = 1; i <= n; i ++) | ||
1011 | { | ||
1012 | lua_pushinteger(L, i); // Stack usage [-0, +1, -] | ||
1013 | lua_gettable(L, 3); // Stack usage [-1, +1, e] | ||
1014 | emsg->val[i - 1] = lua_tonumber(L, -1); // Stack usage [-0, +0, -] | ||
1015 | lua_pop(L, 1); // Stack usage [-n, +0, -] | ||
1016 | } | ||
1017 | _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_FLOAT_SET, id, emsg); | ||
1018 | } | ||
1019 | else if (!strcmp(type, "strint")) | ||
1020 | { | ||
1021 | Edje_Message_String_Int *emsg; | ||
1022 | const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v] | ||
1023 | emsg = alloca(sizeof(Edje_Message_String_Int)); | ||
1024 | emsg->str = (char *)str; | ||
1025 | emsg->val = luaL_checkinteger(L, 4); // Stack usage [-0, +0, v] | ||
1026 | _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_INT, id, emsg); | ||
1027 | } | ||
1028 | else if (!strcmp(type, "strfloat")) | ||
1029 | { | ||
1030 | Edje_Message_String_Float *emsg; | ||
1031 | const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v] | ||
1032 | emsg = alloca(sizeof(Edje_Message_String_Float)); | ||
1033 | emsg->str = (char *)str; | ||
1034 | emsg->val = luaL_checknumber(L, 4); // Stack usage [-0, +0, v] | ||
1035 | _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_FLOAT, id, emsg); | ||
1036 | } | ||
1037 | else if (!strcmp(type, "strintset")) | ||
1038 | { | ||
1039 | Edje_Message_String_Int_Set *emsg; | ||
1040 | int i, n; | ||
1041 | const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v] | ||
1042 | if (!str) return 0; | ||
1043 | luaL_checktype(L, 4, LUA_TTABLE); // Stack usage [-0, +0, v] | ||
1044 | n = lua_objlen(L, 4); // Stack usage [-0, +0, -] | ||
1045 | emsg = alloca(sizeof(Edje_Message_String_Int_Set) + ((n - 1) * sizeof(int))); | ||
1046 | emsg->str = (char *)str; | ||
1047 | emsg->count = n; | ||
1048 | for (i = 1; i <= n; i ++) | ||
1049 | { | ||
1050 | lua_pushinteger(L, i); // Stack usage [-0, +1, -] | ||
1051 | lua_gettable(L, 4); // Stack usage [-1, +1, e] | ||
1052 | emsg->val[i - 1] = lua_tointeger(L, -1); // Stack usage [-0, +0, -] | ||
1053 | lua_pop(L, 1); // Stack usage [-n, +0, -] | ||
1054 | } | ||
1055 | _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_INT_SET, id, emsg); | ||
1056 | } | ||
1057 | else if (!strcmp(type, "strfloatset")) | ||
1058 | { | ||
1059 | Edje_Message_String_Float_Set *emsg; | ||
1060 | int i, n; | ||
1061 | const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v] | ||
1062 | if (!str) return 0; | ||
1063 | luaL_checktype(L, 4, LUA_TTABLE); // Stack usage [-0, +0, v] | ||
1064 | n = lua_objlen(L, 4); | ||
1065 | emsg = alloca(sizeof(Edje_Message_String_Float_Set) + ((n - 1) * sizeof(double))); | ||
1066 | emsg->str = (char *)str; | ||
1067 | emsg->count = n; | ||
1068 | for (i = 1; i <= n; i ++) | ||
1069 | { | ||
1070 | lua_pushinteger(L, i); // Stack usage [-0, +1, -] | ||
1071 | lua_gettable(L, 4); // Stack usage [-1, +1, e] | ||
1072 | emsg->val[i - 1] = lua_tonumber(L, -1); // Stack usage [-0, +0, -] | ||
1073 | lua_pop(L, 1); // Stack usage [-n, +0, -] | ||
1074 | } | ||
1075 | _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_FLOAT_SET, id, emsg); | ||
1076 | } | ||
1077 | return 0; | ||
1078 | } | ||
1079 | |||
1080 | //------------- | ||
1081 | static Eina_Bool | ||
1082 | _elua_animator_cb(void *data) // Stack usage [-2, +2, em] | ||
1083 | { | ||
1084 | Edje_Lua_Animator *ela = data; | ||
1085 | lua_State *L; | ||
1086 | int ret = 0, err = 0; | ||
1087 | |||
1088 | if (!ela->obj.ed) return 0; | ||
1089 | L = ela->obj.ed->L; | ||
1090 | if (!L) return 0; | ||
1091 | /* This is not needed, pcalls don't longjmp(), that's why they are protected. | ||
1092 | if (setjmp(panic_jmp) == 1) | ||
1093 | { | ||
1094 | LE("Animator callback panic"); | ||
1095 | _edje_lua2_error(L, err); // Stack usage [-0, +0, m] | ||
1096 | _elua_obj_free(L, (Edje_Lua_Obj *)ela); | ||
1097 | _elua_gc(L); // Stack usage [-0, +0, e] | ||
1098 | return 0; | ||
1099 | } | ||
1100 | */ | ||
1101 | lua_rawgeti(L, LUA_REGISTRYINDEX, ela->fn_ref); // Stack usage [-0, +1, -] | ||
1102 | if ((err = lua_pcall(L, 0, 1, 0))) // Stack usage [-1, +1, -] | ||
1103 | { | ||
1104 | _edje_lua2_error(L, err); // Stack usage [-0, +0, m] | ||
1105 | _elua_obj_free(L, (Edje_Lua_Obj *)ela); | ||
1106 | _elua_gc(L); // Stack usage [-0, +0, e] | ||
1107 | return 0; | ||
1108 | } | ||
1109 | ret = lua_toboolean(L, -1); // Stack usage [-0, +0, -] | ||
1110 | lua_pop(L, 1); // Stack usage [-n, +0, -] | ||
1111 | if (ret == 0) _elua_obj_free(L, (Edje_Lua_Obj *)ela); | ||
1112 | _elua_gc(L); // Stack usage [-0, +0, e] | ||
1113 | return ret; | ||
1114 | } | ||
1115 | |||
1116 | static void | ||
1117 | _elua_animator_free(void *obj) // Stack usage [-0, +0, -] | ||
1118 | { | ||
1119 | Edje_Lua_Animator *ela = obj; | ||
1120 | lua_State *L; | ||
1121 | if (!ela->obj.ed) return; | ||
1122 | L = ela->obj.ed->L; | ||
1123 | luaL_unref(L, LUA_REGISTRYINDEX, ela->fn_ref); // Stack usage [-0, +0, -] | ||
1124 | ela->fn_ref = 0; | ||
1125 | ecore_animator_del(ela->animator); | ||
1126 | ela->animator = NULL; | ||
1127 | } | ||
1128 | |||
1129 | /** | ||
1130 | @page luaref | ||
1131 | @subsubsection edje_animator edje:animator(func) | ||
1132 | |||
1133 | This function adds an animator and returns its handle on success and NULL on | ||
1134 | failure. The function func will be called every frame tick. Note that setting | ||
1135 | the frame tick is not available as a lua function, so has to be done from C. | ||
1136 | The default tick is 1/30 second. | ||
1137 | |||
1138 | When the animator func is called, it must return a value of either true or false. | ||
1139 | If it returns true it will be called again at the next tick, or if it returns | ||
1140 | false it will be deleted automatically making any references/handles for it | ||
1141 | invalid. | ||
1142 | |||
1143 | Wraps ecore_animator_add(). | ||
1144 | |||
1145 | @param func The function to call when the animator triggers. | ||
1146 | |||
1147 | @returns A userdata that is an ecore animator. | ||
1148 | */ | ||
1149 | static int | ||
1150 | _elua_animator(lua_State *L) // Stack usage [-8, +9, emv] | ||
1151 | { | ||
1152 | Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e] | ||
1153 | Edje_Lua_Animator *ela; | ||
1154 | |||
1155 | luaL_checkany(L, 1); // Stack usage [-0, +0, v] | ||
1156 | |||
1157 | // FIXME: Allow lua to set a data to be sent back with the callback. | ||
1158 | ela = (Edje_Lua_Animator *)_elua_obj_new(L, ed, sizeof(Edje_Lua_Animator), _elua_ecore_animator_meta); | ||
1159 | // Stack usage [-5, +6, m] | ||
1160 | ela->obj.free_func = _elua_animator_free; | ||
1161 | ela->animator = ecore_animator_add(_elua_animator_cb, ela); | ||
1162 | lua_pushvalue(L, 1); // Stack usage [-0, +1, -] | ||
1163 | ela->fn_ref = luaL_ref(L, LUA_REGISTRYINDEX); // Stack usage [-1, +0, m] | ||
1164 | _elua_gc(L); // Stack usage [-0, +0, e] | ||
1165 | return 1; | ||
1166 | } | ||
1167 | |||
1168 | static Eina_Bool | ||
1169 | _elua_timer_cb(void *data) // Stack usage [-2, +2, em] | ||
1170 | { | ||
1171 | Edje_Lua_Timer *elt = data; | ||
1172 | lua_State *L; | ||
1173 | int ret = 0, err = 0; | ||
1174 | |||
1175 | if (!elt->obj.ed) return 0; | ||
1176 | L = elt->obj.ed->L; | ||
1177 | if (!L) return 0; | ||
1178 | /* This is not needed, pcalls don't longjmp(), that's why they are protected. | ||
1179 | if (setjmp(panic_jmp) == 1) | ||
1180 | { | ||
1181 | LE("Timer callback panic"); | ||
1182 | _edje_lua2_error(L, err); // Stack usage [-0, +0, m] | ||
1183 | _elua_obj_free(L, (Edje_Lua_Obj *)elt); | ||
1184 | _elua_gc(L); // Stack usage [-0, +0, e] | ||
1185 | return 0; | ||
1186 | } | ||
1187 | */ | ||
1188 | lua_rawgeti(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +1, -] | ||
1189 | if ((err = lua_pcall(L, 0, 1, 0))) // Stack usage [-1, +1, -] | ||
1190 | { | ||
1191 | _edje_lua2_error(L, err); | ||
1192 | _elua_obj_free(L, (Edje_Lua_Obj *)elt); // Stack usage [-0, +0, m] | ||
1193 | _elua_gc(L); // Stack usage [-0, +0, e] | ||
1194 | return 0; | ||
1195 | } | ||
1196 | ret = lua_toboolean(L, -1); // Stack usage [-0, +0, -] | ||
1197 | lua_pop(L, 1); // Stack usage [-n, +0, -] | ||
1198 | if (ret == 0) _elua_obj_free(L, (Edje_Lua_Obj *)elt); | ||
1199 | _elua_gc(L); // Stack usage [-0, +0, e] | ||
1200 | return ret; | ||
1201 | } | ||
1202 | |||
1203 | static void | ||
1204 | _elua_timer_free(void *obj) // Stack usage [-0, +0, -] | ||
1205 | { | ||
1206 | Edje_Lua_Timer *elt = obj; | ||
1207 | lua_State *L; | ||
1208 | if (!elt->obj.ed) return; | ||
1209 | L = elt->obj.ed->L; | ||
1210 | luaL_unref(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +0, -] | ||
1211 | elt->fn_ref = 0; | ||
1212 | ecore_timer_del(elt->timer); | ||
1213 | elt->timer = NULL; | ||
1214 | } | ||
1215 | |||
1216 | /** | ||
1217 | @page luaref | ||
1218 | @subsubsection edje_timer edje:timer(tick, func) | ||
1219 | |||
1220 | This function adds a timer and returns its handle on success and NULL on failure. | ||
1221 | The function func will be called every tick seconds. | ||
1222 | |||
1223 | When the timer func is called, it must return a value of either true or false. | ||
1224 | If it returns true, it will be called again at the next tick, or if it returns | ||
1225 | false it will be deleted automatically making any references/handles for it | ||
1226 | invalid. | ||
1227 | |||
1228 | Wraps ecore_timer_add(). | ||
1229 | |||
1230 | @param tick How often, in seconds, to call the function. | ||
1231 | @param func The function to call when the timer triggers. | ||
1232 | |||
1233 | @returns A userdata that is an ecore timer. | ||
1234 | */ | ||
1235 | static int | ||
1236 | _elua_timer(lua_State *L) // Stack usage [-8, +9, emv] | ||
1237 | { | ||
1238 | Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e] | ||
1239 | Edje_Lua_Timer *elt; | ||
1240 | double val; | ||
1241 | |||
1242 | val = luaL_checknumber(L, 1); // Stack usage [-0, +0, v] | ||
1243 | luaL_checkany(L, 2); // Stack usage [-0, +0, v] | ||
1244 | |||
1245 | elt = (Edje_Lua_Timer *)_elua_obj_new(L, ed, sizeof(Edje_Lua_Timer), _elua_ecore_timer_meta); | ||
1246 | // Stack usage [-5, +6, m] | ||
1247 | elt->obj.free_func = _elua_timer_free; | ||
1248 | elt->timer = ecore_timer_add(val, _elua_timer_cb, elt); | ||
1249 | lua_pushvalue(L, 2); // Stack usage [-0, +1, -] | ||
1250 | elt->fn_ref = luaL_ref(L, LUA_REGISTRYINDEX); // Stack usage [-1, +0, m] | ||
1251 | _elua_gc(L); // Stack usage [-0, +0, e] | ||
1252 | return 1; | ||
1253 | } | ||
1254 | |||
1255 | static Eina_Bool | ||
1256 | _elua_transition_cb(void *data) // Stack usage [-3, +3, em] | ||
1257 | { | ||
1258 | Edje_Lua_Transition *elt = data; | ||
1259 | lua_State *L; | ||
1260 | int ret = 0, err = 0; | ||
1261 | double t; | ||
1262 | |||
1263 | if (!elt->obj.ed) return 0; | ||
1264 | L = elt->obj.ed->L; | ||
1265 | if (!L) return 0; | ||
1266 | t = (ecore_loop_time_get() - elt->start) / elt->transition; | ||
1267 | if (t > 1.0) t = 1.0; | ||
1268 | /* This is not needed, pcalls don't longjmp(), that's why they are protected. | ||
1269 | if (setjmp(panic_jmp) == 1) | ||
1270 | { | ||
1271 | LE("Transition callback panic"); | ||
1272 | _edje_lua2_error(L, err); // Stack usage [-0, +0, m] | ||
1273 | _elua_obj_free(L, (Edje_Lua_Obj *)elt); | ||
1274 | _elua_gc(L); // Stack usage [-0, +0, e] | ||
1275 | return 0; | ||
1276 | } | ||
1277 | */ | ||
1278 | lua_rawgeti(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +1, -] | ||
1279 | lua_pushnumber(L, t); // Stack usage [-0, +1, -] | ||
1280 | if ((err = lua_pcall(L, 1, 1, 0))) // Stack usage [-2, +1, -] | ||
1281 | { | ||
1282 | _edje_lua2_error(L, err); | ||
1283 | _elua_obj_free(L, (Edje_Lua_Obj *)elt); // Stack usage [-0, +0, m] | ||
1284 | _elua_gc(L); // Stack usage [-0, +0, e] | ||
1285 | return 0; | ||
1286 | } | ||
1287 | ret = lua_toboolean(L, -1); // Stack usage [-0, +0, -] | ||
1288 | lua_pop(L, 1); // Stack usage [-n, +0, -] | ||
1289 | if (t >= 1.0) ret = 0; | ||
1290 | if (ret == 0) _elua_obj_free(L, (Edje_Lua_Obj *)elt); | ||
1291 | _elua_gc(L); // Stack usage [-0, +0, e] | ||
1292 | return ret; | ||
1293 | } | ||
1294 | |||
1295 | static void | ||
1296 | _elua_transition_free(void *obj) // Stack usage [-0, +0, -] | ||
1297 | { | ||
1298 | Edje_Lua_Transition *elt = obj; | ||
1299 | lua_State *L; | ||
1300 | if (!elt->obj.ed) return; | ||
1301 | L = elt->obj.ed->L; | ||
1302 | luaL_unref(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +0, -] | ||
1303 | elt->fn_ref = 0; | ||
1304 | ecore_animator_del(elt->animator); | ||
1305 | elt->animator = NULL; | ||
1306 | } | ||
1307 | |||
1308 | /** | ||
1309 | @page luaref | ||
1310 | @subsubsection edje_transition edje:transition(div, func) | ||
1311 | |||
1312 | Just like edje:animator(), except that the callback function gets called with an | ||
1313 | argument. The argument is the amount of time since the transition was created, | ||
1314 | divided by the div parameter. | ||
1315 | |||
1316 | @param div A number to divide the time since creation by. | ||
1317 | @param func The function to call when the transition triggers. | ||
1318 | |||
1319 | @returns A userdata that is a transition (ecore animator, plus other info). | ||
1320 | */ | ||
1321 | static int | ||
1322 | _elua_transition(lua_State *L) // Stack usage [-8, +9, emv] | ||
1323 | { | ||
1324 | Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e] | ||
1325 | Edje_Lua_Transition *elt; | ||
1326 | double val; | ||
1327 | |||
1328 | val = luaL_checknumber(L, 1); // Stack usage [-0, +0, v] | ||
1329 | luaL_checkany(L, 2); // Stack usage [-0, +0, v] | ||
1330 | |||
1331 | elt = (Edje_Lua_Transition *)_elua_obj_new(L, ed, sizeof(Edje_Lua_Transition), _elua_ecore_animator_meta); | ||
1332 | // Stack usage [-5, +6, m] | ||
1333 | elt->obj.free_func = _elua_transition_free; | ||
1334 | elt->animator = ecore_animator_add(_elua_transition_cb, elt); | ||
1335 | if (val < 0.0000001) val = 0.0000001; | ||
1336 | elt->transition = val; | ||
1337 | elt->start = ecore_loop_time_get(); | ||
1338 | lua_pushvalue(L, 2); // Stack usage [-0, +1, -] | ||
1339 | elt->fn_ref = luaL_ref(L, LUA_REGISTRYINDEX); // Stack usage [-1, +0, m] | ||
1340 | _elua_gc(L); // Stack usage [-0, +0, e] | ||
1341 | return 1; | ||
1342 | } | ||
1343 | |||
1344 | //------------- | ||
1345 | /** | ||
1346 | @page luaref | ||
1347 | @subsubsection edje_colour_class edje:color_class(class, r, g, b, a) | ||
1348 | |||
1349 | Gets, (and optionally sets) the colours for a color class. | ||
1350 | |||
1351 | Wraps edje_object_color_class_set(). | ||
1352 | |||
1353 | @param class A color class name. | ||
1354 | @param r The new red value. | ||
1355 | @param g The new green value. | ||
1356 | @param b The new blue value. | ||
1357 | @param a The new alpha value. | ||
1358 | |||
1359 | Note that the r, g, b, and a arguments are optional, without them this function | ||
1360 | just queries the current values. The r, g, b, and a arguments can be separate | ||
1361 | values, or named fields in a table. | ||
1362 | |||
1363 | @return A table with these fields: | ||
1364 | - integer r: The red value. | ||
1365 | - integer g: The green value. | ||
1366 | - integer b: The blue value. | ||
1367 | - integer a: The alpha value. | ||
1368 | |||
1369 | @since 1.1.0 | ||
1370 | */ | ||
1371 | static int | ||
1372 | _elua_color_class(lua_State *L) // Stack usage [-(10|14), +(11|15), ?] | ||
1373 | { | ||
1374 | Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e] | ||
1375 | Edje_Color_Class *c_class; | ||
1376 | const char *class = luaL_checkstring(L, 1); // Stack usage [-0, +0, v] | ||
1377 | int r, g, b, a; | ||
1378 | |||
1379 | if (!class) return 0; | ||
1380 | |||
1381 | if (_elua_scan_params(L, 2, "%r %g %b %a", &r, &g, &b, &a) > 0) | ||
1382 | { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e] | ||
1383 | _elua_color_fix(&r, &g, &b, &a); | ||
1384 | // This is the way that embryo does it - | ||
1385 | //edje_object_color_class_set(ed->obj, class, r, g, b, a, r, g, b, a, r, g, b, a); | ||
1386 | // But that deals with object scope, which is currently useless in lua, | ||
1387 | // since we have no objects that can use color_class yet. | ||
1388 | // So we do it at global scope instead. | ||
1389 | // LATER - Should do both? | ||
1390 | edje_color_class_set(class, r, g, b, a, r, g, b, a, r, g, b, a); | ||
1391 | } | ||
1392 | |||
1393 | c_class = _edje_color_class_find(ed, class); | ||
1394 | if (!c_class) return 0; | ||
1395 | |||
1396 | _elua_ret(L, "%r %g %b %a", c_class->r, c_class->g, c_class->b, c_class->a); | ||
1397 | // Stack usage [-8, +9, em] | ||
1398 | return 1; | ||
1399 | } | ||
1400 | |||
1401 | /** | ||
1402 | @page luaref | ||
1403 | @subsubsection edje_text_class edje:text_class(class, font, size) | ||
1404 | |||
1405 | Gets, (and optionally sets) the details for a text class. | ||
1406 | |||
1407 | Wraps edje_object_text_class_set(). | ||
1408 | |||
1409 | @param class A text class name. | ||
1410 | @param font The new font name. | ||
1411 | @param size The new font size. | ||
1412 | |||
1413 | Note that the font and size arguments are optional, without them this function | ||
1414 | just queries the current values. The font and size arguments can be separate | ||
1415 | values, or named fields in a table. The font name can refer to a font in the | ||
1416 | edje file, or an external font. | ||
1417 | |||
1418 | @return A table with these fields: | ||
1419 | - string font: The font name. | ||
1420 | - integer size: The font size. | ||
1421 | |||
1422 | @since 1.1.0 | ||
1423 | */ | ||
1424 | static int | ||
1425 | _elua_text_class(lua_State *L) // Stack usage [-(6|8), +(7|9), emv] | ||
1426 | { | ||
1427 | Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e] | ||
1428 | Edje_Text_Class *t_class; | ||
1429 | const char *class = luaL_checkstring(L, 1); // Stack usage [-0, +0, v] | ||
1430 | char *font = NULL; | ||
1431 | Evas_Font_Size size = 0; | ||
1432 | |||
1433 | if (!class) return 0; | ||
1434 | |||
1435 | // Just like color_class above, this does things differently from embryo, | ||
1436 | // for the same reason. | ||
1437 | if (_elua_scan_params(L, 2, "$font %size", &font, &size) > 0) | ||
1438 | // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e] | ||
1439 | edje_text_class_set(class, font, size); | ||
1440 | |||
1441 | t_class = _edje_text_class_find(ed, class); | ||
1442 | if (!t_class) return 0; | ||
1443 | |||
1444 | _elua_ret(L, "$font %size", t_class->font, t_class->size); | ||
1445 | // Stack usage [-4, +5, em] | ||
1446 | return 1; | ||
1447 | } | ||
1448 | |||
1449 | //------------- | ||
1450 | static void | ||
1451 | _elua_evas_obj_free(void *obj) | ||
1452 | { | ||
1453 | Edje_Lua_Evas_Object *elo = obj; | ||
1454 | |||
1455 | if (!elo->obj.ed) return; | ||
1456 | evas_object_del(elo->evas_obj); | ||
1457 | elo->evas_obj = NULL; | ||
1458 | } | ||
1459 | |||
1460 | // Stack usage [-7, +8, em] | ||
1461 | #define _ELUA_PLANT_EVAS_OBJECT(type, meta, free) \ | ||
1462 | Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); \ | ||
1463 | type *elo; \ | ||
1464 | elo = (type *)_elua_obj_new(L, ed, sizeof(type), meta); \ | ||
1465 | elo->obj.free_func = free; | ||
1466 | // Stack usage [-2, +2, e] | ||
1467 | // Stack usage [-5, +6, m] | ||
1468 | |||
1469 | static void | ||
1470 | _elua_polish_evas_object(Edje *ed, Edje_Lua_Evas_Object *elo) | ||
1471 | { | ||
1472 | evas_object_smart_member_add(elo->evas_obj, ed->obj); | ||
1473 | evas_object_clip_set(elo->evas_obj, ed->base.clipper); | ||
1474 | evas_object_move(elo->evas_obj, ed->x, ed->y); | ||
1475 | evas_object_resize(elo->evas_obj, 0, 0); | ||
1476 | evas_object_data_set(elo->evas_obj, ELO, elo); | ||
1477 | } | ||
1478 | |||
1479 | /** | ||
1480 | @page luaref | ||
1481 | @subsubsection edje_edje edje:edje() | ||
1482 | |||
1483 | Create an edje object, and add it to the edje. | ||
1484 | |||
1485 | Wraps edje_object_add(). | ||
1486 | |||
1487 | @returns A userdata that is an edje object. | ||
1488 | |||
1489 | @since 1.1.0 | ||
1490 | */ | ||
1491 | static int | ||
1492 | _elua_edje(lua_State *L) // Stack usage [-7, +8, em] | ||
1493 | { | ||
1494 | _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_edje_meta, _elua_evas_obj_free) | ||
1495 | // Stack usage [-7, +8, em] | ||
1496 | elo->evas_obj = edje_object_add(evas_object_evas_get(ed->obj)); | ||
1497 | _edje_subobj_register(ed, elo->evas_obj); | ||
1498 | _elua_polish_evas_object(ed, elo); | ||
1499 | return 1; | ||
1500 | } | ||
1501 | |||
1502 | /** | ||
1503 | @page luaref | ||
1504 | @subsubsection edje_image edje:image() | ||
1505 | |||
1506 | Create an evas image, and add it to the edje. | ||
1507 | |||
1508 | Wraps evas_object_image_add(). | ||
1509 | |||
1510 | @returns A userdata that is an evas image. | ||
1511 | |||
1512 | @since 1.1.0 | ||
1513 | */ | ||
1514 | static int | ||
1515 | _elua_image(lua_State *L) // Stack usage [-7, +8, em] | ||
1516 | { | ||
1517 | _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_image_meta, _elua_evas_obj_free) | ||
1518 | // Stack usage [-7, +8, em] | ||
1519 | elo->evas_obj = evas_object_image_filled_add(evas_object_evas_get(ed->obj)); | ||
1520 | _elua_polish_evas_object(ed, elo); | ||
1521 | return 1; | ||
1522 | } | ||
1523 | |||
1524 | /** | ||
1525 | @page luaref | ||
1526 | @subsubsection edje_line edje:line() | ||
1527 | |||
1528 | Create an evas line, and add it to the edje. | ||
1529 | |||
1530 | Wraps evas_object_line_add(). | ||
1531 | |||
1532 | @returns A userdata that is an evas line. | ||
1533 | |||
1534 | @since 1.1.0 | ||
1535 | */ | ||
1536 | static int | ||
1537 | _elua_line(lua_State *L) // Stack usage [-7, +8, em] | ||
1538 | { | ||
1539 | _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_line_meta, _elua_evas_obj_free) | ||
1540 | // Stack usage [-7, +8, em] | ||
1541 | elo->evas_obj = evas_object_line_add(evas_object_evas_get(ed->obj)); | ||
1542 | _elua_polish_evas_object(ed, elo); | ||
1543 | return 1; | ||
1544 | } | ||
1545 | |||
1546 | static void | ||
1547 | _elua_map_free(void *obj) | ||
1548 | { | ||
1549 | Edje_Lua_Map *elm = obj; | ||
1550 | if (!elm->obj.ed) return; | ||
1551 | evas_map_free(elm->map); | ||
1552 | elm->map = NULL; | ||
1553 | } | ||
1554 | |||
1555 | /** | ||
1556 | @page luaref | ||
1557 | @subsubsection edje_map edje:map() | ||
1558 | |||
1559 | Create an evas map. | ||
1560 | |||
1561 | Wraps evas_map_new(). | ||
1562 | |||
1563 | @returns A userdata that is an evas map. | ||
1564 | |||
1565 | @since 1.1.0 | ||
1566 | */ | ||
1567 | static int | ||
1568 | _elua_map(lua_State *L) // Stack usage [-7, +8, emv] | ||
1569 | { | ||
1570 | _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Map, _elua_evas_map_meta, _elua_map_free) | ||
1571 | // Stack usage [-7, +8, em] | ||
1572 | elo->map = evas_map_new(luaL_checkinteger(L, 1)); // Stack usage [-0, +0, v] | ||
1573 | return 1; | ||
1574 | } | ||
1575 | |||
1576 | /** | ||
1577 | @page luaref | ||
1578 | @subsubsection edje_polygon edje:polygon() | ||
1579 | |||
1580 | Create an evas polygon, and add it to the edje. | ||
1581 | |||
1582 | Wraps evas_object_polygon_add(). | ||
1583 | |||
1584 | @returns A userdata that is an evas polygon. | ||
1585 | |||
1586 | @since 1.1.0 | ||
1587 | */ | ||
1588 | static int | ||
1589 | _elua_polygon(lua_State *L) // Stack usage [-7, +8, em] | ||
1590 | { | ||
1591 | _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_polygon_meta, _elua_evas_obj_free) | ||
1592 | // Stack usage [-7, +8, em] | ||
1593 | elo->evas_obj = evas_object_polygon_add(evas_object_evas_get(ed->obj)); | ||
1594 | _elua_polish_evas_object(ed, elo); | ||
1595 | return 1; | ||
1596 | } | ||
1597 | |||
1598 | /** | ||
1599 | @page luaref | ||
1600 | @subsubsection edje_rect edje:rect() | ||
1601 | |||
1602 | Create an evas rectangle, and add it to the edje. | ||
1603 | |||
1604 | Wraps evas_object_rectangle_add(). | ||
1605 | |||
1606 | @returns A userdata that is an evas rectangle. | ||
1607 | */ | ||
1608 | static int | ||
1609 | _elua_rect(lua_State *L) // Stack usage [-7, +8, em] | ||
1610 | { | ||
1611 | _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_meta, _elua_evas_obj_free) | ||
1612 | // Stack usage [-7, +8, em] | ||
1613 | elo->evas_obj = evas_object_rectangle_add(evas_object_evas_get(ed->obj)); | ||
1614 | _elua_polish_evas_object(ed, elo); | ||
1615 | return 1; | ||
1616 | } | ||
1617 | |||
1618 | /** | ||
1619 | @page luaref | ||
1620 | @subsubsection edje_text edje:text() | ||
1621 | |||
1622 | Create an evas text object, and add it to the edje. | ||
1623 | |||
1624 | Wraps evas_object_text_add(). | ||
1625 | |||
1626 | @returns A userdata that is an evas text object. | ||
1627 | |||
1628 | @since 1.1.0 | ||
1629 | */ | ||
1630 | static int | ||
1631 | _elua_text(lua_State *L) // Stack usage [-7, +8, em] | ||
1632 | { | ||
1633 | _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_text_meta, _elua_evas_obj_free) | ||
1634 | // Stack usage [-7, +8, em] | ||
1635 | elo->evas_obj = evas_object_text_add(evas_object_evas_get(ed->obj)); | ||
1636 | _elua_polish_evas_object(ed, elo); | ||
1637 | return 1; | ||
1638 | } | ||
1639 | |||
1640 | /* XXX: disabled until there are enough textblock functions implemented to make it actually useful | ||
1641 | _elua_textblock(lua_State *L) // Stack usage [-7, +8, em] | ||
1642 | { | ||
1643 | _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_textblock_meta, _elua_evas_obj_free) | ||
1644 | // Stack usage [-7, +8, em] | ||
1645 | elo->evas_obj = evas_object_textblock_add(evas_object_evas_get(ed->obj)); | ||
1646 | _elua_polish_evas_object(ed, elo); | ||
1647 | return 1; | ||
1648 | } | ||
1649 | */ | ||
1650 | |||
1651 | //------------- | ||
1652 | //------------- | ||
1653 | |||
1654 | /** | ||
1655 | @page luaref | ||
1656 | @subsection evas Evas class. | ||
1657 | |||
1658 | The lua evas class includes functions for dealing with evas objects. The evas | ||
1659 | objects must have been previously created by lua using one of the lua ezas | ||
1660 | object creation functions from the lua edje class. | ||
1661 | |||
1662 | In the following, "evas_object" is a place holder for any lua variable that | ||
1663 | holds a reference to an evas object. | ||
1664 | */ | ||
1665 | |||
1666 | static int _elua_obj_del(lua_State *L); | ||
1667 | |||
1668 | static int _elua_hide(lua_State *L); | ||
1669 | static int _elua_show(lua_State *L); | ||
1670 | static int _elua_visible(lua_State *L); | ||
1671 | |||
1672 | static int _elua_above(lua_State *L); | ||
1673 | static int _elua_below(lua_State *L); | ||
1674 | static int _elua_bottom(lua_State *L); | ||
1675 | static int _elua_lower(lua_State *L); | ||
1676 | static int _elua_raise(lua_State *L); | ||
1677 | static int _elua_top(lua_State *L); | ||
1678 | |||
1679 | static int _elua_geom(lua_State *L); | ||
1680 | static int _elua_move(lua_State *L); | ||
1681 | static int _elua_pos(lua_State *L); | ||
1682 | static int _elua_resize(lua_State *L); | ||
1683 | static int _elua_size(lua_State *L); | ||
1684 | |||
1685 | static int _elua_clip(lua_State *L); | ||
1686 | static int _elua_clipees(lua_State *L); | ||
1687 | static int _elua_unclip(lua_State *L); | ||
1688 | |||
1689 | static int _elua_type(lua_State *L); | ||
1690 | |||
1691 | static int _elua_pass(lua_State *L); | ||
1692 | static int _elua_precise(lua_State *L); | ||
1693 | static int _elua_repeat(lua_State *L); | ||
1694 | |||
1695 | static int _elua_color(lua_State *L); | ||
1696 | |||
1697 | static int _elua_obj_map(lua_State *L); | ||
1698 | static int _elua_obj_map_enable(lua_State *L); | ||
1699 | static int _elua_obj_map_source(lua_State *L); | ||
1700 | |||
1701 | static const char *_elua_evas_api = "evas"; | ||
1702 | static const struct luaL_reg _elua_evas_funcs [] = | ||
1703 | { | ||
1704 | {"del", _elua_obj_del}, // generic del any object created for edje (evas objects, timers, animators, transitions... everything) | ||
1705 | |||
1706 | {"hide", _elua_hide}, // hide, return current visibility | ||
1707 | {"show", _elua_show}, // show, return current visibility | ||
1708 | {"visible", _elua_visible}, // get object visibility | ||
1709 | |||
1710 | {"above", _elua_above}, // get object above or stack obj above given obj | ||
1711 | {"below", _elua_below}, // get object below or stack obj below given obj | ||
1712 | {"bottom", _elua_bottom}, // get bottom | ||
1713 | {"lower", _elua_lower}, // lower to bottom | ||
1714 | {"raise", _elua_raise}, // raise to top | ||
1715 | {"top", _elua_top}, // get top | ||
1716 | |||
1717 | {"geom", _elua_geom}, // move and resize and return current geometry | ||
1718 | {"move", _elua_move}, // move, return current position | ||
1719 | {"pos", _elua_pos}, // move, return current position | ||
1720 | {"resize", _elua_resize}, // resize, return current size | ||
1721 | {"size", _elua_size}, // resize, return current size | ||
1722 | |||
1723 | {"clip", _elua_clip}, // set clip obj, return clip object | ||
1724 | {"clipees", _elua_clipees}, // get clip children | ||
1725 | {"unclip", _elua_unclip}, // clear clip obj | ||
1726 | |||
1727 | {"type", _elua_type}, // get object type | ||
1728 | |||
1729 | {"pass", _elua_pass}, // set pass events, get pass events | ||
1730 | {"precise", _elua_precise}, // set precise inside flag, get precise | ||
1731 | {"repeat", _elua_repeat}, // set repeat events, get repeat events | ||
1732 | |||
1733 | {"color", _elua_color}, // set color, return color | ||
1734 | // {"color_class", _elua_object_color_class}, // get or set object color class | ||
1735 | |||
1736 | // FIXME: set callbacks (mouse down, up, blah blah blah) | ||
1737 | // | ||
1738 | // FIXME: set scale (explicit value) | ||
1739 | // FIXME: need to set auto-scale (same as scale: 1) | ||
1740 | |||
1741 | // FIXME: later - set render op, anti-alias, pointer mode (autograb, nograb) | ||
1742 | |||
1743 | // map api here | ||
1744 | {"map", _elua_obj_map}, | ||
1745 | {"map_enable", _elua_obj_map_enable}, | ||
1746 | {"map_source", _elua_obj_map_source}, | ||
1747 | |||
1748 | {NULL, NULL} // end | ||
1749 | }; | ||
1750 | |||
1751 | //------------- | ||
1752 | /** | ||
1753 | @page luaref | ||
1754 | @subsubsection evas_hide evas_object:hide() | ||
1755 | |||
1756 | Hides the object. | ||
1757 | |||
1758 | Wraps evas_object_hide(). | ||
1759 | |||
1760 | @returns A boolean representing the current visibility. | ||
1761 | */ | ||
1762 | static int | ||
1763 | _elua_hide(lua_State *L) // Stack usage [-0, +1, -] | ||
1764 | { | ||
1765 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
1766 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
1767 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
1768 | evas_object_hide(elo->evas_obj); | ||
1769 | lua_pushboolean(L, evas_object_visible_get(elo->evas_obj)); // Stack usage [-0, +1, -] | ||
1770 | return 1; | ||
1771 | } | ||
1772 | |||
1773 | /** | ||
1774 | @page luaref | ||
1775 | @subsubsection evas_show evas_object:show() | ||
1776 | |||
1777 | Shows the object. | ||
1778 | |||
1779 | Wraps evas_object_show(). | ||
1780 | |||
1781 | @returns A boolean representing the current visibility. | ||
1782 | */ | ||
1783 | static int | ||
1784 | _elua_show(lua_State *L) // Stack usage [-0, +1, -] | ||
1785 | { | ||
1786 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
1787 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
1788 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
1789 | evas_object_show(elo->evas_obj); | ||
1790 | lua_pushboolean(L, evas_object_visible_get(elo->evas_obj)); // Stack usage [-0, +1, -] | ||
1791 | return 1; | ||
1792 | } | ||
1793 | |||
1794 | /** | ||
1795 | @page luaref | ||
1796 | @subsubsection evas_visible evas_object:visible(visibility) | ||
1797 | |||
1798 | Gets (and optionally sets) this objects visibility. | ||
1799 | |||
1800 | Wraps evas_object_hide() or evas_object_show(). | ||
1801 | |||
1802 | @param visibility The new visibility you want to change it to. | ||
1803 | |||
1804 | Note that the argument is optional, without it this function just queries the | ||
1805 | current value. | ||
1806 | |||
1807 | @returns A boolean representing the current visibility. | ||
1808 | */ | ||
1809 | static int | ||
1810 | _elua_visible(lua_State *L) // Stack usage [-0, +1, -] | ||
1811 | { | ||
1812 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
1813 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
1814 | int n; | ||
1815 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
1816 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
1817 | if (n == 2) | ||
1818 | { | ||
1819 | if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -] | ||
1820 | { | ||
1821 | if (lua_toboolean(L, 2)) evas_object_show(elo->evas_obj); | ||
1822 | // Stack usage [-0, +0, -] | ||
1823 | else evas_object_hide(elo->evas_obj); | ||
1824 | } | ||
1825 | } | ||
1826 | lua_pushboolean(L, evas_object_visible_get(elo->evas_obj)); // Stack usage [-0, +1, -] | ||
1827 | return 1; | ||
1828 | } | ||
1829 | |||
1830 | //------------- | ||
1831 | /** | ||
1832 | @page luaref | ||
1833 | @subsubsection evas_above evas_object:above() | ||
1834 | |||
1835 | Figure out what, if anything, is above us. | ||
1836 | |||
1837 | Wraps evas_object_above_get(). | ||
1838 | |||
1839 | Note that it may not return any value. | ||
1840 | |||
1841 | @returns A reference to the object above this one. | ||
1842 | */ | ||
1843 | static int | ||
1844 | _elua_above(lua_State *L) // Stack usage [-3, +4, -] | ||
1845 | { | ||
1846 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
1847 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
1848 | Edje_Lua_Evas_Object *elo2; | ||
1849 | Evas_Object *o; | ||
1850 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
1851 | if (!(o = evas_object_above_get(elo->evas_obj))) return 0; | ||
1852 | if (!(elo2 = evas_object_data_get(o, ELO))) return 0; | ||
1853 | _elua_ref_get(L, elo2); // Stack usage [-3, +4, -] | ||
1854 | return 1; | ||
1855 | } | ||
1856 | |||
1857 | /** | ||
1858 | @page luaref | ||
1859 | @subsubsection evas_below evas_object:below() | ||
1860 | |||
1861 | Figure out what, if anything, is below us. | ||
1862 | |||
1863 | Wraps evas_object_below_get(). | ||
1864 | |||
1865 | Note that it may not return any value. | ||
1866 | |||
1867 | @returns A reference to the object below this one. | ||
1868 | */ | ||
1869 | static int | ||
1870 | _elua_below(lua_State *L) // Stack usage [-3, +4, -] | ||
1871 | { | ||
1872 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
1873 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
1874 | Edje_Lua_Evas_Object *elo2; | ||
1875 | Evas_Object *o; | ||
1876 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
1877 | if (!(o = evas_object_below_get(elo->evas_obj))) return 0; | ||
1878 | if (!(elo2 = evas_object_data_get(o, ELO))) return 0; | ||
1879 | _elua_ref_get(L, elo2); // Stack usage [-3, +4, -] | ||
1880 | return 1; | ||
1881 | } | ||
1882 | |||
1883 | /** | ||
1884 | @page luaref | ||
1885 | @subsubsection evas_bottom evas_object:bottom() | ||
1886 | |||
1887 | Figure out what, if anything, is waaaay below us. | ||
1888 | |||
1889 | Note that it may not return any value. | ||
1890 | |||
1891 | @returns A reference to the object at the bottom. | ||
1892 | */ | ||
1893 | static int | ||
1894 | _elua_bottom(lua_State *L) // Stack usage [-(0|3), +(0|4), -] | ||
1895 | { | ||
1896 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
1897 | Edje_Lua_Evas_Object *elo2; | ||
1898 | Evas_Object *o; | ||
1899 | Eina_List *list, *l; | ||
1900 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
1901 | if (!(list = (Eina_List *)evas_object_smart_members_get(obj->ed->obj))) return 0; | ||
1902 | for (l = list; l; l = l->next) | ||
1903 | { | ||
1904 | o = l->data; | ||
1905 | if ((elo2 = evas_object_data_get(o, ELO))) | ||
1906 | { | ||
1907 | _elua_ref_get(L, elo2); // Stack usage [-3, +4, -] | ||
1908 | return 1; | ||
1909 | } | ||
1910 | } | ||
1911 | return 0; | ||
1912 | } | ||
1913 | |||
1914 | /** | ||
1915 | @page luaref | ||
1916 | @subsubsection evas_lower evas_object:lower() | ||
1917 | |||
1918 | Lower this object to the bottom. | ||
1919 | |||
1920 | Wraps evas_object_lower(). | ||
1921 | */ | ||
1922 | static int | ||
1923 | _elua_lower(lua_State *L) // Stack usage [-0, +0, -] | ||
1924 | { | ||
1925 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
1926 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
1927 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
1928 | evas_object_lower(elo->evas_obj); | ||
1929 | return 0; | ||
1930 | } | ||
1931 | |||
1932 | /** | ||
1933 | @page luaref | ||
1934 | @subsubsection evas_raise evas_object:raise() | ||
1935 | |||
1936 | Raise this object to the top. | ||
1937 | |||
1938 | Wraps evas_object_raise(). | ||
1939 | */ | ||
1940 | static int | ||
1941 | _elua_raise(lua_State *L) // Stack usage [-0, +0, -] | ||
1942 | { | ||
1943 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
1944 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
1945 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
1946 | evas_object_raise(elo->evas_obj); | ||
1947 | return 0; | ||
1948 | } | ||
1949 | |||
1950 | /** | ||
1951 | @page luaref | ||
1952 | @subsubsection evas_top evas_object:top() | ||
1953 | |||
1954 | Figure out what, if anything, is waaaay above us. | ||
1955 | |||
1956 | Note that it may not return any value. | ||
1957 | |||
1958 | @returns A reference to the object at the top. | ||
1959 | */ | ||
1960 | static int | ||
1961 | _elua_top(lua_State *L) // Stack usage [-(0|3), +(0|4), -] | ||
1962 | { | ||
1963 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-(0, +0, -] | ||
1964 | Edje_Lua_Evas_Object *elo2; | ||
1965 | Evas_Object *o; | ||
1966 | Eina_List *list, *l; | ||
1967 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
1968 | if (!(list = (Eina_List *)evas_object_smart_members_get(obj->ed->obj))) return 0; | ||
1969 | if (!list) return 0; | ||
1970 | for (l = eina_list_last(list); l; l = l->prev) | ||
1971 | { | ||
1972 | o = l->data; | ||
1973 | if ((elo2 = evas_object_data_get(o, ELO))) | ||
1974 | { | ||
1975 | _elua_ref_get(L, elo2); // Stack usage [-3, +4, -] | ||
1976 | return 1; | ||
1977 | } | ||
1978 | } | ||
1979 | return 0; | ||
1980 | } | ||
1981 | |||
1982 | //------------- | ||
1983 | /** | ||
1984 | @page luaref | ||
1985 | @subsubsection evas_geom evas_object:geom(x, y, w, h) | ||
1986 | |||
1987 | Gets (and optionally sets) this objects geometry. | ||
1988 | |||
1989 | Wraps evas_object_move() and evas_object_resize. | ||
1990 | |||
1991 | @param x The new X coordinate. | ||
1992 | @param y The new Y coordinate. | ||
1993 | @param w The new width. | ||
1994 | @param h The new height. | ||
1995 | |||
1996 | Note that the arguments are optional, without them this function just queries | ||
1997 | the current values. The arguments can be separate values, or named fields in a | ||
1998 | table. | ||
1999 | |||
2000 | @return A table with these fields: | ||
2001 | - integer x: X coordinate. | ||
2002 | - integer x: Y coordinate. | ||
2003 | - integer w: Width. | ||
2004 | - integer w: Height. | ||
2005 | */ | ||
2006 | static int | ||
2007 | _elua_geom(lua_State *L) // Stack usage [-(8|12), +(9|13), em] | ||
2008 | { | ||
2009 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2010 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2011 | Evas_Coord ox, oy, ow, oh; | ||
2012 | int x, y, w, h; | ||
2013 | |||
2014 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2015 | evas_object_geometry_get(elo->evas_obj, &ox, &oy, &ow, &oh); | ||
2016 | if (_elua_scan_params(L, 2, "%x %y %w %h", &x, &y, &w, &h) > 0) | ||
2017 | { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e] | ||
2018 | if ((x != (ox - obj->ed->x)) || (y != (oy - obj->ed->y))) | ||
2019 | { | ||
2020 | evas_object_move(elo->evas_obj, | ||
2021 | obj->ed->x + x, | ||
2022 | obj->ed->y + y); | ||
2023 | } | ||
2024 | if ((w != ow) || (h != oh)) | ||
2025 | { | ||
2026 | evas_object_resize(elo->evas_obj, w, h); | ||
2027 | } | ||
2028 | evas_object_geometry_get(elo->evas_obj, &ox, &oy, &ow, &oh); | ||
2029 | elo->x = ox - obj->ed->x; | ||
2030 | elo->y = oy - obj->ed->y; | ||
2031 | } | ||
2032 | _elua_ret(L, "%x %y %w %h", elo->x, elo->y, ow, oh); | ||
2033 | // Stack usage [-8, +9, em] | ||
2034 | return 1; | ||
2035 | } | ||
2036 | |||
2037 | /** | ||
2038 | @page luaref | ||
2039 | @subsubsection evas_move evas_object:move(x, y) | ||
2040 | |||
2041 | Gets (and optionally sets) this objects position. | ||
2042 | |||
2043 | Wraps evas_object_move(). | ||
2044 | |||
2045 | @param x The new X coordinate. | ||
2046 | @param y The new Y coordinate. | ||
2047 | |||
2048 | Note that the arguments are optional, without them this function just queries | ||
2049 | the current values. The arguments can be separate values, or named fields in a | ||
2050 | table. | ||
2051 | |||
2052 | @return A table with these fields: | ||
2053 | - integer x: X coordinate. | ||
2054 | - integer x: Y coordinate. | ||
2055 | */ | ||
2056 | static int | ||
2057 | _elua_move(lua_State *L) // Stack usage [-(4|6), +(5|7), em] | ||
2058 | { | ||
2059 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2060 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2061 | Evas_Coord ox, oy; | ||
2062 | int x, y; | ||
2063 | |||
2064 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2065 | evas_object_geometry_get(elo->evas_obj, &ox, &oy, NULL, NULL); | ||
2066 | if (_elua_scan_params(L, 2, "%x %y", &x, &y) > 0) | ||
2067 | { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e] | ||
2068 | if ((x != (ox - obj->ed->x)) || (y != (oy - obj->ed->y))) | ||
2069 | { | ||
2070 | evas_object_move(elo->evas_obj, | ||
2071 | obj->ed->x + x, | ||
2072 | obj->ed->y + y); | ||
2073 | evas_object_geometry_get(elo->evas_obj, &ox, &oy, NULL, NULL); | ||
2074 | } | ||
2075 | elo->x = ox - obj->ed->x; | ||
2076 | elo->y = oy - obj->ed->y; | ||
2077 | } | ||
2078 | _elua_ret(L, "%x %y", elo->x, elo->y); | ||
2079 | // Stack usage [-4, +5, em] | ||
2080 | return 1; | ||
2081 | } | ||
2082 | |||
2083 | /** | ||
2084 | @page luaref | ||
2085 | @subsubsection evas_pos evas_object:pos(x, y) | ||
2086 | |||
2087 | An alias for evas_object:move(). | ||
2088 | */ | ||
2089 | static int | ||
2090 | _elua_pos(lua_State *L) // Stack usage [-(4|6), +(5|7), em] | ||
2091 | { | ||
2092 | return _elua_move(L); | ||
2093 | } | ||
2094 | |||
2095 | /** | ||
2096 | @page luaref | ||
2097 | @subsubsection evas_resize evas_object:resize(w, h) | ||
2098 | |||
2099 | Gets (and optionally sets) this objects size. | ||
2100 | |||
2101 | Wraps evas_object_resize(). | ||
2102 | |||
2103 | @param w The new width. | ||
2104 | @param h The new height. | ||
2105 | |||
2106 | Note that the arguments are optional, without them this function just queries | ||
2107 | the current values. The arguments can be separate values, or named fields in a | ||
2108 | table. | ||
2109 | |||
2110 | @return A table with these fields: | ||
2111 | - integer w: Width. | ||
2112 | - integer w: Height. | ||
2113 | */ | ||
2114 | static int | ||
2115 | _elua_resize(lua_State *L) // Stack usage [-(4|6), +(5|7), em] | ||
2116 | { | ||
2117 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2118 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2119 | Evas_Coord ow, oh; | ||
2120 | int w, h; | ||
2121 | |||
2122 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2123 | evas_object_geometry_get(elo->evas_obj, NULL, NULL, &ow, &oh); | ||
2124 | if (_elua_scan_params(L, 2, "%w %h", &w, &h) > 0) | ||
2125 | { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e] | ||
2126 | if ((w != ow) || (h != oh)) | ||
2127 | { | ||
2128 | evas_object_resize(elo->evas_obj, w, h); | ||
2129 | evas_object_geometry_get(elo->evas_obj, NULL, NULL, &ow, &oh); | ||
2130 | } | ||
2131 | } | ||
2132 | _elua_ret(L, "%w %h", ow, oh); | ||
2133 | // Stack usage [-4, +5, em] | ||
2134 | return 1; | ||
2135 | } | ||
2136 | |||
2137 | /** | ||
2138 | @page luaref | ||
2139 | @subsubsection evas_size evas_object:size() | ||
2140 | |||
2141 | An alias for evas_object:resize(). | ||
2142 | */ | ||
2143 | static int | ||
2144 | _elua_size(lua_State *L) // Stack usage [-(4|6), +(5|7), em] | ||
2145 | { | ||
2146 | return _elua_resize(L); | ||
2147 | } | ||
2148 | |||
2149 | //------------- | ||
2150 | /** | ||
2151 | @page luaref | ||
2152 | @subsubsection evas_clip evas_object:clip(evas_object2) | ||
2153 | |||
2154 | Get (and optionally set) the object that clips this object. | ||
2155 | |||
2156 | Note that the argument is optional, without it this function just queries the | ||
2157 | current value. | ||
2158 | |||
2159 | Wraps evas_object_clip_set(). | ||
2160 | |||
2161 | @param evas_object2 A reference to the object to clip this object with. | ||
2162 | |||
2163 | @returns A reference to the object clipping this object, if any. | ||
2164 | */ | ||
2165 | static int | ||
2166 | _elua_clip(lua_State *L) // Stack usage [-3, +4, -] | ||
2167 | { | ||
2168 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2169 | Edje_Lua_Evas_Object *elo2, *elo = (Edje_Lua_Evas_Object *)obj; | ||
2170 | Evas_Object *o; | ||
2171 | int n; | ||
2172 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2173 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
2174 | if (n == 2) | ||
2175 | { | ||
2176 | Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); // Stack usage [-0, +0, -] | ||
2177 | elo2 = (Edje_Lua_Evas_Object *)obj2; | ||
2178 | if (!_elua_isa(obj2, _elua_evas_meta)) return 0; | ||
2179 | evas_object_clip_set(elo->evas_obj, elo2->evas_obj); | ||
2180 | } | ||
2181 | o = evas_object_clip_get(elo->evas_obj); | ||
2182 | if (!o) return 0; | ||
2183 | if (!(elo2 = evas_object_data_get(o, ELO))) return 0; | ||
2184 | _elua_ref_get(L, elo2); // Stack usage [-3, +4, -] | ||
2185 | return 1; | ||
2186 | } | ||
2187 | |||
2188 | /** | ||
2189 | @page luaref | ||
2190 | @subsubsection evas_clipees evas_object:clipees() | ||
2191 | |||
2192 | Gets the list of objects this objects clips. | ||
2193 | |||
2194 | Wraps evas_object_clipees_get(). | ||
2195 | |||
2196 | @return A table, that holds all the objects this clips, if any, | ||
2197 | otherwise an empty table. | ||
2198 | */ | ||
2199 | static int | ||
2200 | _elua_clipees(lua_State *L) // Stack usage [-0, +1, me] plus [-5, +5] for each clipee. | ||
2201 | { | ||
2202 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2203 | Edje_Lua_Evas_Object *elo2, *elo = (Edje_Lua_Evas_Object *)obj; | ||
2204 | Eina_List *list, *l; | ||
2205 | Evas_Object *o; | ||
2206 | int n = 0; | ||
2207 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2208 | list = (Eina_List *)evas_object_clipees_get(elo->evas_obj); | ||
2209 | lua_newtable(L); // Stack usage [-0, +1, m] | ||
2210 | EINA_LIST_FOREACH(list, l, o) | ||
2211 | { | ||
2212 | if (!(elo2 = evas_object_data_get(o, ELO))) continue; | ||
2213 | lua_pushinteger(L, n + 1); // Stack usage [-0, +1, -] | ||
2214 | _elua_ref_get(L, elo2); // Stack usage [-3, +4, -] | ||
2215 | lua_settable(L, -3); // Stack usage [-2, +0, e] | ||
2216 | n++; | ||
2217 | } | ||
2218 | return 1; | ||
2219 | } | ||
2220 | |||
2221 | /** | ||
2222 | @page luaref | ||
2223 | @subsubsection evas_unclip evas_object:unclip() | ||
2224 | |||
2225 | Remove any clipping on this object. | ||
2226 | |||
2227 | Wraps evas_object_clip_unset(). | ||
2228 | */ | ||
2229 | static int | ||
2230 | _elua_unclip(lua_State *L) // Stack usage [-0, +0, -] | ||
2231 | { | ||
2232 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2233 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2234 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2235 | evas_object_clip_unset(elo->evas_obj); | ||
2236 | return 0; | ||
2237 | } | ||
2238 | |||
2239 | //------------- | ||
2240 | /** | ||
2241 | @page luaref | ||
2242 | @subsubsection evas_type evas_object:type() | ||
2243 | |||
2244 | Get the type of this object. See the documentation of the evas_object_type_get() | ||
2245 | C function for details. | ||
2246 | |||
2247 | Wraps evas_object_type_get(). | ||
2248 | |||
2249 | @return A string with this objects type in it. | ||
2250 | */ | ||
2251 | static int | ||
2252 | _elua_type(lua_State *L) // Stack usage [-0, +1, m] | ||
2253 | { | ||
2254 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2255 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2256 | const char *t; | ||
2257 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2258 | t = evas_object_type_get(elo->evas_obj); | ||
2259 | if (!t) return 0; | ||
2260 | lua_pushstring(L, t); // Stack usage [-0, +1, m] | ||
2261 | return 1; | ||
2262 | } | ||
2263 | |||
2264 | //------------- | ||
2265 | /** | ||
2266 | @page luaref | ||
2267 | @subsubsection evas_pass evas_object:pass(pass) | ||
2268 | |||
2269 | Get (and optionally set) whether this object ignores events, passing them to the | ||
2270 | next object underneath it. | ||
2271 | |||
2272 | Wraps evas_object_pass_events_set(). | ||
2273 | |||
2274 | @param pass A boolean saying if this object passes events. | ||
2275 | |||
2276 | Note that the argument is optional, without it this function just queries the | ||
2277 | current value. | ||
2278 | |||
2279 | @return A boolean saying if this object passes events. | ||
2280 | */ | ||
2281 | static int | ||
2282 | _elua_pass(lua_State *L) // Stack usage [-0, +1, -] | ||
2283 | { | ||
2284 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2285 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2286 | int n; | ||
2287 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2288 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
2289 | if (n == 2) | ||
2290 | { | ||
2291 | if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -] | ||
2292 | { | ||
2293 | evas_object_pass_events_set(elo->evas_obj, lua_toboolean(L, 2)); | ||
2294 | // Stack usage [-0, +0, -] | ||
2295 | } | ||
2296 | } | ||
2297 | lua_pushboolean(L, evas_object_pass_events_get(elo->evas_obj)); | ||
2298 | // Stack usage [-0, +1, -] | ||
2299 | return 1; | ||
2300 | } | ||
2301 | |||
2302 | /** | ||
2303 | @page luaref | ||
2304 | @subsubsection evas_precise evas_object:precise(precise) | ||
2305 | |||
2306 | Get (and optionally set) whether to use precise (usually expensive) point | ||
2307 | collision detection for this object. | ||
2308 | |||
2309 | Wraps evas_object_precise_is_inside_set(). | ||
2310 | |||
2311 | @param precise A boolean saying if this object is precisely detected. | ||
2312 | |||
2313 | Note that the argument is optional, without it this function just queries the | ||
2314 | current value. | ||
2315 | |||
2316 | @return A boolean saying if this object is precisely detected. | ||
2317 | */ | ||
2318 | static int | ||
2319 | _elua_precise(lua_State *L) // Stack usage [-0, +1, -] | ||
2320 | { | ||
2321 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2322 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2323 | int n; | ||
2324 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2325 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
2326 | if (n == 2) | ||
2327 | { | ||
2328 | if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -] | ||
2329 | { | ||
2330 | evas_object_precise_is_inside_set(elo->evas_obj, lua_toboolean(L, 2)); | ||
2331 | // Stack usage [-0, +0, -] | ||
2332 | } | ||
2333 | } | ||
2334 | lua_pushboolean(L, evas_object_precise_is_inside_get(elo->evas_obj)); | ||
2335 | // Stack usage [-0, +1, -] | ||
2336 | return 1; | ||
2337 | } | ||
2338 | |||
2339 | /** | ||
2340 | @page luaref | ||
2341 | @subsubsection evas_repeat evas_object:repeat(repeat) | ||
2342 | |||
2343 | Get (and optionally set) whether this object repeats events. | ||
2344 | |||
2345 | Wraps evas_object_repeat_events_set(). | ||
2346 | |||
2347 | @param repeat A boolean saying if this object repeats events to lower objects. | ||
2348 | |||
2349 | Note that the argument is optional, without it this function just queries the | ||
2350 | current value. | ||
2351 | |||
2352 | @return A boolean saying if this object repeats events. | ||
2353 | */ | ||
2354 | static int | ||
2355 | _elua_repeat(lua_State *L) // Stack usage [-0, +1, -] | ||
2356 | { | ||
2357 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2358 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2359 | int n; | ||
2360 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2361 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
2362 | if (n == 2) | ||
2363 | { | ||
2364 | if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -] | ||
2365 | { | ||
2366 | evas_object_repeat_events_set(elo->evas_obj, lua_toboolean(L, 2)); | ||
2367 | // Stack usage [-0, +0, -] | ||
2368 | } | ||
2369 | } | ||
2370 | lua_pushboolean(L, evas_object_repeat_events_get(elo->evas_obj)); | ||
2371 | // Stack usage [-0, +1, -] | ||
2372 | return 1; | ||
2373 | } | ||
2374 | |||
2375 | //------------- | ||
2376 | /** | ||
2377 | @page luaref | ||
2378 | @subsubsection evas_colour evas_object:color(r, g, b, a) | ||
2379 | |||
2380 | Gets (and optionally sets) this objects colour. | ||
2381 | |||
2382 | Wraps evas_object_color_set(). | ||
2383 | |||
2384 | @param r The new red value. | ||
2385 | @param g The new green value. | ||
2386 | @param b The new blue value. | ||
2387 | @param a The new alpha value. | ||
2388 | |||
2389 | Note that the arguments are optional, without them this function just queries | ||
2390 | the current values. The arguments can be separate values, or named fields in a | ||
2391 | table. | ||
2392 | |||
2393 | @return A table with these fields: | ||
2394 | - integer r: The red value. | ||
2395 | - integer g: The green value. | ||
2396 | - integer b: The blue value. | ||
2397 | - integer a: The alpha value. | ||
2398 | */ | ||
2399 | static int | ||
2400 | _elua_color(lua_State *L) // Stack usage [-(8|12), +(9|13), em] | ||
2401 | { | ||
2402 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2403 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2404 | int r, g, b, a; | ||
2405 | |||
2406 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2407 | if (_elua_scan_params(L, 2, "%r %g %b %a", &r, &g, &b, &a) > 0) | ||
2408 | { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e] | ||
2409 | _elua_color_fix(&r, &g, &b, &a); | ||
2410 | evas_object_color_set(elo->evas_obj, r, g, b, a); | ||
2411 | } | ||
2412 | evas_object_color_get(elo->evas_obj, &r, &g, &b, &a); | ||
2413 | _elua_ret(L, "%r %g %b %a", r, g, b, a); | ||
2414 | // Stack usage [-8, +9, em] | ||
2415 | return 1; | ||
2416 | } | ||
2417 | |||
2418 | //------------- | ||
2419 | /** | ||
2420 | @page luaref | ||
2421 | @subsubsection evas_map evas_object:map(map) | ||
2422 | |||
2423 | Attach a map to this object. | ||
2424 | |||
2425 | Wraps evas_object_map_set(). | ||
2426 | |||
2427 | @param map The map to attach. | ||
2428 | |||
2429 | @since 1.1.0 | ||
2430 | */ | ||
2431 | static int | ||
2432 | _elua_obj_map(lua_State *L) // Stack usage [-0, +0, -] | ||
2433 | { | ||
2434 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2435 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2436 | Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); // Stack usage [-0, +0, -] | ||
2437 | Edje_Lua_Map *elm = (Edje_Lua_Map *)obj2; | ||
2438 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2439 | if (!_elua_isa(obj2, _elua_evas_map_meta)) return 0; | ||
2440 | |||
2441 | evas_object_map_set(elo->evas_obj, elm->map); | ||
2442 | |||
2443 | return 0; | ||
2444 | } | ||
2445 | |||
2446 | /** | ||
2447 | @page luaref | ||
2448 | @subsubsection evas_map_enable evas_object:map_enable(enable) | ||
2449 | |||
2450 | Enable or disable the map attached to this object. | ||
2451 | |||
2452 | Wraps evas_object_map_enable_set(). | ||
2453 | |||
2454 | @param enable A booleon that controls if the attached map is enabled or not. | ||
2455 | |||
2456 | @return A boolean reflecting the map enabled status of this object. | ||
2457 | |||
2458 | @since 1.1.0 | ||
2459 | */ | ||
2460 | static int | ||
2461 | _elua_obj_map_enable(lua_State *L) // Stack usage [-0, +1, -] | ||
2462 | { | ||
2463 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2464 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2465 | int n; | ||
2466 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2467 | |||
2468 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
2469 | if (n == 2) | ||
2470 | { | ||
2471 | evas_object_map_enable_set(elo->evas_obj, lua_toboolean(L, 2)); | ||
2472 | // Stack usage [-0, +0, -] | ||
2473 | } | ||
2474 | lua_pushboolean(L, evas_object_map_enable_get(elo->evas_obj)); | ||
2475 | // Stack usage [-0, +1, -] | ||
2476 | return 1; | ||
2477 | } | ||
2478 | |||
2479 | /** | ||
2480 | @page luaref | ||
2481 | @subsubsection evas_map_source evas_object:map_source(object) | ||
2482 | |||
2483 | Sets the object as the map source for this object. | ||
2484 | |||
2485 | Wraps evas_object_map_source_set(). | ||
2486 | |||
2487 | @param object The map source object. | ||
2488 | |||
2489 | @return A userdata reference to the current map source object. | ||
2490 | |||
2491 | @since 1.1.0 | ||
2492 | */ | ||
2493 | static int | ||
2494 | _elua_obj_map_source(lua_State *L) // Stack usage [-3, +4, -] | ||
2495 | { | ||
2496 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2497 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2498 | Evas_Object *o; | ||
2499 | Edje_Lua_Evas_Object *elo2; | ||
2500 | int n; | ||
2501 | |||
2502 | if (!_elua_isa(obj, _elua_evas_meta)) return 0; | ||
2503 | |||
2504 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
2505 | if (n == 2) | ||
2506 | { | ||
2507 | Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); // Stack usage [-0, +0, -] | ||
2508 | const Edje_Lua_Evas_Object *source = (Edje_Lua_Evas_Object *)obj2; | ||
2509 | |||
2510 | if (!_elua_isa(obj2, _elua_evas_meta)) return 0; | ||
2511 | evas_object_map_source_set(elo->evas_obj, source->evas_obj); | ||
2512 | } | ||
2513 | |||
2514 | if (!(o = evas_object_map_source_get(elo->evas_obj))) return 0; | ||
2515 | if (!(elo2 = evas_object_data_get(o, ELO))) return 0; | ||
2516 | _elua_ref_get(L, elo2); // Stack usage [-3, +4, -] | ||
2517 | |||
2518 | return 1; | ||
2519 | } | ||
2520 | |||
2521 | //------------- | ||
2522 | //------------- | ||
2523 | /** | ||
2524 | @page luaref | ||
2525 | @subsection ecore_animator Ecore animator class. | ||
2526 | |||
2527 | The lua ecore animator class includes functions for dealing with ecore animator objects. | ||
2528 | The ecore animator objects must have been previously created by lua using the lua | ||
2529 | edje object creation function edje:animator() or edje:transition(). | ||
2530 | |||
2531 | In the following, "animator_object" is a place holder for any lua variable that | ||
2532 | holds a reference to an ecore animator object. | ||
2533 | */ | ||
2534 | static const char *_elua_ecore_animator_api = "ecore_animator"; | ||
2535 | static const struct luaL_reg _elua_ecore_animator_funcs [] = | ||
2536 | { | ||
2537 | {NULL, NULL} // end | ||
2538 | }; | ||
2539 | |||
2540 | //------------- | ||
2541 | //------------- | ||
2542 | /** | ||
2543 | @page luaref | ||
2544 | @subsection ecore_timer Ecore timer class. | ||
2545 | |||
2546 | The lua ecore timer class includes functions for dealing with ecore timer objects. | ||
2547 | The ecore timer objects must have been previously created by lua using the lua | ||
2548 | edje object creation function edje:timer(). | ||
2549 | |||
2550 | In the following, "timer_object" is a place holder for any lua variable that | ||
2551 | holds a reference to an ecore timer object. | ||
2552 | */ | ||
2553 | |||
2554 | static const char *_elua_ecore_timer_api = "ecore_timer"; | ||
2555 | static const struct luaL_reg _elua_ecore_timer_funcs [] = | ||
2556 | { | ||
2557 | {NULL, NULL} // end | ||
2558 | }; | ||
2559 | |||
2560 | //------------- | ||
2561 | //------------- | ||
2562 | /** | ||
2563 | @page luaref | ||
2564 | @subsection evas_edje Evas edje class. | ||
2565 | |||
2566 | The lua evas edje class includes functions for dealing with evas edje objects. | ||
2567 | The evas edje objects must have been previously created by lua using the lua | ||
2568 | edje object creation function edje:edje(). | ||
2569 | |||
2570 | In the following, "edje_object" is a place holder for any lua variable that | ||
2571 | holds a reference to an evas edje object. NOT the edje class specified earlier | ||
2572 | though. | ||
2573 | |||
2574 | @since 1.1.0 | ||
2575 | */ | ||
2576 | |||
2577 | static int _elua_edje_file(lua_State *L); | ||
2578 | |||
2579 | static const char *_elua_evas_edje_api = "evas_edje"; | ||
2580 | static const char *_elua_evas_edje_parent = "evas_edje_parent"; | ||
2581 | static const struct luaL_reg _elua_evas_edje_funcs [] = | ||
2582 | { | ||
2583 | {"file", _elua_edje_file}, // get or set edje file and group | ||
2584 | |||
2585 | {NULL, NULL} // end | ||
2586 | }; | ||
2587 | |||
2588 | /** | ||
2589 | @page luaref | ||
2590 | @subsubsection edje_file edje_object:file(file, group) | ||
2591 | |||
2592 | Load an edje group into this edje object. | ||
2593 | |||
2594 | Wraps edje_object_file_set(). | ||
2595 | |||
2596 | @param file An edje file name (ignored, sandboxed to the file this lua script is in). | ||
2597 | @param group The group within the edje file to be loaded. | ||
2598 | |||
2599 | Note that the arguments are optional, without them this function just queries | ||
2600 | the current values. The arguments can be separate values, or named fields in a | ||
2601 | table. The file argument is optional, and ignored anyway. | ||
2602 | |||
2603 | @return A table with these fields: | ||
2604 | - string file: The name of the edje file this edje's group is loaded from. | ||
2605 | - string group: The name of the group this edje is loaded from. | ||
2606 | |||
2607 | @since 1.1.0 | ||
2608 | */ | ||
2609 | static int | ||
2610 | _elua_edje_file(lua_State *L) // Stack usage [-(4|6), +(5|7), em] | ||
2611 | { | ||
2612 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2613 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2614 | const char *file = NULL, *group = NULL; | ||
2615 | int n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
2616 | |||
2617 | if (!_elua_isa(obj, _elua_evas_edje_meta)) return 0; | ||
2618 | |||
2619 | n = _elua_scan_params(L, 2, "$file $group", &file, &group); | ||
2620 | // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e] | ||
2621 | if (0 >= n) | ||
2622 | { | ||
2623 | file = (char *) obj->ed->file->path; | ||
2624 | group = (char *) lua_tostring(L, 2); // Stack usage [-0, +0, m] | ||
2625 | n = 2; | ||
2626 | } | ||
2627 | |||
2628 | if (1 < n) | ||
2629 | { | ||
2630 | // Sandbox lua - Only allow access to groups within the same file. | ||
2631 | // By the simple expedient of completely ignoring what file was requested. | ||
2632 | file = (char *) obj->ed->file->path; | ||
2633 | if (!edje_object_file_set(elo->evas_obj, file, group)) | ||
2634 | { | ||
2635 | Edje_Load_Error err = edje_object_load_error_get(elo->evas_obj); | ||
2636 | |||
2637 | switch (err) | ||
2638 | { | ||
2639 | case EDJE_LOAD_ERROR_NONE : LE("Edje file loading errer %s %s - no error happened, but you should not see this.\n", obj->ed->file->path, group); break; | ||
2640 | case EDJE_LOAD_ERROR_GENERIC : LE("Edje file loading errer %s %s - generic error.\n", obj->ed->file->path, group); break; | ||
2641 | case EDJE_LOAD_ERROR_DOES_NOT_EXIST : LE("Edje file loading errer %s %s - file does not exist.\n", obj->ed->file->path, group); break; | ||
2642 | case EDJE_LOAD_ERROR_PERMISSION_DENIED : LE("Edje file loading errer %s %s - permission denied reading the file.\n", obj->ed->file->path, group); break; | ||
2643 | case EDJE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED : LE("Edje file loading errer %s %s - resource allocation failed.\n", obj->ed->file->path, group); break; | ||
2644 | case EDJE_LOAD_ERROR_CORRUPT_FILE : LE("Edje file loading errer %s %s - corrupt file.\n", obj->ed->file->path, group); break; | ||
2645 | case EDJE_LOAD_ERROR_UNKNOWN_FORMAT : LE("Edje file loading errer %s %s - unknown file format.\n", obj->ed->file->path, group); break; | ||
2646 | case EDJE_LOAD_ERROR_INCOMPATIBLE_FILE : LE("Edje file loading errer %s %s - incompatible file.\n", obj->ed->file->path, group); break; | ||
2647 | case EDJE_LOAD_ERROR_UNKNOWN_COLLECTION : LE("Edje file loading errer %s %s - unknown group.\n", obj->ed->file->path, group); break; | ||
2648 | case EDJE_LOAD_ERROR_RECURSIVE_REFERENCE : LE("Edje file loading errer %s %s - recursive reference in group.\n", obj->ed->file->path, group); break; | ||
2649 | } | ||
2650 | } | ||
2651 | } | ||
2652 | edje_object_file_get(elo->evas_obj, &file, &group); | ||
2653 | _elua_ret(L, "$file $group", file, group); | ||
2654 | // Stack usage [-4, +5, em] | ||
2655 | return 1; | ||
2656 | } | ||
2657 | |||
2658 | //------------- | ||
2659 | //------------- | ||
2660 | /** | ||
2661 | @page luaref | ||
2662 | @subsection evas_image Evas image class. | ||
2663 | |||
2664 | The lua evas image class includes functions for dealing with evas image objects. | ||
2665 | The evas image objects must have been previously created by lua using the lua | ||
2666 | image object creation function edje:image(). | ||
2667 | |||
2668 | In the following, "image_object" is a place holder for any lua variable that | ||
2669 | holds a reference to an evas image object. | ||
2670 | |||
2671 | @since 1.1.0 | ||
2672 | */ | ||
2673 | |||
2674 | static int _elua_image_fill(lua_State *L); | ||
2675 | static int _elua_image_filled(lua_State *L); | ||
2676 | static int _elua_image_image(lua_State *L); | ||
2677 | |||
2678 | static const char *_elua_evas_image_api = "evas_image"; | ||
2679 | static const char *_elua_evas_image_parent = "evas_image_parent"; | ||
2680 | static const struct luaL_reg _elua_evas_image_funcs [] = | ||
2681 | { | ||
2682 | {"fill", _elua_image_fill}, // get or set the fill parameters | ||
2683 | {"filled", _elua_image_filled}, // get or set the filled state (overrides fill()) | ||
2684 | {"image", _elua_image_image}, // get or set image | ||
2685 | |||
2686 | {NULL, NULL} // end | ||
2687 | }; | ||
2688 | |||
2689 | /** | ||
2690 | @page luaref | ||
2691 | @subsubsection image_fill image_object:fill(x, y, w, h) | ||
2692 | |||
2693 | Gets (and optionally sets) how to fill this image's drawing rectangle given the | ||
2694 | (real) image bound to it. | ||
2695 | |||
2696 | Wraps evas_object_image_fill_set(). | ||
2697 | |||
2698 | @param x The x coordinate (from the top left corner of the bound image) to start drawing from. | ||
2699 | @param y The y coordinate (from the top left corner of the bound image) to start drawing from. | ||
2700 | @param w The width the bound image will be displayed at. | ||
2701 | @param h The height the bound image will be displayed at. | ||
2702 | |||
2703 | Note that the arguments are optional, without them this function just queries | ||
2704 | the current values. The arguments can be separate values, or named fields in a | ||
2705 | table. | ||
2706 | |||
2707 | @return A table with these fields: | ||
2708 | - integer x: The x coordinate (from the top left corner of the bound image) to start drawing from. | ||
2709 | - integer y: The y coordinate (from the top left corner of the bound image) to start drawing from. | ||
2710 | - integer w: The width the bound image will be displayed at. | ||
2711 | - integer h: The height the bound image will be displayed at. | ||
2712 | |||
2713 | @since 1.1.0 | ||
2714 | */ | ||
2715 | static int | ||
2716 | _elua_image_fill(lua_State *L) // Stack usage [-(8|12), +(9|13), em] | ||
2717 | { | ||
2718 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2719 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2720 | Evas_Coord x, y, w, h; | ||
2721 | |||
2722 | if (!_elua_isa(obj, _elua_evas_image_meta)) return 0; | ||
2723 | |||
2724 | if (_elua_scan_params(L, 2, "%x %y %w %h", &x, &y, &w, &h) > 0) | ||
2725 | { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e] | ||
2726 | evas_object_image_fill_set(elo->evas_obj, x, y, w, h); | ||
2727 | } | ||
2728 | evas_object_image_fill_get(elo->evas_obj, &x, &y, &w, &h); | ||
2729 | _elua_ret(L, "%x %y %w %h", x, y, w, h); | ||
2730 | // Stack usage [-8, +9, em] | ||
2731 | return 1; | ||
2732 | } | ||
2733 | |||
2734 | /** | ||
2735 | @page luaref | ||
2736 | @subsubsection image_filled image_object:filled(filled) | ||
2737 | |||
2738 | Get (and optionally set) whether this image fills the object. | ||
2739 | |||
2740 | Wraps evas_object_image_filled_set(). | ||
2741 | |||
2742 | @param filled A boolean saying if this image fills the object. | ||
2743 | |||
2744 | Note that the argument is optional, without it this function just queries the | ||
2745 | current value. | ||
2746 | |||
2747 | @return A boolean saying if this image fills the object. | ||
2748 | |||
2749 | @since 1.1.0 | ||
2750 | */ | ||
2751 | static int | ||
2752 | _elua_image_filled(lua_State *L) // Stack usage [-0, +0, -] | ||
2753 | { | ||
2754 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2755 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2756 | int n; | ||
2757 | |||
2758 | if (!_elua_isa(obj, _elua_evas_image_meta)) return 0; | ||
2759 | |||
2760 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
2761 | if (n == 2) | ||
2762 | { | ||
2763 | evas_object_image_filled_set(elo->evas_obj, lua_toboolean(L, 2)); | ||
2764 | // Stack usage [-0, +0, -] | ||
2765 | } | ||
2766 | lua_pushboolean(L, evas_object_image_filled_get(elo->evas_obj)); | ||
2767 | // Stack usage [-0, +0, -] | ||
2768 | return 1; | ||
2769 | } | ||
2770 | |||
2771 | /** | ||
2772 | @page luaref | ||
2773 | @subsubsection image_image image_object:image(file, key) | ||
2774 | |||
2775 | Load an image into this edje object. | ||
2776 | |||
2777 | Wraps evas_object_image_file_set(). | ||
2778 | |||
2779 | @param file An edje file name (ignored, sandboxed to the file this lua script is in). | ||
2780 | @param group The name of an image. | ||
2781 | |||
2782 | Note that the arguments are optional, without them this function just queries | ||
2783 | the current values. The arguments can be separate values, or named fields in a | ||
2784 | table. The file argument is optional, and ignored anyway. | ||
2785 | |||
2786 | @return A table with these fields: | ||
2787 | - string file: The name of the edje file the image is loaded from. | ||
2788 | - string key: The name of the image within the edje file. | ||
2789 | |||
2790 | @since 1.1.0 | ||
2791 | */ | ||
2792 | static int | ||
2793 | _elua_image_image(lua_State *L) // Stack usage [-(4|6), +(5|7), em] | ||
2794 | { | ||
2795 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2796 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2797 | const char *file = NULL, *key = NULL; | ||
2798 | int n, id = -1; | ||
2799 | |||
2800 | if (!_elua_isa(obj, _elua_evas_image_meta)) return 0; | ||
2801 | |||
2802 | n = _elua_scan_params(L, 2, "$file $key", &file, &key); | ||
2803 | // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e] | ||
2804 | if (0 >= n) | ||
2805 | { | ||
2806 | file = (char *) obj->ed->file->path; | ||
2807 | key = (char *) lua_tostring(L, 2); // Stack usage [-0, +0, m] | ||
2808 | n = 2; | ||
2809 | } | ||
2810 | |||
2811 | if (1 < n) | ||
2812 | { | ||
2813 | if (obj->ed->file->image_dir) | ||
2814 | { | ||
2815 | Edje_Image_Directory_Entry *de; | ||
2816 | unsigned int i; | ||
2817 | char *name; | ||
2818 | |||
2819 | /* Image name */ | ||
2820 | if ((name = strrchr(key, '/'))) name++; | ||
2821 | else name = (char *)key; | ||
2822 | |||
2823 | /* Loop through image directory to find if image exists */ | ||
2824 | for (i = 0; i < obj->ed->file->image_dir->entries_count; ++i) | ||
2825 | { | ||
2826 | de = obj->ed->file->image_dir->entries + i; | ||
2827 | |||
2828 | if (de->entry) | ||
2829 | { | ||
2830 | if (strcmp(name, de->entry) == 0) | ||
2831 | { | ||
2832 | char buf[32]; | ||
2833 | |||
2834 | id = i; | ||
2835 | // This is copied from _edje_image_recalc_apply()), dunno if it provides any benefit over sprintf(). | ||
2836 | /* Replace snprint("edje/images/%i") == memcpy + itoa */ | ||
2837 | #define IMAGES "edje/images/" | ||
2838 | memcpy(buf, IMAGES, strlen(IMAGES)); | ||
2839 | eina_convert_itoa(id, buf + strlen(IMAGES)); /* No need to check length as 2³² need only 10 characters. */ | ||
2840 | evas_object_image_file_set(elo->evas_obj, obj->ed->file->path, buf); | ||
2841 | break; | ||
2842 | } | ||
2843 | } | ||
2844 | } | ||
2845 | } | ||
2846 | |||
2847 | /* Sandbox lua - Only allow access to images within the same edje file. I'm not so sure we need this level of sandboxing though. So leaving it here, just in case. | ||
2848 | if (-1 == id) | ||
2849 | { | ||
2850 | LI("Image %s not found in our edje file, trying external image file %s.\n", key, file); | ||
2851 | evas_object_image_file_set(elo->evas_obj, file, key); | ||
2852 | } | ||
2853 | */ | ||
2854 | } | ||
2855 | evas_object_image_file_get(elo->evas_obj, &file, &key); | ||
2856 | _elua_ret(L, "$file $key", file, key); | ||
2857 | // Stack usage [-4, +5, em] | ||
2858 | return 1; | ||
2859 | } | ||
2860 | |||
2861 | //------------- | ||
2862 | //------------- | ||
2863 | /** | ||
2864 | @page luaref | ||
2865 | @subsection evas_line Evas line class. | ||
2866 | |||
2867 | The lua evas line class includes functions for dealing with evas line objects. | ||
2868 | The evas line objects must have been previously created by lua using the lua | ||
2869 | line object creation function edje:line(). | ||
2870 | |||
2871 | In the following, "line_object" is a place holder for any lua variable that | ||
2872 | holds a reference to an evas line object. | ||
2873 | |||
2874 | @since 1.1.0 | ||
2875 | */ | ||
2876 | |||
2877 | static int _elua_line_xy(lua_State *L); | ||
2878 | |||
2879 | static const char *_elua_evas_line_api = "evas_line"; | ||
2880 | static const char *_elua_evas_line_parent = "evas_line_parent"; | ||
2881 | static const struct luaL_reg _elua_evas_line_funcs [] = | ||
2882 | { | ||
2883 | {"xy", _elua_line_xy}, // get or set line coords | ||
2884 | |||
2885 | {NULL, NULL} // end | ||
2886 | }; | ||
2887 | |||
2888 | /** | ||
2889 | @page luaref | ||
2890 | @subsubsection line_xy line_object:xy(x1, y1, x2, y2) | ||
2891 | |||
2892 | Sets the end points of this line. | ||
2893 | |||
2894 | Wraps evas_object_line_xy_set(). | ||
2895 | |||
2896 | @param x1 The X coordinate of the first line end. | ||
2897 | @param y1 The Y coordinate of the first line end. | ||
2898 | @param x2 The X coordinate of the other line end. | ||
2899 | @param y2 The Y coordinate of the other line end. | ||
2900 | |||
2901 | Note that the arguments are optional, without them this function just queries | ||
2902 | the current values. The arguments can be separate values, or named fields in a | ||
2903 | table. | ||
2904 | |||
2905 | @return A table with these fields: | ||
2906 | - integer x1: The X coordinate of the first line end. | ||
2907 | - integer y1: The Y coordinate of the first line end. | ||
2908 | - integer x2: The X coordinate of the other line end. | ||
2909 | - integer y2: The Y coordinate of the other line end. | ||
2910 | |||
2911 | @since 1.1.0 | ||
2912 | */ | ||
2913 | static int _elua_line_xy(lua_State *L) // Stack usage [-(8|12), +(9|13), em] | ||
2914 | { | ||
2915 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2916 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
2917 | Evas_Coord x1, y1, x2, y2; | ||
2918 | |||
2919 | if (!_elua_isa(obj, _elua_evas_line_meta)) return 0; | ||
2920 | |||
2921 | if (_elua_scan_params(L, 2, "%x1 %y1 %x2 %y2", &x1, &y1, &x2, &y2) > 0) | ||
2922 | { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e] | ||
2923 | evas_object_line_xy_set(elo->evas_obj, x1, y1, x2, y2); | ||
2924 | } | ||
2925 | evas_object_line_xy_get(elo->evas_obj, &x1, &y1, &x2, &y2); | ||
2926 | _elua_ret(L, "%x1 %y1 %x2 %y2", x1, y1, x2, y2); | ||
2927 | // Stack usage [-8, +9, em] | ||
2928 | return 1; | ||
2929 | } | ||
2930 | |||
2931 | //------------- | ||
2932 | //------------- | ||
2933 | /** | ||
2934 | @page luaref | ||
2935 | @subsection evas_object_map Evas map class. | ||
2936 | |||
2937 | The lua evas map class includes functions for dealing with evas map objects. | ||
2938 | The evas map objects must have been previously created by lua using the lua | ||
2939 | map object creation function edje:map(). | ||
2940 | |||
2941 | In the following, "map_object" is a place holder for any lua variable that | ||
2942 | holds a reference to an evas map object. | ||
2943 | |||
2944 | @since 1.1.0 | ||
2945 | */ | ||
2946 | |||
2947 | static int _elua_map_alpha(lua_State *L); | ||
2948 | static int _elua_map_clockwise(lua_State *L); | ||
2949 | static int _elua_map_colour(lua_State *L); | ||
2950 | static int _elua_map_coord(lua_State *L); | ||
2951 | static int _elua_map_lighting(lua_State *L); | ||
2952 | static int _elua_map_perspective(lua_State *L); | ||
2953 | static int _elua_map_populate(lua_State *L); | ||
2954 | static int _elua_map_rotate(lua_State *L); | ||
2955 | static int _elua_map_rotate3d(lua_State *L); | ||
2956 | static int _elua_map_smooth(lua_State *L); | ||
2957 | static int _elua_map_uv(lua_State *L); | ||
2958 | static int _elua_map_zoom(lua_State *L); | ||
2959 | |||
2960 | static const char *_elua_evas_map_api = "ewas_map"; | ||
2961 | static const struct luaL_reg _elua_evas_map_funcs [] = | ||
2962 | { | ||
2963 | {"alpha", _elua_map_alpha}, | ||
2964 | // {"dup", _elua_map_dup}, // not sure of proper api for this. | ||
2965 | {"clockwise", _elua_map_clockwise}, | ||
2966 | {"color", _elua_map_colour}, | ||
2967 | {"coord", _elua_map_coord}, | ||
2968 | {"lighting", _elua_map_lighting}, | ||
2969 | {"perspective", _elua_map_perspective}, | ||
2970 | {"populate", _elua_map_populate}, | ||
2971 | {"rotate", _elua_map_rotate}, | ||
2972 | {"rotate3d", _elua_map_rotate3d}, | ||
2973 | // {"size", _elua_map_size}, // not sure of proper API for this | ||
2974 | {"smooth", _elua_map_smooth}, | ||
2975 | {"uv", _elua_map_uv}, | ||
2976 | {"zoom", _elua_map_zoom}, | ||
2977 | |||
2978 | {NULL, NULL} // end | ||
2979 | }; | ||
2980 | |||
2981 | /** | ||
2982 | @page luaref | ||
2983 | @subsubsection map_alpha map_object:alpha() | ||
2984 | |||
2985 | |||
2986 | @since 1.1.0 | ||
2987 | */ | ||
2988 | static int | ||
2989 | _elua_map_alpha(lua_State *L) // Stack usage [-0, +1, -] | ||
2990 | { | ||
2991 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
2992 | Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; | ||
2993 | int n; | ||
2994 | |||
2995 | if (!_elua_isa(obj, _elua_evas_map_meta)) return 0; | ||
2996 | |||
2997 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
2998 | if (n == 2) | ||
2999 | { | ||
3000 | evas_map_alpha_set(elm->map, lua_toboolean(L, 2)); | ||
3001 | // Stack usage [-0, +0, -] | ||
3002 | } | ||
3003 | lua_pushboolean(L, evas_map_alpha_get(elm->map)); // Stack usage [-0, +1, -] | ||
3004 | return 1; | ||
3005 | } | ||
3006 | |||
3007 | /** | ||
3008 | @page luaref | ||
3009 | @subsubsection map_clockwise map_object:clockwise() | ||
3010 | |||
3011 | |||
3012 | @since 1.1.0 | ||
3013 | */ | ||
3014 | static int | ||
3015 | _elua_map_clockwise(lua_State *L) // Stack usage [-0, +1, -] | ||
3016 | { | ||
3017 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3018 | Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; | ||
3019 | |||
3020 | if (!_elua_isa(obj, _elua_evas_map_meta)) return 0; | ||
3021 | |||
3022 | lua_pushboolean(L, evas_map_util_clockwise_get(elm->map)); // Stack usage [-0, +1, -] | ||
3023 | return 1; | ||
3024 | } | ||
3025 | |||
3026 | /** | ||
3027 | @page luaref | ||
3028 | @subsubsection map_colour map_object:colour() | ||
3029 | |||
3030 | |||
3031 | @since 1.1.0 | ||
3032 | */ | ||
3033 | static int | ||
3034 | _elua_map_colour(lua_State *L) // Stack usage [-(8|12), +(9|13), em] | ||
3035 | { | ||
3036 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3037 | Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; | ||
3038 | int r, g, b, a; | ||
3039 | int n; | ||
3040 | |||
3041 | if (!_elua_isa(obj, _elua_evas_map_meta)) return 0; | ||
3042 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
3043 | |||
3044 | switch (n) | ||
3045 | { | ||
3046 | case 5 : | ||
3047 | { | ||
3048 | if (_elua_scan_params(L, 2, "%r %g %b %a", &r, &g, &b, &a) > 0) | ||
3049 | { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e] | ||
3050 | evas_map_util_points_color_set(elm->map, r, g, b, a); | ||
3051 | } | ||
3052 | break; | ||
3053 | } | ||
3054 | |||
3055 | case 1 : | ||
3056 | case 6 : | ||
3057 | { | ||
3058 | if (_elua_scan_params(L, 3, "%r %g %b %a", &r, &g, &b, &a) > 0) | ||
3059 | { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e] | ||
3060 | evas_map_point_color_set(elm->map, lua_tointeger(L, 2), r, g, b, a); | ||
3061 | // Stack usage [-0, +0, -] | ||
3062 | } | ||
3063 | evas_map_point_color_get(elm->map, lua_tointeger(L, 2), &r, &g, &b, &a); | ||
3064 | // Stack usage [-0, +0, -] | ||
3065 | _elua_ret(L, "%r %g %b %a", r, g, b, a); | ||
3066 | // Stack usage [-8, +9, em] | ||
3067 | return 1; | ||
3068 | } | ||
3069 | } | ||
3070 | |||
3071 | return 0; | ||
3072 | } | ||
3073 | |||
3074 | /** | ||
3075 | @page luaref | ||
3076 | @subsubsection map_coord map_object:coord() | ||
3077 | |||
3078 | |||
3079 | @since 1.1.0 | ||
3080 | */ | ||
3081 | static int | ||
3082 | _elua_map_coord(lua_State *L) // Stack usage [-(6|9), +(7|10), em] | ||
3083 | { | ||
3084 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3085 | Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; | ||
3086 | Evas_Coord x, y, z; | ||
3087 | int n; | ||
3088 | |||
3089 | if (!_elua_isa(obj, _elua_evas_map_meta)) return 0; | ||
3090 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
3091 | if (2 > n) return 0; | ||
3092 | |||
3093 | if (_elua_scan_params(L, 2, "%x %y %z", &x, &y, &z) > 0) | ||
3094 | { // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e] | ||
3095 | evas_map_point_coord_set(elm->map, lua_tointeger(L, 2), x, y, z); | ||
3096 | // Stack usage [-0, +0, -] | ||
3097 | } | ||
3098 | evas_map_point_coord_get(elm->map, lua_tointeger(L, 2), &x, &y, &z); | ||
3099 | // Stack usage [-0, +0, -] | ||
3100 | _elua_ret(L, "%x %y %z", x, y, z); | ||
3101 | // Stack usage [-6, +7, em] | ||
3102 | return 1; | ||
3103 | } | ||
3104 | |||
3105 | /** | ||
3106 | @page luaref | ||
3107 | @subsubsection map_lighting map_object:lighting() | ||
3108 | |||
3109 | |||
3110 | @since 1.1.0 | ||
3111 | */ | ||
3112 | static int | ||
3113 | _elua_map_lighting(lua_State *L) // Stack usage [-(0|9), +(0|9), e] | ||
3114 | { | ||
3115 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3116 | Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; | ||
3117 | Evas_Coord x, y, z; | ||
3118 | int r, g, b, r1, g1, b1; | ||
3119 | int n; | ||
3120 | |||
3121 | if (!_elua_isa(obj, _elua_evas_map_meta)) return 0; | ||
3122 | |||
3123 | if ((n = _elua_scan_params(L, 2, "%x %y %z", &x, &y, &z)) > 0) | ||
3124 | // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e] | ||
3125 | if (n += _elua_scan_params(L, 2 + n, "%r %g %b", &r, &g, &b) > 0) | ||
3126 | // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e] | ||
3127 | if (_elua_scan_params(L, 2 + n, "%r %g %b", &r1, &g1, &b1) > 0) | ||
3128 | { // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e] | ||
3129 | evas_map_util_3d_lighting(elm->map, x, y, z, r, g, b, r1, g1, b1); | ||
3130 | } | ||
3131 | return 0; | ||
3132 | } | ||
3133 | |||
3134 | /** | ||
3135 | @page luaref | ||
3136 | @subsubsection map_perspective map_object:perspective() | ||
3137 | |||
3138 | |||
3139 | @since 1.1.0 | ||
3140 | */ | ||
3141 | static int | ||
3142 | _elua_map_perspective(lua_State *L) // Stack usage [-(0|4), +(0|4), e] | ||
3143 | { | ||
3144 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3145 | Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; | ||
3146 | Evas_Coord x, y, z, f; | ||
3147 | |||
3148 | if (!_elua_isa(obj, _elua_evas_map_meta)) return 0; | ||
3149 | |||
3150 | if (_elua_scan_params(L, 2, "%x %y %z %f", &x, &y, &z, &f) > 0) | ||
3151 | { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e] | ||
3152 | evas_map_util_3d_perspective(elm->map, x, y, z, f); | ||
3153 | } | ||
3154 | return 0; | ||
3155 | } | ||
3156 | |||
3157 | /** | ||
3158 | @page luaref | ||
3159 | @subsubsection map_populate map_object:populate() | ||
3160 | |||
3161 | |||
3162 | @since 1.1.0 | ||
3163 | */ | ||
3164 | static int | ||
3165 | _elua_map_populate(lua_State *L) // Stack usage [-(0|4), +(0|4), e] | ||
3166 | { | ||
3167 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3168 | Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; | ||
3169 | int n; | ||
3170 | |||
3171 | if (!_elua_isa(obj, _elua_evas_map_meta)) return 0; | ||
3172 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
3173 | |||
3174 | switch (n) | ||
3175 | { | ||
3176 | case 2 : | ||
3177 | { | ||
3178 | Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); // Stack usage [-0, +0, -] | ||
3179 | const Edje_Lua_Evas_Object *source = (Edje_Lua_Evas_Object *)obj2; | ||
3180 | |||
3181 | if (!_elua_isa(obj2, _elua_evas_meta)) return 0; | ||
3182 | evas_map_util_points_populate_from_object(elm->map, source->evas_obj); | ||
3183 | break; | ||
3184 | } | ||
3185 | |||
3186 | case 3 : | ||
3187 | { | ||
3188 | Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); // Stack usage [-0, +0, -] | ||
3189 | const Edje_Lua_Evas_Object *source = (Edje_Lua_Evas_Object *)obj2; | ||
3190 | Evas_Coord z = lua_tointeger(L, 3); | ||
3191 | |||
3192 | if (!_elua_isa(obj2, _elua_evas_meta)) return 0; | ||
3193 | evas_map_util_points_populate_from_object_full(elm->map, source->evas_obj, z); | ||
3194 | break; | ||
3195 | } | ||
3196 | |||
3197 | case 6 : | ||
3198 | { | ||
3199 | Evas_Coord x, y, w, h; | ||
3200 | |||
3201 | if ((n = _elua_scan_params(L, 2, "%x %y %w %h", &x, &y, &w, &h)) > 0) | ||
3202 | { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e] | ||
3203 | evas_map_util_points_populate_from_geometry(elm->map, x, y, w, h, lua_tointeger(L, 2 + n)); | ||
3204 | } | ||
3205 | break; | ||
3206 | } | ||
3207 | } | ||
3208 | return 0; | ||
3209 | } | ||
3210 | |||
3211 | /** | ||
3212 | @page luaref | ||
3213 | @subsubsection map_rotate map_object:rotate() | ||
3214 | |||
3215 | |||
3216 | @since 1.1.0 | ||
3217 | */ | ||
3218 | static int | ||
3219 | _elua_map_rotate(lua_State *L) // Stack usage [-(0|2), +(0|2), e] | ||
3220 | { | ||
3221 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3222 | Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; | ||
3223 | double degrees; | ||
3224 | Evas_Coord x, y; | ||
3225 | int n; | ||
3226 | |||
3227 | if (!_elua_isa(obj, _elua_evas_map_meta)) return 0; | ||
3228 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
3229 | if (4 != n) return 0; | ||
3230 | |||
3231 | degrees = lua_tonumber(L, 2); | ||
3232 | if (_elua_scan_params(L, 3, "%x %y", &x, &y) > 0) | ||
3233 | { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e] | ||
3234 | evas_map_util_rotate(elm->map, degrees, x, y); | ||
3235 | } | ||
3236 | return 0; | ||
3237 | } | ||
3238 | |||
3239 | /** | ||
3240 | @page luaref | ||
3241 | @subsubsection map_rotate3d map_object:rotate3d() | ||
3242 | |||
3243 | |||
3244 | @since 1.1.0 | ||
3245 | */ | ||
3246 | static int | ||
3247 | _elua_map_rotate3d(lua_State *L) // Stack usage [-(0|6), +(0|6), e] | ||
3248 | { | ||
3249 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3250 | Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; | ||
3251 | double zx, zy, zz; | ||
3252 | Evas_Coord x, y, z; | ||
3253 | int n; | ||
3254 | |||
3255 | if (!_elua_isa(obj, _elua_evas_map_meta)) return 0; | ||
3256 | |||
3257 | if ((n = _elua_scan_params(L, 2, "#x #y #z", &zx, &zy, &zz)) > 0) | ||
3258 | // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e] | ||
3259 | if (_elua_scan_params(L, 2 + n, "%x %y %z", &x, &y, &z) > 0) | ||
3260 | { // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e] | ||
3261 | evas_map_util_3d_rotate(elm->map, zx, zy, zz, x, y, z); | ||
3262 | } | ||
3263 | return 0; | ||
3264 | } | ||
3265 | |||
3266 | /** | ||
3267 | @page luaref | ||
3268 | @subsubsection map_smooth map_object:smooth() | ||
3269 | |||
3270 | |||
3271 | @since 1.1.0 | ||
3272 | */ | ||
3273 | static int | ||
3274 | _elua_map_smooth(lua_State *L) // Stack usage [-0, +1, -] | ||
3275 | { | ||
3276 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3277 | Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; | ||
3278 | int n; | ||
3279 | |||
3280 | if (!_elua_isa(obj, _elua_evas_map_meta)) return 0; | ||
3281 | |||
3282 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
3283 | if (n == 2) | ||
3284 | { | ||
3285 | evas_map_smooth_set(elm->map, lua_toboolean(L, 2)); | ||
3286 | // Stack usage [-0, +0, -] | ||
3287 | } | ||
3288 | lua_pushboolean(L, evas_map_smooth_get(elm->map)); // Stack usage [-0, +1, -] | ||
3289 | return 1; | ||
3290 | } | ||
3291 | |||
3292 | /** | ||
3293 | @page luaref | ||
3294 | @subsubsection map_uv map_object:uv() | ||
3295 | |||
3296 | |||
3297 | @since 1.1.0 | ||
3298 | */ | ||
3299 | static int | ||
3300 | _elua_map_uv(lua_State *L) // Stack usage [-(4|6), +(5|7), em] | ||
3301 | { | ||
3302 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3303 | Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; | ||
3304 | double u, v; | ||
3305 | int n; | ||
3306 | |||
3307 | if (!_elua_isa(obj, _elua_evas_map_meta)) return 0; | ||
3308 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
3309 | if (2 > n) return 0; | ||
3310 | |||
3311 | if (_elua_scan_params(L, 3, "#u #v", &u, &v) > 0) | ||
3312 | { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e] | ||
3313 | evas_map_point_image_uv_set(elm->map, lua_tonumber(L, 2), u, v); | ||
3314 | // Stack usage [-0, +0, -] | ||
3315 | } | ||
3316 | evas_map_point_image_uv_get(elm->map, lua_tonumber(L, 2), &u, &v); | ||
3317 | // Stack usage [-0, +0, -] | ||
3318 | _elua_ret(L, "#u #v", u, v); | ||
3319 | // Stack usage [-4, +5, em] | ||
3320 | return 1; | ||
3321 | } | ||
3322 | |||
3323 | /** | ||
3324 | @page luaref | ||
3325 | @subsubsection map_zoom map_object:zoom() | ||
3326 | |||
3327 | |||
3328 | @since 1.1.0 | ||
3329 | */ | ||
3330 | static int | ||
3331 | _elua_map_zoom(lua_State *L) // Stack usage [-(0|4), +(0|4), e] | ||
3332 | { | ||
3333 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3334 | Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; | ||
3335 | double zx, zy; | ||
3336 | Evas_Coord x, y; | ||
3337 | int n; | ||
3338 | |||
3339 | if (!_elua_isa(obj, _elua_evas_map_meta)) return 0; | ||
3340 | |||
3341 | if ((n = _elua_scan_params(L, 2, "#x #y", &zx, &zy)) > 0) | ||
3342 | // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e] | ||
3343 | if (_elua_scan_params(L, 2 + n, "%x %y", &x, &y) > 0) | ||
3344 | { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e] | ||
3345 | evas_map_util_zoom(elm->map, zx, zy, x, y); | ||
3346 | } | ||
3347 | return 0; | ||
3348 | } | ||
3349 | |||
3350 | //------------- | ||
3351 | //------------- | ||
3352 | /** | ||
3353 | @page luaref | ||
3354 | @subsection evas_polygon Evas polygon class. | ||
3355 | |||
3356 | The lua evas polygon class includes functions for dealing with evas polygon objects. | ||
3357 | The evas polygon objects must have been previously created by lua using the lua | ||
3358 | polygon object creation function edje:polygon(). | ||
3359 | |||
3360 | In the following, "polygon_object" is a place holder for any lua variable that | ||
3361 | holds a reference to an evas polygon object. | ||
3362 | |||
3363 | @since 1.1.0 | ||
3364 | */ | ||
3365 | |||
3366 | static int _elua_polygon_clear(lua_State *L); | ||
3367 | static int _elua_polygon_point(lua_State *L); | ||
3368 | |||
3369 | static const char *_elua_evas_polygon_api = "evas_polygon"; | ||
3370 | static const char *_elua_evas_polygon_parent = "evas_polygon_parent"; | ||
3371 | static const struct luaL_reg _elua_evas_polygon_funcs [] = | ||
3372 | { | ||
3373 | {"clear", _elua_polygon_clear}, // clear all polygon points | ||
3374 | {"point", _elua_polygon_point}, // add a polygon point | ||
3375 | |||
3376 | {NULL, NULL} // end | ||
3377 | }; | ||
3378 | |||
3379 | /** | ||
3380 | @page luaref | ||
3381 | @subsubsection polygon_clear polygon_object:clear() | ||
3382 | |||
3383 | Clears all points from the polygon. | ||
3384 | |||
3385 | Wraps evas_object_polygon_points_clear(), | ||
3386 | |||
3387 | @since 1.1.0 | ||
3388 | */ | ||
3389 | static int | ||
3390 | _elua_polygon_clear(lua_State *L) // Stack usage [-0, +0, -] | ||
3391 | { | ||
3392 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3393 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
3394 | |||
3395 | if (!_elua_isa(obj, _elua_evas_polygon_meta)) return 0; | ||
3396 | evas_object_polygon_points_clear(elo->evas_obj); | ||
3397 | return 0; | ||
3398 | } | ||
3399 | |||
3400 | /** | ||
3401 | @page luaref | ||
3402 | @subsubsection polygon_point polygon_object:point(x, y) | ||
3403 | |||
3404 | Adds a point to this polygon. | ||
3405 | |||
3406 | Wraps evas_object_polygon_point_add(). | ||
3407 | |||
3408 | @param x The X coordinate of the point. | ||
3409 | @param y The Y coordinate of the point. | ||
3410 | |||
3411 | @since 1.1.0 | ||
3412 | */ | ||
3413 | static int | ||
3414 | _elua_polygon_point(lua_State *L) // Stack usage [-(0|2), +(0|2), e] | ||
3415 | { | ||
3416 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3417 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
3418 | Evas_Coord x, y; | ||
3419 | |||
3420 | if (!_elua_isa(obj, _elua_evas_polygon_meta)) return 0; | ||
3421 | |||
3422 | if (_elua_scan_params(L, 2, "%x %y", &x, &y) > 0) | ||
3423 | { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e] | ||
3424 | evas_object_polygon_point_add(elo->evas_obj, x, y); | ||
3425 | } | ||
3426 | |||
3427 | return 0; | ||
3428 | } | ||
3429 | |||
3430 | //------------- | ||
3431 | //------------- | ||
3432 | /** | ||
3433 | @page luaref | ||
3434 | @subsection evas_text Evas text class. | ||
3435 | |||
3436 | The lua evas text class includes functions for dealing with evas text objects. | ||
3437 | The evas text objects must have been previously created by lua using the lua | ||
3438 | text object creation function edje:text(). | ||
3439 | |||
3440 | In the following, "text_object" is a place holder for any lua variable that | ||
3441 | holds a reference to an evas text object. | ||
3442 | |||
3443 | @since 1.1.0 | ||
3444 | */ | ||
3445 | |||
3446 | static int _elua_text_font(lua_State *L); | ||
3447 | static int _elua_text_text(lua_State *L); | ||
3448 | |||
3449 | static const char *_elua_evas_text_api = "evas_text"; | ||
3450 | static const char *_elua_evas_text_parent = "evas_text_parent"; | ||
3451 | static const struct luaL_reg _elua_evas_text_funcs [] = | ||
3452 | { | ||
3453 | {"font", _elua_text_font}, // get or set text font | ||
3454 | {"text", _elua_text_text}, // get or set text | ||
3455 | // {"text_class", _elua_object_text_class}, // get or set object text class | ||
3456 | |||
3457 | {NULL, NULL} // end | ||
3458 | }; | ||
3459 | |||
3460 | /** | ||
3461 | @page luaref | ||
3462 | @subsubsection text_font text_object:font(font, size) | ||
3463 | |||
3464 | Gets, (and optionally sets) the font for this text object. | ||
3465 | |||
3466 | Wraps evas_object_text_font_set(). | ||
3467 | |||
3468 | @param font The new font name. | ||
3469 | @param size The new font size. | ||
3470 | |||
3471 | Note that the font and size arguments are optional, without them this function | ||
3472 | just queries the current values. The font and size arguments can be separate | ||
3473 | values, or named fields in a table. The font name can refer to a font in the | ||
3474 | edje file, or an external font. | ||
3475 | |||
3476 | @return A table with these fields: | ||
3477 | - string font: The font name. | ||
3478 | - integer size: The font size. | ||
3479 | |||
3480 | @since 1.1.0 | ||
3481 | */ | ||
3482 | static int | ||
3483 | _elua_text_font(lua_State *L) // Stack usage [-(4|6), +(5|7), em] | ||
3484 | { | ||
3485 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3486 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
3487 | char *font, *font2 = NULL; | ||
3488 | Evas_Font_Size size; | ||
3489 | int inlined_font = 0; | ||
3490 | |||
3491 | if (!_elua_isa(obj, _elua_evas_text_meta)) return 0; | ||
3492 | |||
3493 | if (_elua_scan_params(L, 2, "$font %size", &font, &size) > 0) | ||
3494 | { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e] | ||
3495 | /* Check if the font is embedded in the .edj | ||
3496 | * This is a simple check. | ||
3497 | * There is a much more complicated version in edje_text.c _edje_text_recalc_apply(). | ||
3498 | * If we need to get more complicated, we can do that later, | ||
3499 | * and maybe refactor things. | ||
3500 | */ | ||
3501 | if (obj->ed->file->fonts) | ||
3502 | { | ||
3503 | Edje_Font_Directory_Entry *fnt = eina_hash_find(obj->ed->file->fonts, font); | ||
3504 | |||
3505 | if (fnt) | ||
3506 | { | ||
3507 | size_t len = strlen(font) + sizeof("edje/fonts/") + 1; | ||
3508 | font2 = alloca(len); | ||
3509 | sprintf(font2, "edje/fonts/%s", font); | ||
3510 | font = font2; | ||
3511 | inlined_font = 1; | ||
3512 | font2 = NULL; | ||
3513 | } | ||
3514 | } | ||
3515 | |||
3516 | if (inlined_font) evas_object_text_font_source_set(elo->evas_obj, obj->ed->path); | ||
3517 | else evas_object_text_font_source_set(elo->evas_obj, NULL); | ||
3518 | |||
3519 | evas_object_text_font_set(elo->evas_obj, font, size); | ||
3520 | } | ||
3521 | |||
3522 | // When one external API says it's gotta be const, and another one says not, then one of them's gotta be cast. :-P | ||
3523 | evas_object_text_font_get(elo->evas_obj, (const char **) &font, &size); | ||
3524 | _elua_ret(L, "$font %size", font, size); | ||
3525 | // Stack usage [-4, +5, em] | ||
3526 | return 1; | ||
3527 | } | ||
3528 | |||
3529 | /** | ||
3530 | @page luaref | ||
3531 | @subsubsection text_text text_object:text(text) | ||
3532 | |||
3533 | Get (and optionally set) the actual tetx for this text object. | ||
3534 | |||
3535 | Wraps evas_object_text_text_set(). | ||
3536 | |||
3537 | @param text The text to set for this text object. | ||
3538 | |||
3539 | Note that the argument is optional, without it this function just queries the | ||
3540 | current value. | ||
3541 | |||
3542 | @return A string of the text on this text object. | ||
3543 | |||
3544 | @since 1.1.0 | ||
3545 | */ | ||
3546 | static int | ||
3547 | _elua_text_text(lua_State *L) // Stack usage [-0, +1, m] | ||
3548 | { | ||
3549 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -] | ||
3550 | Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; | ||
3551 | int n; | ||
3552 | |||
3553 | if (!_elua_isa(obj, _elua_evas_text_meta)) return 0; | ||
3554 | n = lua_gettop(L); // Stack usage [-0, +0, -] | ||
3555 | if (n == 2) | ||
3556 | { | ||
3557 | if (lua_isstring(L, 2)) | ||
3558 | { | ||
3559 | const char *str; | ||
3560 | |||
3561 | if ((str = lua_tostring(L, 2))) // Extra parenthesis, coz Mikes compiler has a lisp. | ||
3562 | // Stack usage [-0, +0, m] | ||
3563 | evas_object_text_text_set(elo->evas_obj, str); | ||
3564 | } | ||
3565 | } | ||
3566 | lua_pushstring(L, evas_object_text_text_get(elo->evas_obj)); // Stack usage [-0, +1, m] | ||
3567 | return 1; | ||
3568 | } | ||
3569 | |||
3570 | |||
3571 | //--------------------------------------------------------------------------// | ||
3572 | // Brain dead inheritance thingy, built for speed. Kinda. Part 1. | ||
3573 | static void | ||
3574 | _elua_add_functions(lua_State *L, const char *api, const luaL_Reg *funcs, const char *meta, const char *parent, const char *base) // Stack usage [-3, +5, m] if inheriting [-6, +11, em] | ||
3575 | { | ||
3576 | luaL_register(L, api, funcs); // Stack usage [-0, +1, m] | ||
3577 | luaL_newmetatable(L, meta); // Stack usage [-0, +1, m] | ||
3578 | luaL_register(L, 0, _elua_edje_gc_funcs); // Stack usage [-1, +1, m] | ||
3579 | lua_pushliteral(L, "__index"); // Stack usage [-0, +1, m] | ||
3580 | lua_pushvalue(L, -3); // Stack usage [-0, +1, -] | ||
3581 | lua_rawset(L, -3); // Stack usage [-2, +0, m] | ||
3582 | |||
3583 | if (base && parent) | ||
3584 | { | ||
3585 | // Inherit from base | ||
3586 | lua_getglobal(L, base); // Stack usage [-0, +1, e] | ||
3587 | luaL_newmetatable(L, parent); // Stack usage [-0, +1, m] | ||
3588 | lua_pushliteral(L, "__index"); // Stack usage [-0, +1, m] | ||
3589 | lua_pushvalue(L, -3); // Stack usage [-0, +1, -] | ||
3590 | lua_rawset(L, -3); // Stack usage [-2, +0, m] | ||
3591 | lua_getglobal(L, api); // Stack usage [-0, +1, e] | ||
3592 | luaL_getmetatable(L, parent); // Stack usage [-0, +1, -] | ||
3593 | lua_setmetatable(L, -2); // Stack usage [-1, +0, -] | ||
3594 | } | ||
3595 | } | ||
3596 | |||
3597 | // Brain dead inheritance thingy, built for speed. Kinda. Part 2. | ||
3598 | static Eina_Bool | ||
3599 | _elua_isa(Edje_Lua_Obj *obj, const char *type) | ||
3600 | { | ||
3601 | Eina_Bool isa = EINA_FALSE; | ||
3602 | |||
3603 | if (!obj) return isa; | ||
3604 | if (obj->meta == type) | ||
3605 | isa = EINA_TRUE; | ||
3606 | if (_elua_evas_meta == type) | ||
3607 | { | ||
3608 | if (obj->meta == _elua_evas_image_meta) | ||
3609 | isa = EINA_TRUE; | ||
3610 | else if (obj->meta == _elua_evas_text_meta) | ||
3611 | isa = EINA_TRUE; | ||
3612 | else if (obj->meta == _elua_evas_edje_meta) | ||
3613 | isa = EINA_TRUE; | ||
3614 | else if (obj->meta == _elua_evas_line_meta) | ||
3615 | isa = EINA_TRUE; | ||
3616 | else if (obj->meta == _elua_evas_polygon_meta) | ||
3617 | isa = EINA_TRUE; | ||
3618 | } | ||
3619 | return isa; | ||
3620 | } | ||
3621 | |||
3622 | #ifndef RASTER_FORGOT_WHY | ||
3623 | static void | ||
3624 | _elua_init(void) // Stack usage [-16, +20, em] | ||
3625 | { | ||
3626 | static Edje_Lua_Alloc ela = { MAX_LUA_MEM, 0 }; | ||
3627 | const luaL_Reg *l; | ||
3628 | lua_State *L; | ||
3629 | |||
3630 | if (lstate) return; | ||
3631 | |||
3632 | lstate = L = lua_newstate(_elua_alloc, &ela); // Stack usage [-0, +0, -] | ||
3633 | lua_atpanic(L, _elua_custom_panic); // Stack usage [-0, +0, -] | ||
3634 | |||
3635 | // FIXME: figure out optimal gc settings later | ||
3636 | // lua_gc(L, LUA_GCSETPAUSE, 200); // Stack usage [-0, +0, e] | ||
3637 | // lua_gc(L, LUA_GCSETSTEPMUL, 200); // Stack usage [-0, +0, e] | ||
3638 | |||
3639 | for (l = _elua_libs; l->func; l++) // Currently * 4 | ||
3640 | { | ||
3641 | lua_pushcfunction(L, l->func); // Stack usage [-0, +1, m] | ||
3642 | lua_pushstring(L, l->name); // Stack usage [-0, +1, m] | ||
3643 | lua_call(L, 1, 0); // Stack usage [-2, +0, e] | ||
3644 | } | ||
3645 | |||
3646 | luaL_register(L, _elua_edje_api, _elua_edje_funcs); // Stack usage [-0, +1, m] | ||
3647 | luaL_newmetatable(L, _elua_edje_meta); // Stack usage [-0, +1, m] | ||
3648 | luaL_register(L, 0, _elua_edje_gc_funcs); // Stack usage [-1, +1, m] | ||
3649 | |||
3650 | _elua_add_functions(L, _elua_evas_api, _elua_evas_funcs, _elua_evas_meta, NULL, NULL); // Stack usage [-3, +5, m] | ||
3651 | |||
3652 | // weak table for our objects | ||
3653 | lua_pushlightuserdata(L, &_elua_objs); // Stack usage [-0, +1, -] | ||
3654 | lua_newtable(L); // Stack usage [-0, +1, m] | ||
3655 | lua_pushstring(L, "__mode"); // Stack usage [-0, +1, m] | ||
3656 | lua_pushstring(L, "v"); // Stack usage [-0, +1, m] | ||
3657 | lua_rawset(L, -3); // Stack usage [-2, +0, m] | ||
3658 | lua_rawset(L, LUA_REGISTRYINDEX); // Stack usage [-2, +0, m] | ||
3659 | } | ||
3660 | #endif | ||
3661 | |||
3662 | void | ||
3663 | _edje_lua2_script_init(Edje *ed) // Stack usage [-63, +99, em] | ||
3664 | { | ||
3665 | static Edje_Lua_Alloc ela = { MAX_LUA_MEM, 0 }; | ||
3666 | const luaL_Reg *l; | ||
3667 | char buf[256]; | ||
3668 | void *data; | ||
3669 | int size; | ||
3670 | lua_State *L; | ||
3671 | |||
3672 | if (ed->L) return; | ||
3673 | if (0 > _log_domain) | ||
3674 | _log_domain = eina_log_domain_register("lua", NULL); | ||
3675 | if (0 <= _log_domain) | ||
3676 | { | ||
3677 | _log_count++; | ||
3678 | eina_log_domain_level_set("lua", EINA_LOG_LEVEL_WARN); | ||
3679 | } | ||
3680 | |||
3681 | #ifndef RASTER_FORGOT_WHY | ||
3682 | _elua_init(); // This is actually truly pointless, even if raster remembers. | ||
3683 | #endif | ||
3684 | L = ed->L = lua_newstate(_elua_alloc, &ela); // Stack usage [-0, +0, -] | ||
3685 | lua_atpanic(L, _elua_custom_panic); // Stack usage [-0, +0, -] | ||
3686 | |||
3687 | // FIXME: figure out optimal gc settings later | ||
3688 | // lua_gc(L, LUA_GCSETPAUSE, 200); // Stack usage [-0, +0, e] | ||
3689 | // lua_gc(L, LUA_GCSETSTEPMUL, 200); // Stack usage [-0, +0, e] | ||
3690 | |||
3691 | for (l = _elua_libs; l->func; l++) // Currently * 4 | ||
3692 | { | ||
3693 | lua_pushcfunction(L, l->func); // Stack usage [-0, +1, m] | ||
3694 | lua_pushstring(L, l->name); // Stack usage [-0, +1, m] | ||
3695 | lua_call(L, 1, 0); // Stack usage [-2, +0, m] | ||
3696 | } | ||
3697 | |||
3698 | luaL_register(L, _elua_edje_api, _elua_edje_funcs); // Stack usage [-0, +1, m] | ||
3699 | luaL_newmetatable(L, _elua_edje_meta); // Stack usage [-0, +1, m] | ||
3700 | luaL_register(L, 0, _elua_edje_gc_funcs); // Stack usage [-1, +1, m] | ||
3701 | |||
3702 | lua_pop(L, 2); // Stack usage [-n, +0, -] | ||
3703 | |||
3704 | _elua_add_functions(L, _elua_evas_api, _elua_evas_funcs, _elua_evas_meta, NULL, NULL); | ||
3705 | // Stack usage [-3, +5, m] | ||
3706 | _elua_add_functions(L, _elua_ecore_timer_api, _elua_ecore_timer_funcs, _elua_ecore_timer_meta, NULL, NULL); | ||
3707 | // Stack usage [-3, +5, m] | ||
3708 | _elua_add_functions(L, _elua_ecore_animator_api, _elua_ecore_animator_funcs, _elua_ecore_animator_meta, NULL, NULL); | ||
3709 | // Stack usage [-6, +11, m] | ||
3710 | _elua_add_functions(L, _elua_evas_edje_api, _elua_evas_edje_funcs, _elua_evas_edje_meta, _elua_evas_edje_parent, _elua_evas_api); | ||
3711 | // Stack usage [-6, +11, em] | ||
3712 | _elua_add_functions(L, _elua_evas_image_api, _elua_evas_image_funcs, _elua_evas_image_meta, _elua_evas_image_parent, _elua_evas_api); | ||
3713 | // Stack usage [-6, +11, em] | ||
3714 | _elua_add_functions(L, _elua_evas_line_api, _elua_evas_line_funcs, _elua_evas_line_meta, _elua_evas_line_parent, _elua_evas_api); | ||
3715 | // Stack usage [-6, +11, em] | ||
3716 | _elua_add_functions(L, _elua_evas_map_api, _elua_evas_map_funcs, _elua_evas_map_meta, NULL, NULL); | ||
3717 | // Stack usage [-3, +5, m] | ||
3718 | _elua_add_functions(L, _elua_evas_polygon_api, _elua_evas_polygon_funcs, _elua_evas_polygon_meta, _elua_evas_polygon_parent, _elua_evas_api); | ||
3719 | // Stack usage [-6, +11, em] | ||
3720 | _elua_add_functions(L, _elua_evas_text_api, _elua_evas_text_funcs, _elua_evas_text_meta, _elua_evas_text_parent, _elua_evas_api); | ||
3721 | // Stack usage [-6, +11, em] | ||
3722 | |||
3723 | // weak table for our objects | ||
3724 | lua_pushlightuserdata(L, &_elua_objs); // Stack usage [-0, +1, -] | ||
3725 | lua_newtable(L); // Stack usage [-0, +1, m] | ||
3726 | lua_pushstring(L, "__mode"); // Stack usage [-0, +1, m] | ||
3727 | lua_pushstring(L, "v"); // Stack usage [-0, +1, m] | ||
3728 | lua_rawset(L, -3); // Stack usage [-2, +0, m] | ||
3729 | lua_rawset(L, LUA_REGISTRYINDEX); // Stack usage [-2, +0, m] | ||
3730 | |||
3731 | _elua_table_ptr_set(L, _elua_key, ed); // Stack usage [-2, +2, e] | ||
3732 | |||
3733 | snprintf(buf, sizeof(buf), "edje/scripts/lua/%i", ed->collection->id); | ||
3734 | data = eet_read(ed->file->ef, buf, &size); | ||
3735 | |||
3736 | if (data) | ||
3737 | { | ||
3738 | int err; | ||
3739 | |||
3740 | err = luaL_loadbuffer(L, data, size, "edje_lua_script"); // Stack usage [-0, +1, m] | ||
3741 | if (err) | ||
3742 | { | ||
3743 | if (err == LUA_ERRSYNTAX) | ||
3744 | ERR("Lua load syntax error: %s", | ||
3745 | lua_tostring(L, -1)); // Stack usage [-0, +0, m] | ||
3746 | else if (err == LUA_ERRMEM) | ||
3747 | ERR("Lua load memory allocation error: %s", | ||
3748 | lua_tostring(L, -1)); // Stack usage [-0, +0, m] | ||
3749 | } | ||
3750 | free(data); | ||
3751 | /* This is not needed, pcalls don't longjmp(), that's why they are protected. | ||
3752 | if (setjmp(panic_jmp) == 1) | ||
3753 | { | ||
3754 | ERR("Lua script init panic"); | ||
3755 | return; | ||
3756 | } | ||
3757 | */ | ||
3758 | if ((err = lua_pcall(L, 0, 0, 0))) // Stack usage [-1, +0, -] | ||
3759 | _edje_lua2_error(L, err); // Stack usage [-0, +0, m] | ||
3760 | } | ||
3761 | } | ||
3762 | |||
3763 | void | ||
3764 | _edje_lua2_script_shutdown(Edje *ed) | ||
3765 | { | ||
3766 | if (!ed->L) return; | ||
3767 | lua_close(ed->L); // Stack usage irrelevant, as it's all gone now. | ||
3768 | ed->L = NULL; | ||
3769 | while (ed->lua_objs) | ||
3770 | { | ||
3771 | Edje_Lua_Obj *obj = (Edje_Lua_Obj *)ed->lua_objs; | ||
3772 | if (obj->free_func) | ||
3773 | { | ||
3774 | ERR("uncollected Lua object %p", obj); | ||
3775 | ed->lua_objs = eina_inlist_remove(ed->lua_objs, ed->lua_objs); | ||
3776 | } | ||
3777 | else | ||
3778 | { | ||
3779 | ERR("dangling Lua object %p", obj); | ||
3780 | ed->lua_objs = eina_inlist_remove(ed->lua_objs, ed->lua_objs); | ||
3781 | } | ||
3782 | } | ||
3783 | |||
3784 | if (0 <= _log_domain) | ||
3785 | { | ||
3786 | _log_count--; | ||
3787 | if (0 >= _log_count) | ||
3788 | { | ||
3789 | eina_log_domain_unregister(_log_domain); | ||
3790 | _log_domain = -1; | ||
3791 | } | ||
3792 | } | ||
3793 | } | ||
3794 | |||
3795 | void | ||
3796 | _edje_lua2_script_load(Edje_Part_Collection *edc __UNUSED__, void *data __UNUSED__, int size __UNUSED__) // Stack usage [-16, +20, em] | ||
3797 | { | ||
3798 | #ifndef RASTER_FORGOT_WHY | ||
3799 | _elua_init(); // Stack usage [-16, +20, em] | ||
3800 | #endif | ||
3801 | } | ||
3802 | |||
3803 | void | ||
3804 | _edje_lua2_script_unload(Edje_Part_Collection *edc __UNUSED__) // Stack usage [-0, +0, e] | ||
3805 | { | ||
3806 | #ifndef RASTER_FORGOT_WHY | ||
3807 | lua_State *L; | ||
3808 | |||
3809 | if (!lstate) return; | ||
3810 | L = lstate; | ||
3811 | lua_gc(L, LUA_GCCOLLECT, 0); // Stack usage [-0, +0, e] | ||
3812 | #endif | ||
3813 | } | ||
3814 | |||
3815 | void | ||
3816 | _edje_lua2_error_full(const char *file, const char *fnc, int line, | ||
3817 | lua_State *L, int err_code) // Stack usage [-0, +0, m] | ||
3818 | { | ||
3819 | const char *err_type; | ||
3820 | |||
3821 | switch (err_code) | ||
3822 | { | ||
3823 | case LUA_ERRRUN: | ||
3824 | err_type = "runtime"; | ||
3825 | break; | ||
3826 | case LUA_ERRSYNTAX: | ||
3827 | err_type = "syntax"; | ||
3828 | break; | ||
3829 | case LUA_ERRMEM: | ||
3830 | err_type = "memory allocation"; | ||
3831 | break; | ||
3832 | case LUA_ERRERR: | ||
3833 | err_type = "error handler"; | ||
3834 | break; | ||
3835 | default: | ||
3836 | err_type = "unknown"; | ||
3837 | break; | ||
3838 | } | ||
3839 | eina_log_print | ||
3840 | (_edje_default_log_dom, EINA_LOG_LEVEL_ERR, file, fnc, line, | ||
3841 | "Lua %s error: %s", err_type, lua_tostring(L, -1)); // Stack usage [-0, +0, m] | ||
3842 | } | ||
3843 | |||
3844 | /** | ||
3845 | @page luaref | ||
3846 | @section callbacks Lua callbacks | ||
3847 | |||
3848 | These are lua functions that are called by the lua edje system when certain | ||
3849 | events occur. If the functions don't exist in the lua group, they don't get | ||
3850 | called. | ||
3851 | |||
3852 | */ | ||
3853 | |||
3854 | /** | ||
3855 | @page luaref | ||
3856 | @subsection edje_shutdown Edje shutdown() callback. | ||
3857 | |||
3858 | If a function called "shutdown" exists in a lua edje group, then it is called when | ||
3859 | that edje gets deleted. | ||
3860 | */ | ||
3861 | void | ||
3862 | _edje_lua2_script_func_shutdown(Edje *ed) // Stack usage [-1, +1, em] | ||
3863 | { | ||
3864 | int err; | ||
3865 | |||
3866 | lua_getglobal(ed->L, "shutdown"); // Stack usage [-0, +1, e] | ||
3867 | if (!lua_isnil(ed->L, -1)) // Stack usage [-0, +0, -] | ||
3868 | { | ||
3869 | if ((err = lua_pcall(ed->L, 0, 0, 0))) // Stack usage [-1, +0, -] | ||
3870 | _edje_lua2_error(ed->L, err); // Stack usage [-0, +0, m] | ||
3871 | } | ||
3872 | else | ||
3873 | lua_pop(ed->L, 1); // Stack usage [-n, +0, -] | ||
3874 | _edje_lua2_script_shutdown(ed); | ||
3875 | } | ||
3876 | |||
3877 | /** | ||
3878 | @page luaref | ||
3879 | @subsection edje_show Edje show() callback. | ||
3880 | |||
3881 | If a function called "show" exists in a lua edje group, then it is called when | ||
3882 | that edje gets shown. | ||
3883 | */ | ||
3884 | void | ||
3885 | _edje_lua2_script_func_show(Edje *ed) // Stack usage [-1, +1, e] | ||
3886 | { | ||
3887 | int err; | ||
3888 | |||
3889 | lua_getglobal(ed->L, "show"); | ||
3890 | if (!lua_isnil(ed->L, -1)) | ||
3891 | { | ||
3892 | if ((err = lua_pcall(ed->L, 0, 0, 0))) | ||
3893 | _edje_lua2_error(ed->L, err); | ||
3894 | } | ||
3895 | else | ||
3896 | lua_pop(ed->L, 1); | ||
3897 | } | ||
3898 | |||
3899 | /** | ||
3900 | @page luaref | ||
3901 | @subsection edje_hide Edje hide() callback. | ||
3902 | |||
3903 | If a function called "hide" exists in a lua edje group, then it is called when | ||
3904 | that edje gets hidden. | ||
3905 | */ | ||
3906 | void | ||
3907 | _edje_lua2_script_func_hide(Edje *ed) // Stack usage [-1, +1, e] | ||
3908 | { | ||
3909 | int err; | ||
3910 | |||
3911 | lua_getglobal(ed->L, "hide"); | ||
3912 | if (!lua_isnil(ed->L, -1)) | ||
3913 | { | ||
3914 | if ((err = lua_pcall(ed->L, 0, 0, 0))) | ||
3915 | _edje_lua2_error(ed->L, err); | ||
3916 | } | ||
3917 | else | ||
3918 | lua_pop(ed->L, 1); | ||
3919 | } | ||
3920 | |||
3921 | /** | ||
3922 | @page luaref | ||
3923 | @subsection edje_move Edje move(x, y) callback. | ||
3924 | |||
3925 | If a function called "move" exists in a lua edje group, then it is called when | ||
3926 | that edje gets moved, with the new position passed to it. | ||
3927 | */ | ||
3928 | void | ||
3929 | _edje_lua2_script_func_move(Edje *ed) // Stack usage [-3, +3, e] or [-1, +1, e] if no matching function. | ||
3930 | { | ||
3931 | int err; | ||
3932 | |||
3933 | // FIXME: move all objects created by script | ||
3934 | lua_getglobal(ed->L, "move"); // Stack usage [-0, +1, e] | ||
3935 | if (!lua_isnil(ed->L, -1)) // Stack usage [-0, +0, -] | ||
3936 | { | ||
3937 | lua_pushinteger(ed->L, ed->x); // Stack usage [-0, +1, -] | ||
3938 | lua_pushinteger(ed->L, ed->y); // Stack usage [-0, +1, -] | ||
3939 | if ((err = lua_pcall(ed->L, 2, 0, 0))) // Stack usage [-3, +0, -] | ||
3940 | _edje_lua2_error(ed->L, err); | ||
3941 | } | ||
3942 | else | ||
3943 | lua_pop(ed->L, 1); // Stack usage [-n, +0, -] | ||
3944 | } | ||
3945 | |||
3946 | /** | ||
3947 | @page luaref | ||
3948 | @subsection edje_resize Edje resize(w, h) callback. | ||
3949 | |||
3950 | If a function called "resize" exists in a lua edje group, then it is called when | ||
3951 | that edje gets resized, with the new size passed to it. | ||
3952 | */ | ||
3953 | void | ||
3954 | _edje_lua2_script_func_resize(Edje *ed) // Stack usage [-3, +3, e] or [-1, +1, e] if no matching function. | ||
3955 | { | ||
3956 | int err; | ||
3957 | |||
3958 | lua_getglobal(ed->L, "resize"); | ||
3959 | if (!lua_isnil(ed->L, -1)) | ||
3960 | { | ||
3961 | lua_pushinteger(ed->L, ed->w); | ||
3962 | lua_pushinteger(ed->L, ed->h); | ||
3963 | if ((err = lua_pcall(ed->L, 2, 0, 0))) | ||
3964 | _edje_lua2_error(ed->L, err); | ||
3965 | } | ||
3966 | else | ||
3967 | lua_pop(ed->L, 1); | ||
3968 | } | ||
3969 | |||
3970 | /** | ||
3971 | @page luaref | ||
3972 | @subsection edje_message Edje message(id, type, ...) callback. | ||
3973 | |||
3974 | If a function called "message" exists in a lua edje group, then it is called when | ||
3975 | that edje gets gets a message sent to it, with the message details passed to it. | ||
3976 | See edje:messagesend() for details of what each type means. The arrays are | ||
3977 | passed as a table. | ||
3978 | */ | ||
3979 | void | ||
3980 | _edje_lua2_script_func_message(Edje *ed, Edje_Message *em) // Stack usage [-?, +?, em] It's complicated, but it's even at least. | ||
3981 | { | ||
3982 | int err, n, c, i; | ||
3983 | |||
3984 | lua_getglobal(ed->L, "message"); // Stack usage [-0, +1, e] | ||
3985 | if (!lua_isnil(ed->L, -1)) // Stack usage [-0, +0, -] | ||
3986 | { | ||
3987 | n = 2; | ||
3988 | lua_pushinteger(ed->L, em->id); // Stack usage [-0, +1, -] | ||
3989 | switch (em->type) | ||
3990 | { | ||
3991 | case EDJE_MESSAGE_NONE: | ||
3992 | lua_pushstring(ed->L, "none"); // Stack usage [-0, +1, m] | ||
3993 | break; | ||
3994 | case EDJE_MESSAGE_SIGNAL: | ||
3995 | break; | ||
3996 | case EDJE_MESSAGE_STRING: | ||
3997 | lua_pushstring(ed->L, "str"); // Stack usage [-0, +1, m] | ||
3998 | lua_pushstring(ed->L, ((Edje_Message_String *)em->msg)->str); | ||
3999 | // Stack usage [-0, +1, m] | ||
4000 | n += 1; | ||
4001 | break; | ||
4002 | case EDJE_MESSAGE_INT: | ||
4003 | lua_pushstring(ed->L, "int"); // Stack usage [-0, +1, m] | ||
4004 | lua_pushinteger(ed->L, ((Edje_Message_Int *)em->msg)->val); | ||
4005 | // Stack usage [-0, +1, -] | ||
4006 | n += 1; | ||
4007 | break; | ||
4008 | case EDJE_MESSAGE_FLOAT: | ||
4009 | lua_pushstring(ed->L, "float"); // Stack usage [-0, +1, m] | ||
4010 | lua_pushnumber(ed->L, ((Edje_Message_Float *)em->msg)->val); | ||
4011 | // Stack usage [-0, +1, -] | ||
4012 | n += 1; | ||
4013 | break; | ||
4014 | case EDJE_MESSAGE_STRING_SET: | ||
4015 | lua_pushstring(ed->L, "strset"); // Stack usage [-0, +1, m] | ||
4016 | c = ((Edje_Message_String_Set *)em->msg)->count; | ||
4017 | lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m] | ||
4018 | for (i = 0; i < c; i++) | ||
4019 | { | ||
4020 | lua_pushstring(ed->L, ((Edje_Message_String_Set *)em->msg)->str[i]); | ||
4021 | // Stack usage [-0, +1, m] | ||
4022 | // It's OK to bypass the metatable in these cases, | ||
4023 | // we create the table, and know there is no metatable. B-) | ||
4024 | lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m] | ||
4025 | } | ||
4026 | n += 1; | ||
4027 | break; | ||
4028 | case EDJE_MESSAGE_INT_SET: | ||
4029 | lua_pushstring(ed->L, "intset"); // Stack usage [-0, +1, m] | ||
4030 | c = ((Edje_Message_Int_Set *)em->msg)->count; | ||
4031 | lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m] | ||
4032 | for (i = 0; i < c; i++) | ||
4033 | { | ||
4034 | lua_pushinteger(ed->L, ((Edje_Message_Int_Set *)em->msg)->val[i]); | ||
4035 | // Stack usage [-0, +1, -] | ||
4036 | lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m] | ||
4037 | } | ||
4038 | n += 1; | ||
4039 | break; | ||
4040 | case EDJE_MESSAGE_FLOAT_SET: | ||
4041 | lua_pushstring(ed->L, "floatset"); // Stack usage [-0, +1, m] | ||
4042 | c = ((Edje_Message_Float_Set *)em->msg)->count; | ||
4043 | lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m] | ||
4044 | for (i = 0; i < c; i++) | ||
4045 | { | ||
4046 | lua_pushnumber(ed->L, ((Edje_Message_Float_Set *)em->msg)->val[i]); | ||
4047 | // Stack usage [-0, +1, -] | ||
4048 | lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m] | ||
4049 | } | ||
4050 | n += 1; | ||
4051 | break; | ||
4052 | case EDJE_MESSAGE_STRING_INT: | ||
4053 | lua_pushstring(ed->L, "strint"); // Stack usage [-0, +1, m] | ||
4054 | lua_pushstring(ed->L, ((Edje_Message_String_Int *)em->msg)->str); | ||
4055 | // Stack usage [-0, +1, m] | ||
4056 | lua_pushinteger(ed->L, ((Edje_Message_String_Int *)em->msg)->val); | ||
4057 | // Stack usage [-0, +1, -] | ||
4058 | n += 2; | ||
4059 | break; | ||
4060 | case EDJE_MESSAGE_STRING_FLOAT: | ||
4061 | lua_pushstring(ed->L, "strfloat"); // Stack usage [-0, +1, m] | ||
4062 | lua_pushstring(ed->L, ((Edje_Message_String_Float *)em->msg)->str); | ||
4063 | // Stack usage [-0, +1, m] | ||
4064 | lua_pushnumber(ed->L, ((Edje_Message_String_Float *)em->msg)->val); | ||
4065 | // Stack usage [-0, +1, -] | ||
4066 | n += 2; | ||
4067 | break; | ||
4068 | case EDJE_MESSAGE_STRING_INT_SET: | ||
4069 | lua_pushstring(ed->L, "strintset"); // Stack usage [-0, +1, m] | ||
4070 | lua_pushstring(ed->L, ((Edje_Message_String_Int_Set *)em->msg)->str); | ||
4071 | // Stack usage [-0, +1, m] | ||
4072 | c = ((Edje_Message_String_Int_Set *)em->msg)->count; | ||
4073 | lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m] | ||
4074 | for (i = 0; i < c; i++) | ||
4075 | { | ||
4076 | lua_pushinteger(ed->L, ((Edje_Message_String_Int_Set *)em->msg)->val[i]); | ||
4077 | // Stack usage [-0, +1, -] | ||
4078 | lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m] | ||
4079 | } | ||
4080 | n += 2; | ||
4081 | break; | ||
4082 | case EDJE_MESSAGE_STRING_FLOAT_SET: | ||
4083 | lua_pushstring(ed->L, "strfloatset"); // Stack usage [-0, +1, m] | ||
4084 | lua_pushstring(ed->L, ((Edje_Message_String_Float_Set *)em->msg)->str); | ||
4085 | // Stack usage [-0, +1, m] | ||
4086 | c = ((Edje_Message_String_Float_Set *)em->msg)->count; | ||
4087 | lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m] | ||
4088 | for (i = 0; i < c; i++) | ||
4089 | { | ||
4090 | lua_pushnumber(ed->L, ((Edje_Message_String_Float_Set *)em->msg)->val[i]); | ||
4091 | // Stack usage [-0, +1, -] | ||
4092 | lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m] | ||
4093 | } | ||
4094 | n += 2; | ||
4095 | break; | ||
4096 | default: | ||
4097 | break; | ||
4098 | } | ||
4099 | if ((err = lua_pcall(ed->L, n, 0, 0))) // Stack usage [-n+1, +0, -] | ||
4100 | _edje_lua2_error(ed->L, err); | ||
4101 | } | ||
4102 | else | ||
4103 | lua_pop(ed->L, 1); // Stack usage [-n, +0, -] | ||
4104 | } | ||
4105 | |||
4106 | /** | ||
4107 | @page luaref | ||
4108 | @subsection edje_signal Edje signal(signal, source) callback. | ||
4109 | |||
4110 | If a function called "signal" exists in a lua edje group, then it is called when | ||
4111 | ever a signal arrives, with the signal details passed to it. | ||
4112 | |||
4113 | */ | ||
4114 | void | ||
4115 | _edje_lua2_script_func_signal(Edje *ed, const char *sig, const char *src) // Stack usage [-3, +3, em] or [-1, +1, e] if no matching function. | ||
4116 | { | ||
4117 | int err; | ||
4118 | |||
4119 | lua_getglobal(ed->L, "signal"); | ||
4120 | if (!lua_isnil(ed->L, -1)) | ||
4121 | { | ||
4122 | lua_pushstring(ed->L, sig); | ||
4123 | lua_pushstring(ed->L, src); | ||
4124 | if ((err = lua_pcall(ed->L, 2, 0, 0))) | ||
4125 | _edje_lua2_error(ed->L, err); | ||
4126 | } | ||
4127 | else | ||
4128 | lua_pop(ed->L, 1); | ||
4129 | } | ||