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