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