1 // FIXME: Some error checking would be nice.
4 #include "edje_private.h"
7 #define RASTER_FORGOT_WHY "this is here."
10 //--------------------------------------------------------------------------//
11 #define MAX_LUA_MEM (4 * (1024 * 1024))
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__)
21 @page luaref Edje Lua scripting
23 @section intro Introduction
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.
31 To get you started, here's an example that uses most of this lua API:
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
39 @section args Lua function argument and return syntax
41 Some of the lua functions can accept a table as well as separate arguments.
42 Some of them return tables.
44 @section classes Lua classes
49 Lua functions stack usage.
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.
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.
58 Should do the same for the support functions. These ARE more important to check.
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;
70 struct _Edje_Lua_Alloc
80 void (*free_func) (void *obj);
84 struct _Edje_Lua_Animator
87 Ecore_Animator *animator;
91 struct _Edje_Lua_Timer
98 struct _Edje_Lua_Transition
101 Ecore_Animator *animator;
102 double transition, start;
106 struct _Edje_Lua_Evas_Object
109 Evas_Object *evas_obj;
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);
123 //--------------------------------------------------------------------------//
124 #ifndef RASTER_FORGOT_WHY
125 static lua_State *lstate = NULL;
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;
132 static int panics = 0;
133 static int _log_domain = -1;
134 static int _log_count = 0;
136 // FIXME: methods lua script can provide that edje will call (not done yet):
140 // // get dragable pos
141 // // set dragable pos
142 // // set drag size, step, page
143 // // get drag size, step, page
148 // // get swallow part
149 // // set swallow 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)
160 // // parts extends calc
161 // // part object get
162 // // part geometry get
164 // // LATER: all the entry calls
165 // // LATER: box and table calls
166 // // LATER: perspective stuff change
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";
181 static int _elua_obj_gc(lua_State *L);
183 static const struct luaL_Reg _elua_edje_gc_funcs [] =
185 {"__gc", _elua_obj_gc}, // garbage collector func for edje objects
190 static const luaL_Reg _elua_libs[] =
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
204 //--------------------------------------------------------------------------//
206 _elua_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
208 Edje_Lua_Alloc *ela = ud;
211 ela->cur += nsize - osize;
212 if (ela->cur > ela->max)
214 ERR("Lua memory limit of %zu bytes reached (%zu allocated)",
224 ptr2 = realloc(ptr, nsize);
225 if (ptr2) return ptr2;
226 ERR("Lua cannot re-allocate %zu bytes", nsize);
231 _elua_custom_panic(lua_State *L) // Stack usage [-0, +0, m]
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.
238 EINA_LOG_DOM_CRIT(_edje_default_log_dom, "Lua PANICS!!!!!");
242 EINA_LOG_DOM_CRIT(_edje_default_log_dom,
243 "Lua PANIC!!!!!: %s", lua_tostring(L, -1)); // Stack usage [-0, +0, m]
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.
253 // Really only used to manage the pointer to our edje.
255 _elua_table_ptr_set(lua_State *L, const void *key, const void *val) // Stack usage [-2, +2, e]
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]
263 _elua_table_ptr_get(lua_State *L, const void *key) // Stack usage [-2, +2, e]
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, -]
275 _elua_table_ptr_del(lua_State *L, const void *key) // Stack usage [-2, +2, e]
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]
284 * Cori: Assumes object to be saved on top of stack
287 _elua_ref_set(lua_State *L, void *key) // Stack usage [-4, +4, m]
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, -]
298 * Cori: Get an object from the object table
301 _elua_ref_get(lua_State *L, void *key) // Stack usage [-3, +4, -]
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, -]
311 static Edje_Lua_Obj *
312 _elua_obj_new(lua_State *L, Edje *ed, int size, const char *metatable) // Stack usage [-5, +6, m]
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));
320 luaL_getmetatable(L, metatable); // Stack usage [-0, +1, -]
321 lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
323 obj->meta = metatable;
325 _elua_ref_set(L, obj); // Stack usage [-4, +4, m]
330 _elua_obj_free(lua_State *L __UNUSED__, Edje_Lua_Obj *obj)
332 if (!obj->free_func) return;
334 obj->ed->lua_objs = eina_inlist_remove(obj->ed->lua_objs, EINA_INLIST_GET(obj));
335 obj->free_func = NULL;
340 _elua_obj_gc(lua_State *L) // Stack usage [-0, +0, -]
342 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
344 _elua_obj_free(L, obj);
349 _elua_obj_del(lua_State *L) // Stack usage [-0, +0, -]
351 return _elua_obj_gc(L); // Stack usage [-0, +0, -]
355 _elua_gc(lua_State *L) // Stack usage [-0, +0, e]
357 lua_gc(L, LUA_GCCOLLECT, 0); // Stack usage [-0, +0, e]
360 // These are what the various symbols are for each type -
365 // FIXME: Still to do, if we ever use them -
374 _elua_push_name(lua_State *L, char *q, int idx) // Stack usage [-0, +1, e or m]
379 // A simplistic scan through an identifier, it's wrong, but it's quick,
380 // and we don't mind that it's wrong, coz this is only internal.
381 while (isalnum((int)*q))
386 lua_getfield(L, idx, p); // Stack usage [-0, +1, e]
388 lua_pushstring(L, p); // Stack usage [-0, +1, m]
395 _elua_scan_params(lua_State *L, int i, char *params, ...) // Stack usage -
402 char *f = strdup(params);
404 int n = 0, j = i, count = 0;
405 Eina_Bool table = EINA_FALSE;
408 va_start(vl, params);
410 if (lua_istable(L, i)) // Stack usage [-0, +0, -]
419 Eina_Bool get = EINA_TRUE;
421 while (isspace((int)*p))
430 q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e]
432 if (lua_isnumber(L, j)) // Stack usage [-0, +0, -]
434 int *v = va_arg(vl, int *);
435 *v = lua_tointeger(L, j); // Stack usage [-0, +0, -]
444 q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e]
446 if (lua_isnumber(L, j)) // Stack usage [-0, +0, -]
448 double *v = va_arg(vl, double *);
449 *v = lua_tonumber(L, j); // Stack usage [-0, +0, -]
458 q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e]
460 if (lua_isstring(L, j)) // Stack usage [-0, +0, -]
462 char **v = va_arg(vl, char **);
464 char *temp = (char *) lua_tolstring(L, j, &len); // Stack usage [-0, +0, m]
466 len++; // Cater for the null at the end.
470 memcpy(*v, temp, len);
480 q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e]
482 if (lua_isboolean(L, j)) // Stack usage [-0, +0, -]
484 int *v = va_arg(vl, int *);
485 *v = lua_toboolean(L, j); // Stack usage [-0, +0, -]
501 // If this is a table, then we pushed a value on the stack, pop it off.
502 lua_pop(L, 1); // Stack usage [-n, +0, -]
521 _elua_ret(lua_State *L, char *params, ...) // Stack usage [-(2*n), +(2*n+1), em]
524 char *f = strdup(params);
530 lua_newtable(L); // Stack usage [-0, +1, m]
531 va_start(vl, params);
536 Eina_Bool set = EINA_TRUE;
538 while (isspace((int)*p))
545 q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m]
546 lua_pushinteger(L, va_arg(vl, int)); // Stack usage [-0, +1, -]
551 q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m]
552 lua_pushnumber(L, va_arg(vl, double)); // Stack usage [-0, +1, -]
557 q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m]
558 lua_pushstring(L, va_arg(vl, char *)); // Stack usage [-0, +1, m]
563 q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m]
564 lua_pushboolean(L, va_arg(vl, int)); // Stack usage [-0, +1, -]
576 lua_settable(L, -3); // Stack usage [-2, +0, e]
588 _elua_color_fix(int *r, int *g, int *b, int *a)
590 if (*r > *a) *r = *a;
591 if (*g > *a) *g = *a;
592 if (*b > *a) *b = *a;
595 //--------------------------------------------------------------------------//
599 @subsection edje Edje class.
601 The lua edje class includes functions for dealing with the lua script only group
602 as an edje object, basic functions, and functions to create other objects.
604 In the following, "edje" is the actual global table used to access these edje functions.
607 static int _elua_echo(lua_State *L);
609 static int _elua_date(lua_State *L);
610 static int _elua_looptime(lua_State *L);
611 static int _elua_seconds(lua_State *L);
612 static int _elua_version(lua_State *L);
614 static int _elua_objgeom(lua_State *L);
615 static int _elua_objpos(lua_State *L);
616 static int _elua_objsize(lua_State *L);
618 static int _elua_emit(lua_State *L);
619 static int _elua_messagesend(lua_State *L);
621 static int _elua_animator(lua_State *L);
622 static int _elua_timer(lua_State *L);
623 static int _elua_transition(lua_State *L);
625 static int _elua_color_class(lua_State *L);
626 static int _elua_text_class(lua_State *L);
628 static int _elua_edje(lua_State *L);
629 static int _elua_image(lua_State *L);
630 static int _elua_line(lua_State *L);
631 static int _elua_map(lua_State *L);
632 static int _elua_polygon(lua_State *L);
633 static int _elua_rect(lua_State *L);
634 static int _elua_text(lua_State *L);
635 //static int _elua_textblock(lua_State *L); /* XXX: disabled until there are enough textblock functions implemented to make it actually useful
637 static const char *_elua_edje_api = "edje";
638 static const struct luaL_Reg _elua_edje_funcs [] =
640 // add an echo too to make it more shelly
641 {"echo", _elua_echo}, // test func - echo (i know we have print. test)
642 // FIXME: add logging functions here, probably to it's own domain, or even a script defined domain.
644 // system information (time, date blah blah)
645 {"date", _elua_date}, // get date in a table
646 {"looptime", _elua_looptime}, // get loop time
647 {"seconds", _elua_seconds}, // get seconds
648 {"version", _elua_version}, // edje version
650 // query edje - size, pos
651 {"geom", _elua_objgeom}, // get while edje object geometry in canvas
652 {"pos", _elua_objpos}, // get while edje object pos in canvas
653 {"size", _elua_objsize}, // get while edje object pos in canvas
655 // talk to application/caller
656 {"emit", _elua_emit}, // emit signal + src
657 {"messagesend", _elua_messagesend}, // send a structured message
659 // time based "callback" systems
660 {"animator", _elua_animator}, // add animator
661 {"timer", _elua_timer}, // add timer
662 {"transition", _elua_transition}, // add transition
663 // FIXME: need poller
665 // set and query color / text class
666 {"color_class", _elua_color_class},
667 {"text_class", _elua_text_class},
669 // create new objects
670 {"edje", _elua_edje},
671 {"image", _elua_image}, // defaults to a filled image.
672 {"line", _elua_line},
674 {"polygon", _elua_polygon},
675 {"rect", _elua_rect},
676 {"text", _elua_text},
677 // {"textblock", _elua_textblock}, /* XXX: disabled until there are enough textblock functions implemented to make it actually useful
679 // FIXME: add the new sound stuff.
686 @subsubsection edje_echo edje:echo(text)
688 Make lua a bit shelly. Prints a string to the console
690 @param text The string to print.
693 _elua_echo(lua_State *L) // Stack usage [-0, +0, v]
695 const char *string = luaL_checkstring(L, 1); // Stack usage [-0, +0, v]
703 @subsubsection edje_date edje:date()
705 Retrieves the current time and date.
707 Wraps gettimeofday(), as passed through localtime().
709 @return A table with these fields:
710 - integer year: Year.
711 - integer month: Month of the year.
712 - integer day: Day of the month.
713 - integer yearday: Day of the year.
714 - integer weekday: Day of the week.
715 - integer hour: Hour of the day (24 hour format).
716 - integer min: Minute of the hour.
717 - number sec: Seconds as a number.
721 _elua_date(lua_State *L) // Stack usage [-16, +17, em]
723 static time_t last_tzset = 0;
724 struct timeval timev;
728 gettimeofday(&timev, NULL);
729 tt = (time_t)(timev.tv_sec);
730 if ((tt > (last_tzset + 1)) || (tt < (last_tzset - 1)))
737 { // Stack usage [-16, +17, em]
738 _elua_ret(L, "%year %month %day %yearday %weekday %hour %min #sec",
739 (int)(tm->tm_year + 1900),
740 (int)(tm->tm_mon + 1),
743 (int)((tm->tm_wday + 6) % 7),
746 (double)((double)tm->tm_sec + (((double)timev.tv_usec) / 1000000))
756 @subsubsection edje_looptime edje:looptime()
758 Retrieves the time at which the last loop stopped waiting for timeouts or events.
760 This gets the time that the main loop ceased waiting for timouts and/or events
761 to come in or for signals or any other interrupt source. This should be
762 considered a reference point for all time based activity that should calculate
763 its timepoint from the return of edje:looptime(). Use this UNLESS you absolutely
764 must get the current actual timepoint - then use edje:seconds(). Note that this
765 time is meant to be used as relative to other times obtained on this run.
767 Wraps ecore_loop_time_get().
769 @returns A number of seconds.
772 _elua_looptime(lua_State *L) // Stack usage [-0, +1, -]
774 double t = ecore_loop_time_get();
775 lua_pushnumber(L, t); // Stack usage [-0, +1, -]
781 @subsubsection edje_seconds edje:seconds()
783 Retrieves the current system time as a floating point value in seconds.
785 This uses a monotonic clock and thus never goes back in time while machine is
786 live (even if user changes time or timezone changes, however it may be reset
787 whenever the machine is restarted).
789 Wraps ecore_time_get().
791 @returns A number of seconds.
794 _elua_seconds(lua_State *L) // Stack usage [-0, +1, -]
796 double t = ecore_time_get();
797 lua_pushnumber(L, t); // Stack usage [-0, +1, -]
803 @subsubsection edje_version edje:version()
805 Retrieves the current edje version number.
807 @returns A table with these fields:
808 - integer major: The edje version major number.
809 - integer minor: The edje version minor number.
814 _elua_version(lua_State *L) // Stack usage [-4, +5, em]
816 _elua_ret(L, "%major %minor", EDJE_VERSION_MAJOR, EDJE_VERSION_MINOR); // Stack usage [-4, +5, em]
823 @subsubsection edje_geom edje:geom()
825 Retrieves the position and size of the edje object that this lua group is in.
827 @returns A table with these fields:
828 - integer x: The edjes X position.
829 - integer y: The edjes Y position.
830 - integer w: The edjes width.
831 - integer h: The edjes height.
834 _elua_objgeom(lua_State *L) // Stack usage [-10, +11, em]
836 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
837 _elua_ret(L, "%x %y %w %h", ed->x, ed->y, ed->w, ed->h); // Stack usage [-8, +9, em]
843 @subsubsection edje_pos edje:pos()
846 Retrieves the position of the edje object that this lua group is in.
848 @returns A table with these fields:
849 - integer x: The edjes X position.
850 - integer y: The edjes Y position.
853 _elua_objpos(lua_State *L) // Stack usage [-6, +7, em]
855 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
856 _elua_ret(L, "%x %y", ed->x, ed->y); // Stack usage [-4, +5, em]
862 @subsubsection edje_size edje:size()
865 Retrieves the size of the edje object that this lua group is in.
867 @returns A table with these fields:
868 - integer w: The edjes width.
869 - integer h: The edjes height.
872 _elua_objsize(lua_State *L) // Stack usage [-6, +7, em]
874 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
875 _elua_ret(L, "%w %h", ed->w, ed->h); // Stack usage [-4, +5, em]
882 @subsubsection edje_emit edje:emit(signal, source)
886 Wraps edje_object_signal_emit().
888 @param signal The signal string to send.
889 @param source The source string of the signal.
891 NOTE: The source string will have a name and a colon prepended to in when it is
892 delivered to things that are not this edje, like C and other edje groups.
893 If this edje is a top level edje, then it will be the name of the group (I think).
894 If this edje is swallowed into some other part, then it will be the name of the
899 FIXME: I actually have no idea what happens if it's swallowed into another lua
903 _elua_emit(lua_State *L) // Stack usage [-2, +2, ev]
905 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
906 const char *sig = luaL_checkstring(L, 1); // Stack usage [-0, +0, v]
907 const char *src = luaL_checkstring(L, 2); // Stack usage [-0, +0, v]
908 if ((!sig) || (!src)) return 0;
909 _edje_emit(ed, sig, src);
915 @subsubsection edje_message_send edje:messagesend(id, type, ...)
917 Send a message to this edje, and all it's child objects.
919 Wraps edje_object_message_send().
921 @param id An identification integer for the message.
922 @param type The type of message to send.
923 @param ... Zero or more things to send as part of the message, depending on the type.
925 The type can be one of:
927 - sig: The msg is two strings (signal, source), sent as a signal.
928 - str: The msg is a C string.
929 - int: The message is a C integer.
930 - float: The message is a C float.
931 - strset: The message is an array of C strings.
932 - intset: The message is an array of C integers.
933 - floatset: The message is an array of C floats.
934 - strint: The message is a C stnring and a C integer.
935 - strfloat: The message is a C string and a C float.
936 - strintset: The message is a C string and an array of C integers.
937 - strfloatset: The message is a G string and an array of C floats.
939 For the array types, the lua caller passes a table.
942 _elua_messagesend(lua_State *L) // Stack usage [-2, +2, ev] plus [-2, +2] for every element if it's an array message.
944 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
945 int id = luaL_checkinteger(L, 1); // Stack usage [-0, +0, v]
946 const char *type = luaL_checkstring(L, 2); // Stack usage [-0, +0, v]
948 if (!strcmp(type, "none"))
950 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_NONE, id, NULL);
952 else if (!strcmp(type, "sig"))
954 const char *sig = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
955 const char *src = luaL_checkstring(L, 4); // Stack usage [-0, +0, v]
956 _edje_emit(ed, sig, src);
958 else if (!strcmp(type, "str"))
960 Edje_Message_String *emsg;
961 const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
962 emsg = alloca(sizeof(Edje_Message_String));
963 emsg->str = (char *)str;
964 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING, id, emsg);
966 else if (!strcmp(type, "int"))
968 Edje_Message_Int *emsg;
969 int val = luaL_checkinteger(L, 3); // Stack usage [-0, +0, v]
970 emsg = alloca(sizeof(Edje_Message_Int));
972 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_INT, id, emsg);
974 else if (!strcmp(type, "float"))
976 Edje_Message_Float *emsg;
977 float val = luaL_checknumber(L, 3); // Stack usage [-0, +0, v]
978 emsg = alloca(sizeof(Edje_Message_Float));
980 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_FLOAT, id, emsg);
982 else if (!strcmp(type, "strset"))
984 Edje_Message_String_Set *emsg;
987 luaL_checktype(L, 3, LUA_TTABLE); // Stack usage [-0, +0, v]
988 n = lua_objlen(L, 3); // Stack usage [-0, +0, -]
989 emsg = alloca(sizeof(Edje_Message_String_Set) + ((n - 1) * sizeof(char *)));
991 for (i = 1; i <= n; i ++)
993 lua_pushinteger(L, i); // Stack usage [-0, +1, -]
994 lua_gettable(L, 3); // Stack usage [-1, +1, e]
995 str = lua_tostring(L, -1); // Stack usage [-0, +0, m]
996 lua_pop(L, 1); // Stack usage [-n, +0, -]
997 emsg->str[i - 1] = (char *)str;
999 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_SET, id, emsg);
1001 else if (!strcmp(type, "intset"))
1003 Edje_Message_Int_Set *emsg;
1005 luaL_checktype(L, 3, LUA_TTABLE); // Stack usage [-0, +0, v]
1006 n = lua_objlen(L, 3); // Stack usage [-0, +0, -]
1007 emsg = alloca(sizeof(Edje_Message_Int_Set) + ((n - 1) * sizeof(int)));
1009 for (i = 1; i <= n; i ++)
1011 lua_pushinteger(L, i); // Stack usage [-0, +1, -]
1012 lua_gettable(L, 3); // Stack usage [-1, +1, e]
1013 emsg->val[i - 1] = lua_tointeger(L, -1); // Stack usage [-0, +0, -]
1014 lua_pop(L, 1); // Stack usage [-n, +0, -]
1016 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_INT_SET, id, emsg);
1018 else if (!strcmp(type, "floatset"))
1020 Edje_Message_Float_Set *emsg;
1022 luaL_checktype(L, 3, LUA_TTABLE); // Stack usage [-0, +0, v]
1023 n = lua_objlen(L, 3); // Stack usage [-0, +0, -]
1024 emsg = alloca(sizeof(Edje_Message_Float_Set) + ((n - 1) * sizeof(double)));
1026 for (i = 1; i <= n; i ++)
1028 lua_pushinteger(L, i); // Stack usage [-0, +1, -]
1029 lua_gettable(L, 3); // Stack usage [-1, +1, e]
1030 emsg->val[i - 1] = lua_tonumber(L, -1); // Stack usage [-0, +0, -]
1031 lua_pop(L, 1); // Stack usage [-n, +0, -]
1033 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_FLOAT_SET, id, emsg);
1035 else if (!strcmp(type, "strint"))
1037 Edje_Message_String_Int *emsg;
1038 const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
1039 emsg = alloca(sizeof(Edje_Message_String_Int));
1040 emsg->str = (char *)str;
1041 emsg->val = luaL_checkinteger(L, 4); // Stack usage [-0, +0, v]
1042 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_INT, id, emsg);
1044 else if (!strcmp(type, "strfloat"))
1046 Edje_Message_String_Float *emsg;
1047 const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
1048 emsg = alloca(sizeof(Edje_Message_String_Float));
1049 emsg->str = (char *)str;
1050 emsg->val = luaL_checknumber(L, 4); // Stack usage [-0, +0, v]
1051 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_FLOAT, id, emsg);
1053 else if (!strcmp(type, "strintset"))
1055 Edje_Message_String_Int_Set *emsg;
1057 const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
1059 luaL_checktype(L, 4, LUA_TTABLE); // Stack usage [-0, +0, v]
1060 n = lua_objlen(L, 4); // Stack usage [-0, +0, -]
1061 emsg = alloca(sizeof(Edje_Message_String_Int_Set) + ((n - 1) * sizeof(int)));
1062 emsg->str = (char *)str;
1064 for (i = 1; i <= n; i ++)
1066 lua_pushinteger(L, i); // Stack usage [-0, +1, -]
1067 lua_gettable(L, 4); // Stack usage [-1, +1, e]
1068 emsg->val[i - 1] = lua_tointeger(L, -1); // Stack usage [-0, +0, -]
1069 lua_pop(L, 1); // Stack usage [-n, +0, -]
1071 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_INT_SET, id, emsg);
1073 else if (!strcmp(type, "strfloatset"))
1075 Edje_Message_String_Float_Set *emsg;
1077 const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
1079 luaL_checktype(L, 4, LUA_TTABLE); // Stack usage [-0, +0, v]
1080 n = lua_objlen(L, 4);
1081 emsg = alloca(sizeof(Edje_Message_String_Float_Set) + ((n - 1) * sizeof(double)));
1082 emsg->str = (char *)str;
1084 for (i = 1; i <= n; i ++)
1086 lua_pushinteger(L, i); // Stack usage [-0, +1, -]
1087 lua_gettable(L, 4); // Stack usage [-1, +1, e]
1088 emsg->val[i - 1] = lua_tonumber(L, -1); // Stack usage [-0, +0, -]
1089 lua_pop(L, 1); // Stack usage [-n, +0, -]
1091 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_FLOAT_SET, id, emsg);
1098 _elua_animator_cb(void *data) // Stack usage [-2, +2, em]
1100 Edje_Lua_Animator *ela = data;
1102 int ret = 0, err = 0;
1104 if (!ela->obj.ed) return 0;
1107 /* This is not needed, pcalls don't longjmp(), that's why they are protected.
1108 if (setjmp(panic_jmp) == 1)
1110 LE("Animator callback panic");
1111 _edje_lua2_error(L, err); // Stack usage [-0, +0, m]
1112 _elua_obj_free(L, (Edje_Lua_Obj *)ela);
1113 _elua_gc(L); // Stack usage [-0, +0, e]
1117 lua_rawgeti(L, LUA_REGISTRYINDEX, ela->fn_ref); // Stack usage [-0, +1, -]
1118 if ((err = lua_pcall(L, 0, 1, 0))) // Stack usage [-1, +1, -]
1120 _edje_lua2_error(L, err); // Stack usage [-0, +0, m]
1121 _elua_obj_free(L, (Edje_Lua_Obj *)ela);
1122 _elua_gc(L); // Stack usage [-0, +0, e]
1125 ret = lua_toboolean(L, -1); // Stack usage [-0, +0, -]
1126 lua_pop(L, 1); // Stack usage [-n, +0, -]
1127 if (ret == 0) _elua_obj_free(L, (Edje_Lua_Obj *)ela);
1128 _elua_gc(L); // Stack usage [-0, +0, e]
1133 _elua_animator_free(void *obj) // Stack usage [-0, +0, -]
1135 Edje_Lua_Animator *ela = obj;
1137 if (!ela->obj.ed) return;
1139 luaL_unref(L, LUA_REGISTRYINDEX, ela->fn_ref); // Stack usage [-0, +0, -]
1141 ecore_animator_del(ela->animator);
1142 ela->animator = NULL;
1147 @subsubsection edje_animator edje:animator(func)
1149 This function adds an animator and returns its handle on success and NULL on
1150 failure. The function func will be called every frame tick. Note that setting
1151 the frame tick is not available as a lua function, so has to be done from C.
1152 The default tick is 1/30 second.
1154 When the animator func is called, it must return a value of either true or false.
1155 If it returns true it will be called again at the next tick, or if it returns
1156 false it will be deleted automatically making any references/handles for it
1159 Wraps ecore_animator_add().
1161 @param func The function to call when the animator triggers.
1163 @returns A userdata that is an ecore animator.
1166 _elua_animator(lua_State *L) // Stack usage [-8, +9, emv]
1168 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
1169 Edje_Lua_Animator *ela;
1171 luaL_checkany(L, 1); // Stack usage [-0, +0, v]
1173 // FIXME: Allow lua to set a data to be sent back with the callback.
1174 ela = (Edje_Lua_Animator *)_elua_obj_new(L, ed, sizeof(Edje_Lua_Animator), _elua_ecore_animator_meta);
1175 // Stack usage [-5, +6, m]
1176 ela->obj.free_func = _elua_animator_free;
1177 ela->animator = ecore_animator_add(_elua_animator_cb, ela);
1178 lua_pushvalue(L, 1); // Stack usage [-0, +1, -]
1179 ela->fn_ref = luaL_ref(L, LUA_REGISTRYINDEX); // Stack usage [-1, +0, m]
1180 _elua_gc(L); // Stack usage [-0, +0, e]
1185 _elua_timer_cb(void *data) // Stack usage [-2, +2, em]
1187 Edje_Lua_Timer *elt = data;
1189 int ret = 0, err = 0;
1191 if (!elt->obj.ed) return 0;
1194 /* This is not needed, pcalls don't longjmp(), that's why they are protected.
1195 if (setjmp(panic_jmp) == 1)
1197 LE("Timer callback panic");
1198 _edje_lua2_error(L, err); // Stack usage [-0, +0, m]
1199 _elua_obj_free(L, (Edje_Lua_Obj *)elt);
1200 _elua_gc(L); // Stack usage [-0, +0, e]
1204 lua_rawgeti(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +1, -]
1205 if ((err = lua_pcall(L, 0, 1, 0))) // Stack usage [-1, +1, -]
1207 _edje_lua2_error(L, err);
1208 _elua_obj_free(L, (Edje_Lua_Obj *)elt); // Stack usage [-0, +0, m]
1209 _elua_gc(L); // Stack usage [-0, +0, e]
1212 ret = lua_toboolean(L, -1); // Stack usage [-0, +0, -]
1213 lua_pop(L, 1); // Stack usage [-n, +0, -]
1214 if (ret == 0) _elua_obj_free(L, (Edje_Lua_Obj *)elt);
1215 _elua_gc(L); // Stack usage [-0, +0, e]
1220 _elua_timer_free(void *obj) // Stack usage [-0, +0, -]
1222 Edje_Lua_Timer *elt = obj;
1224 if (!elt->obj.ed) return;
1226 luaL_unref(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +0, -]
1228 ecore_timer_del(elt->timer);
1234 @subsubsection edje_timer edje:timer(tick, func)
1236 This function adds a timer and returns its handle on success and NULL on failure.
1237 The function func will be called every tick seconds.
1239 When the timer func is called, it must return a value of either true or false.
1240 If it returns true, it will be called again at the next tick, or if it returns
1241 false it will be deleted automatically making any references/handles for it
1244 Wraps ecore_timer_add().
1246 @param tick How often, in seconds, to call the function.
1247 @param func The function to call when the timer triggers.
1249 @returns A userdata that is an ecore timer.
1252 _elua_timer(lua_State *L) // Stack usage [-8, +9, emv]
1254 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
1255 Edje_Lua_Timer *elt;
1258 val = luaL_checknumber(L, 1); // Stack usage [-0, +0, v]
1259 luaL_checkany(L, 2); // Stack usage [-0, +0, v]
1261 elt = (Edje_Lua_Timer *)_elua_obj_new(L, ed, sizeof(Edje_Lua_Timer), _elua_ecore_timer_meta);
1262 // Stack usage [-5, +6, m]
1263 elt->obj.free_func = _elua_timer_free;
1264 elt->timer = ecore_timer_add(val, _elua_timer_cb, elt);
1265 lua_pushvalue(L, 2); // Stack usage [-0, +1, -]
1266 elt->fn_ref = luaL_ref(L, LUA_REGISTRYINDEX); // Stack usage [-1, +0, m]
1267 _elua_gc(L); // Stack usage [-0, +0, e]
1272 _elua_transition_cb(void *data) // Stack usage [-3, +3, em]
1274 Edje_Lua_Transition *elt = data;
1276 int ret = 0, err = 0;
1279 if (!elt->obj.ed) return 0;
1282 t = (ecore_loop_time_get() - elt->start) / elt->transition;
1283 if (t > 1.0) t = 1.0;
1284 /* This is not needed, pcalls don't longjmp(), that's why they are protected.
1285 if (setjmp(panic_jmp) == 1)
1287 LE("Transition callback panic");
1288 _edje_lua2_error(L, err); // Stack usage [-0, +0, m]
1289 _elua_obj_free(L, (Edje_Lua_Obj *)elt);
1290 _elua_gc(L); // Stack usage [-0, +0, e]
1294 lua_rawgeti(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +1, -]
1295 lua_pushnumber(L, t); // Stack usage [-0, +1, -]
1296 if ((err = lua_pcall(L, 1, 1, 0))) // Stack usage [-2, +1, -]
1298 _edje_lua2_error(L, err);
1299 _elua_obj_free(L, (Edje_Lua_Obj *)elt); // Stack usage [-0, +0, m]
1300 _elua_gc(L); // Stack usage [-0, +0, e]
1303 ret = lua_toboolean(L, -1); // Stack usage [-0, +0, -]
1304 lua_pop(L, 1); // Stack usage [-n, +0, -]
1305 if (t >= 1.0) ret = 0;
1306 if (ret == 0) _elua_obj_free(L, (Edje_Lua_Obj *)elt);
1307 _elua_gc(L); // Stack usage [-0, +0, e]
1312 _elua_transition_free(void *obj) // Stack usage [-0, +0, -]
1314 Edje_Lua_Transition *elt = obj;
1316 if (!elt->obj.ed) return;
1318 luaL_unref(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +0, -]
1320 ecore_animator_del(elt->animator);
1321 elt->animator = NULL;
1326 @subsubsection edje_transition edje:transition(div, func)
1328 Just like edje:animator(), except that the callback function gets called with an
1329 argument. The argument is the amount of time since the transition was created,
1330 divided by the div parameter.
1332 @param div A number to divide the time since creation by.
1333 @param func The function to call when the transition triggers.
1335 @returns A userdata that is a transition (ecore animator, plus other info).
1338 _elua_transition(lua_State *L) // Stack usage [-8, +9, emv]
1340 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
1341 Edje_Lua_Transition *elt;
1344 val = luaL_checknumber(L, 1); // Stack usage [-0, +0, v]
1345 luaL_checkany(L, 2); // Stack usage [-0, +0, v]
1347 elt = (Edje_Lua_Transition *)_elua_obj_new(L, ed, sizeof(Edje_Lua_Transition), _elua_ecore_animator_meta);
1348 // Stack usage [-5, +6, m]
1349 elt->obj.free_func = _elua_transition_free;
1350 elt->animator = ecore_animator_add(_elua_transition_cb, elt);
1351 if (val < 0.0000001) val = 0.0000001;
1352 elt->transition = val;
1353 elt->start = ecore_loop_time_get();
1354 lua_pushvalue(L, 2); // Stack usage [-0, +1, -]
1355 elt->fn_ref = luaL_ref(L, LUA_REGISTRYINDEX); // Stack usage [-1, +0, m]
1356 _elua_gc(L); // Stack usage [-0, +0, e]
1363 @subsubsection edje_colour_class edje:color_class(class, r, g, b, a)
1365 Gets, (and optionally sets) the colours for a color class.
1367 Wraps edje_object_color_class_set().
1369 @param class A color class name.
1370 @param r The new red value.
1371 @param g The new green value.
1372 @param b The new blue value.
1373 @param a The new alpha value.
1375 Note that the r, g, b, and a arguments are optional, without them this function
1376 just queries the current values. The r, g, b, and a arguments can be separate
1377 values, or named fields in a table.
1379 @return A table with these fields:
1380 - integer r: The red value.
1381 - integer g: The green value.
1382 - integer b: The blue value.
1383 - integer a: The alpha value.
1388 _elua_color_class(lua_State *L) // Stack usage [-(10|14), +(11|15), ?]
1390 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
1391 Edje_Color_Class *c_class;
1392 const char *class = luaL_checkstring(L, 1); // Stack usage [-0, +0, v]
1395 if (!class) return 0;
1397 if (_elua_scan_params(L, 2, "%r %g %b %a", &r, &g, &b, &a) > 0)
1398 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
1399 _elua_color_fix(&r, &g, &b, &a);
1400 // This is the way that embryo does it -
1401 //edje_object_color_class_set(ed->obj, class, r, g, b, a, r, g, b, a, r, g, b, a);
1402 // But that deals with object scope, which is currently useless in lua,
1403 // since we have no objects that can use color_class yet.
1404 // So we do it at global scope instead.
1405 // LATER - Should do both?
1406 edje_color_class_set(class, r, g, b, a, r, g, b, a, r, g, b, a);
1409 c_class = _edje_color_class_find(ed, class);
1410 if (!c_class) return 0;
1412 _elua_ret(L, "%r %g %b %a", c_class->r, c_class->g, c_class->b, c_class->a);
1413 // Stack usage [-8, +9, em]
1419 @subsubsection edje_text_class edje:text_class(class, font, size)
1421 Gets, (and optionally sets) the details for a text class.
1423 Wraps edje_object_text_class_set().
1425 @param class A text class name.
1426 @param font The new font name.
1427 @param size The new font size.
1429 Note that the font and size arguments are optional, without them this function
1430 just queries the current values. The font and size arguments can be separate
1431 values, or named fields in a table. The font name can refer to a font in the
1432 edje file, or an external font.
1434 @return A table with these fields:
1435 - string font: The font name.
1436 - integer size: The font size.
1441 _elua_text_class(lua_State *L) // Stack usage [-(6|8), +(7|9), emv]
1443 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
1444 Edje_Text_Class *t_class;
1445 const char *class = luaL_checkstring(L, 1); // Stack usage [-0, +0, v]
1447 Evas_Font_Size size = 0;
1449 if (!class) return 0;
1451 // Just like color_class above, this does things differently from embryo,
1452 // for the same reason.
1453 if (_elua_scan_params(L, 2, "$font %size", &font, &size) > 0)
1454 // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
1455 edje_text_class_set(class, font, size);
1457 t_class = _edje_text_class_find(ed, class);
1458 if (!t_class) return 0;
1460 _elua_ret(L, "$font %size", t_class->font, t_class->size);
1461 // Stack usage [-4, +5, em]
1467 _elua_evas_obj_free(void *obj)
1469 Edje_Lua_Evas_Object *elo = obj;
1471 if (!elo->obj.ed) return;
1472 evas_object_del(elo->evas_obj);
1473 elo->evas_obj = NULL;
1476 // Stack usage [-7, +8, em]
1477 #define _ELUA_PLANT_EVAS_OBJECT(type, meta, free) \
1478 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); \
1480 elo = (type *)_elua_obj_new(L, ed, sizeof(type), meta); \
1481 elo->obj.free_func = free;
1482 // Stack usage [-2, +2, e]
1483 // Stack usage [-5, +6, m]
1486 _elua_polish_evas_object(Edje *ed, Edje_Lua_Evas_Object *elo)
1488 evas_object_smart_member_add(elo->evas_obj, ed->obj);
1489 evas_object_clip_set(elo->evas_obj, ed->base.clipper);
1490 evas_object_move(elo->evas_obj, ed->x, ed->y);
1491 evas_object_resize(elo->evas_obj, 0, 0);
1492 evas_object_data_set(elo->evas_obj, ELO, elo);
1497 @subsubsection edje_edje edje:edje()
1499 Create an edje object, and add it to the edje.
1501 Wraps edje_object_add().
1503 @returns A userdata that is an edje object.
1508 _elua_edje(lua_State *L) // Stack usage [-7, +8, em]
1510 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_edje_meta, _elua_evas_obj_free)
1511 // Stack usage [-7, +8, em]
1512 elo->evas_obj = edje_object_add(evas_object_evas_get(ed->obj));
1513 _edje_subobj_register(ed, elo->evas_obj);
1514 _elua_polish_evas_object(ed, elo);
1520 @subsubsection edje_image edje:image()
1522 Create an evas image, and add it to the edje.
1524 Wraps evas_object_image_add().
1526 @returns A userdata that is an evas image.
1531 _elua_image(lua_State *L) // Stack usage [-7, +8, em]
1533 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_image_meta, _elua_evas_obj_free)
1534 // Stack usage [-7, +8, em]
1535 elo->evas_obj = evas_object_image_filled_add(evas_object_evas_get(ed->obj));
1536 _elua_polish_evas_object(ed, elo);
1542 @subsubsection edje_line edje:line()
1544 Create an evas line, and add it to the edje.
1546 Wraps evas_object_line_add().
1548 @returns A userdata that is an evas line.
1553 _elua_line(lua_State *L) // Stack usage [-7, +8, em]
1555 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_line_meta, _elua_evas_obj_free)
1556 // Stack usage [-7, +8, em]
1557 elo->evas_obj = evas_object_line_add(evas_object_evas_get(ed->obj));
1558 _elua_polish_evas_object(ed, elo);
1563 _elua_map_free(void *obj)
1565 Edje_Lua_Map *elm = obj;
1566 if (!elm->obj.ed) return;
1567 evas_map_free(elm->map);
1573 @subsubsection edje_map edje:map()
1577 Wraps evas_map_new().
1579 @returns A userdata that is an evas map.
1584 _elua_map(lua_State *L) // Stack usage [-7, +8, emv]
1586 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Map, _elua_evas_map_meta, _elua_map_free)
1587 // Stack usage [-7, +8, em]
1588 elo->map = evas_map_new(luaL_checkinteger(L, 1)); // Stack usage [-0, +0, v]
1594 @subsubsection edje_polygon edje:polygon()
1596 Create an evas polygon, and add it to the edje.
1598 Wraps evas_object_polygon_add().
1600 @returns A userdata that is an evas polygon.
1605 _elua_polygon(lua_State *L) // Stack usage [-7, +8, em]
1607 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_polygon_meta, _elua_evas_obj_free)
1608 // Stack usage [-7, +8, em]
1609 elo->evas_obj = evas_object_polygon_add(evas_object_evas_get(ed->obj));
1610 _elua_polish_evas_object(ed, elo);
1616 @subsubsection edje_rect edje:rect()
1618 Create an evas rectangle, and add it to the edje.
1620 Wraps evas_object_rectangle_add().
1622 @returns A userdata that is an evas rectangle.
1625 _elua_rect(lua_State *L) // Stack usage [-7, +8, em]
1627 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_meta, _elua_evas_obj_free)
1628 // Stack usage [-7, +8, em]
1629 elo->evas_obj = evas_object_rectangle_add(evas_object_evas_get(ed->obj));
1630 _elua_polish_evas_object(ed, elo);
1636 @subsubsection edje_text edje:text()
1638 Create an evas text object, and add it to the edje.
1640 Wraps evas_object_text_add().
1642 @returns A userdata that is an evas text object.
1647 _elua_text(lua_State *L) // Stack usage [-7, +8, em]
1649 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_text_meta, _elua_evas_obj_free)
1650 // Stack usage [-7, +8, em]
1651 elo->evas_obj = evas_object_text_add(evas_object_evas_get(ed->obj));
1652 _elua_polish_evas_object(ed, elo);
1656 /* XXX: disabled until there are enough textblock functions implemented to make it actually useful
1657 _elua_textblock(lua_State *L) // Stack usage [-7, +8, em]
1659 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_textblock_meta, _elua_evas_obj_free)
1660 // Stack usage [-7, +8, em]
1661 elo->evas_obj = evas_object_textblock_add(evas_object_evas_get(ed->obj));
1662 _elua_polish_evas_object(ed, elo);
1672 @subsection evas Evas class.
1674 The lua evas class includes functions for dealing with evas objects. The evas
1675 objects must have been previously created by lua using one of the lua ezas
1676 object creation functions from the lua edje class.
1678 In the following, "evas_object" is a place holder for any lua variable that
1679 holds a reference to an evas object.
1682 static int _elua_obj_del(lua_State *L);
1684 static int _elua_hide(lua_State *L);
1685 static int _elua_show(lua_State *L);
1686 static int _elua_visible(lua_State *L);
1688 static int _elua_above(lua_State *L);
1689 static int _elua_below(lua_State *L);
1690 static int _elua_bottom(lua_State *L);
1691 static int _elua_lower(lua_State *L);
1692 static int _elua_raise(lua_State *L);
1693 static int _elua_top(lua_State *L);
1695 static int _elua_geom(lua_State *L);
1696 static int _elua_move(lua_State *L);
1697 static int _elua_pos(lua_State *L);
1698 static int _elua_resize(lua_State *L);
1699 static int _elua_size(lua_State *L);
1701 static int _elua_clip(lua_State *L);
1702 static int _elua_clipees(lua_State *L);
1703 static int _elua_unclip(lua_State *L);
1705 static int _elua_type(lua_State *L);
1707 static int _elua_pass(lua_State *L);
1708 static int _elua_precise(lua_State *L);
1709 static int _elua_repeat(lua_State *L);
1711 static int _elua_color(lua_State *L);
1713 static int _elua_obj_map(lua_State *L);
1714 static int _elua_obj_map_enable(lua_State *L);
1716 static const char *_elua_evas_api = "evas";
1717 static const struct luaL_Reg _elua_evas_funcs [] =
1719 {"del", _elua_obj_del}, // generic del any object created for edje (evas objects, timers, animators, transitions... everything)
1721 {"hide", _elua_hide}, // hide, return current visibility
1722 {"show", _elua_show}, // show, return current visibility
1723 {"visible", _elua_visible}, // get object visibility
1725 {"above", _elua_above}, // get object above or stack obj above given obj
1726 {"below", _elua_below}, // get object below or stack obj below given obj
1727 {"bottom", _elua_bottom}, // get bottom
1728 {"lower", _elua_lower}, // lower to bottom
1729 {"raise", _elua_raise}, // raise to top
1730 {"top", _elua_top}, // get top
1732 {"geom", _elua_geom}, // move and resize and return current geometry
1733 {"move", _elua_move}, // move, return current position
1734 {"pos", _elua_pos}, // move, return current position
1735 {"resize", _elua_resize}, // resize, return current size
1736 {"size", _elua_size}, // resize, return current size
1738 {"clip", _elua_clip}, // set clip obj, return clip object
1739 {"clipees", _elua_clipees}, // get clip children
1740 {"unclip", _elua_unclip}, // clear clip obj
1742 {"type", _elua_type}, // get object type
1744 {"pass", _elua_pass}, // set pass events, get pass events
1745 {"precise", _elua_precise}, // set precise inside flag, get precise
1746 {"repeat", _elua_repeat}, // set repeat events, get repeat events
1748 {"color", _elua_color}, // set color, return color
1749 // {"color_class", _elua_object_color_class}, // get or set object color class
1751 // FIXME: set callbacks (mouse down, up, blah blah blah)
1753 // FIXME: set scale (explicit value)
1754 // FIXME: need to set auto-scale (same as scale: 1)
1756 // FIXME: later - set render op, anti-alias, pointer mode (autograb, nograb)
1759 {"map", _elua_obj_map},
1760 {"map_enable", _elua_obj_map_enable},
1768 @subsubsection evas_hide evas_object:hide()
1772 Wraps evas_object_hide().
1774 @returns A boolean representing the current visibility.
1777 _elua_hide(lua_State *L) // Stack usage [-0, +1, -]
1779 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1780 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1781 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1782 evas_object_hide(elo->evas_obj);
1783 lua_pushboolean(L, evas_object_visible_get(elo->evas_obj)); // Stack usage [-0, +1, -]
1789 @subsubsection evas_show evas_object:show()
1793 Wraps evas_object_show().
1795 @returns A boolean representing the current visibility.
1798 _elua_show(lua_State *L) // Stack usage [-0, +1, -]
1800 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1801 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1802 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1803 evas_object_show(elo->evas_obj);
1804 lua_pushboolean(L, evas_object_visible_get(elo->evas_obj)); // Stack usage [-0, +1, -]
1810 @subsubsection evas_visible evas_object:visible(visibility)
1812 Gets (and optionally sets) this objects visibility.
1814 Wraps evas_object_hide() or evas_object_show().
1816 @param visibility The new visibility you want to change it to.
1818 Note that the argument is optional, without it this function just queries the
1821 @returns A boolean representing the current visibility.
1824 _elua_visible(lua_State *L) // Stack usage [-0, +1, -]
1826 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1827 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1829 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1830 n = lua_gettop(L); // Stack usage [-0, +0, -]
1833 if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -]
1835 if (lua_toboolean(L, 2)) evas_object_show(elo->evas_obj);
1836 // Stack usage [-0, +0, -]
1837 else evas_object_hide(elo->evas_obj);
1840 lua_pushboolean(L, evas_object_visible_get(elo->evas_obj)); // Stack usage [-0, +1, -]
1847 @subsubsection evas_above evas_object:above()
1849 Figure out what, if anything, is above us.
1851 Wraps evas_object_above_get().
1853 Note that it may not return any value.
1855 @returns A reference to the object above this one.
1858 _elua_above(lua_State *L) // Stack usage [-3, +4, -]
1860 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1861 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1862 Edje_Lua_Evas_Object *elo2;
1864 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1865 if (!(o = evas_object_above_get(elo->evas_obj))) return 0;
1866 if (!(elo2 = evas_object_data_get(o, ELO))) return 0;
1867 _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
1873 @subsubsection evas_below evas_object:below()
1875 Figure out what, if anything, is below us.
1877 Wraps evas_object_below_get().
1879 Note that it may not return any value.
1881 @returns A reference to the object below this one.
1884 _elua_below(lua_State *L) // Stack usage [-3, +4, -]
1886 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1887 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1888 Edje_Lua_Evas_Object *elo2;
1890 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1891 if (!(o = evas_object_below_get(elo->evas_obj))) return 0;
1892 if (!(elo2 = evas_object_data_get(o, ELO))) return 0;
1893 _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
1899 @subsubsection evas_bottom evas_object:bottom()
1901 Figure out what, if anything, is waaaay below us.
1903 Note that it may not return any value.
1905 @returns A reference to the object at the bottom.
1908 _elua_bottom(lua_State *L) // Stack usage [-(0|3), +(0|4), -]
1910 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1911 Edje_Lua_Evas_Object *elo2;
1913 Eina_List *list, *l;
1914 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1915 if (!(list = (Eina_List *)evas_object_smart_members_get(obj->ed->obj))) return 0;
1916 for (l = list; l; l = l->next)
1919 if ((elo2 = evas_object_data_get(o, ELO)))
1921 _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
1930 @subsubsection evas_lower evas_object:lower()
1932 Lower this object to the bottom.
1934 Wraps evas_object_lower().
1937 _elua_lower(lua_State *L) // Stack usage [-0, +0, -]
1939 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1940 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1941 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1942 evas_object_lower(elo->evas_obj);
1948 @subsubsection evas_raise evas_object:raise()
1950 Raise this object to the top.
1952 Wraps evas_object_raise().
1955 _elua_raise(lua_State *L) // Stack usage [-0, +0, -]
1957 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1958 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1959 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1960 evas_object_raise(elo->evas_obj);
1966 @subsubsection evas_top evas_object:top()
1968 Figure out what, if anything, is waaaay above us.
1970 Note that it may not return any value.
1972 @returns A reference to the object at the top.
1975 _elua_top(lua_State *L) // Stack usage [-(0|3), +(0|4), -]
1977 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-(0, +0, -]
1978 Edje_Lua_Evas_Object *elo2;
1980 Eina_List *list, *l;
1981 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1982 if (!(list = (Eina_List *)evas_object_smart_members_get(obj->ed->obj))) return 0;
1983 if (!list) return 0;
1984 for (l = eina_list_last(list); l; l = l->prev)
1987 if ((elo2 = evas_object_data_get(o, ELO)))
1989 _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
1999 @subsubsection evas_geom evas_object:geom(x, y, w, h)
2001 Gets (and optionally sets) this objects geometry.
2003 Wraps evas_object_move() and evas_object_resize.
2005 @param x The new X coordinate.
2006 @param y The new Y coordinate.
2007 @param w The new width.
2008 @param h The new height.
2010 Note that the arguments are optional, without them this function just queries
2011 the current values. The arguments can be separate values, or named fields in a
2014 @return A table with these fields:
2015 - integer x: X coordinate.
2016 - integer x: Y coordinate.
2018 - integer w: Height.
2021 _elua_geom(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
2023 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2024 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2025 Evas_Coord ox, oy, ow, oh;
2028 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2029 evas_object_geometry_get(elo->evas_obj, &ox, &oy, &ow, &oh);
2030 if (_elua_scan_params(L, 2, "%x %y %w %h", &x, &y, &w, &h) > 0)
2031 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
2032 if ((x != (ox - obj->ed->x)) || (y != (oy - obj->ed->y)))
2034 evas_object_move(elo->evas_obj,
2038 if ((w != ow) || (h != oh))
2040 evas_object_resize(elo->evas_obj, w, h);
2042 evas_object_geometry_get(elo->evas_obj, &ox, &oy, &ow, &oh);
2043 elo->x = ox - obj->ed->x;
2044 elo->y = oy - obj->ed->y;
2046 _elua_ret(L, "%x %y %w %h", elo->x, elo->y, ow, oh);
2047 // Stack usage [-8, +9, em]
2053 @subsubsection evas_move evas_object:move(x, y)
2055 Gets (and optionally sets) this objects position.
2057 Wraps evas_object_move().
2059 @param x The new X coordinate.
2060 @param y The new Y coordinate.
2062 Note that the arguments are optional, without them this function just queries
2063 the current values. The arguments can be separate values, or named fields in a
2066 @return A table with these fields:
2067 - integer x: X coordinate.
2068 - integer x: Y coordinate.
2071 _elua_move(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2073 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2074 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2078 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2079 evas_object_geometry_get(elo->evas_obj, &ox, &oy, NULL, NULL);
2080 if (_elua_scan_params(L, 2, "%x %y", &x, &y) > 0)
2081 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
2082 if ((x != (ox - obj->ed->x)) || (y != (oy - obj->ed->y)))
2084 evas_object_move(elo->evas_obj,
2087 evas_object_geometry_get(elo->evas_obj, &ox, &oy, NULL, NULL);
2089 elo->x = ox - obj->ed->x;
2090 elo->y = oy - obj->ed->y;
2092 _elua_ret(L, "%x %y", elo->x, elo->y);
2093 // Stack usage [-4, +5, em]
2099 @subsubsection evas_pos evas_object:pos(x, y)
2101 An alias for evas_object:move().
2104 _elua_pos(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2106 return _elua_move(L);
2111 @subsubsection evas_resize evas_object:resize(w, h)
2113 Gets (and optionally sets) this objects size.
2115 Wraps evas_object_resize().
2117 @param w The new width.
2118 @param h The new height.
2120 Note that the arguments are optional, without them this function just queries
2121 the current values. The arguments can be separate values, or named fields in a
2124 @return A table with these fields:
2126 - integer w: Height.
2129 _elua_resize(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2131 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2132 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2136 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2137 evas_object_geometry_get(elo->evas_obj, NULL, NULL, &ow, &oh);
2138 if (_elua_scan_params(L, 2, "%w %h", &w, &h) > 0)
2139 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
2140 if ((w != ow) || (h != oh))
2142 evas_object_resize(elo->evas_obj, w, h);
2143 evas_object_geometry_get(elo->evas_obj, NULL, NULL, &ow, &oh);
2146 _elua_ret(L, "%w %h", ow, oh);
2147 // Stack usage [-4, +5, em]
2153 @subsubsection evas_size evas_object:size()
2155 An alias for evas_object:resize().
2158 _elua_size(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2160 return _elua_resize(L);
2166 @subsubsection evas_clip evas_object:clip(evas_object2)
2168 Get (and optionally set) the object that clips this object.
2170 Note that the argument is optional, without it this function just queries the
2173 Wraps evas_object_clip_set().
2175 @param evas_object2 A reference to the object to clip this object with.
2177 @returns A reference to the object clipping this object, if any.
2180 _elua_clip(lua_State *L) // Stack usage [-3, +4, -]
2182 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2183 Edje_Lua_Evas_Object *elo2, *elo = (Edje_Lua_Evas_Object *)obj;
2186 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2187 n = lua_gettop(L); // Stack usage [-0, +0, -]
2190 Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); // Stack usage [-0, +0, -]
2191 elo2 = (Edje_Lua_Evas_Object *)obj2;
2192 if (!_elua_isa(obj2, _elua_evas_meta)) return 0;
2193 evas_object_clip_set(elo->evas_obj, elo2->evas_obj);
2195 o = evas_object_clip_get(elo->evas_obj);
2197 if (!(elo2 = evas_object_data_get(o, ELO))) return 0;
2198 _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
2204 @subsubsection evas_clipees evas_object:clipees()
2206 Gets the list of objects this objects clips.
2208 Wraps evas_object_clipees_get().
2210 @return A table, that holds all the objects this clips, if any,
2211 otherwise an empty table.
2214 _elua_clipees(lua_State *L) // Stack usage [-0, +1, me] plus [-5, +5] for each clipee.
2216 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2217 Edje_Lua_Evas_Object *elo2, *elo = (Edje_Lua_Evas_Object *)obj;
2218 Eina_List *list, *l;
2221 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2222 list = (Eina_List *)evas_object_clipees_get(elo->evas_obj);
2223 lua_newtable(L); // Stack usage [-0, +1, m]
2224 EINA_LIST_FOREACH(list, l, o)
2226 if (!(elo2 = evas_object_data_get(o, ELO))) continue;
2227 lua_pushinteger(L, n + 1); // Stack usage [-0, +1, -]
2228 _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
2229 lua_settable(L, -3); // Stack usage [-2, +0, e]
2237 @subsubsection evas_unclip evas_object:unclip()
2239 Remove any clipping on this object.
2241 Wraps evas_object_clip_unset().
2244 _elua_unclip(lua_State *L) // Stack usage [-0, +0, -]
2246 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2247 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2248 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2249 evas_object_clip_unset(elo->evas_obj);
2256 @subsubsection evas_type evas_object:type()
2258 Get the type of this object. See the documentation of the evas_object_type_get()
2259 C function for details.
2261 Wraps evas_object_type_get().
2263 @return A string with this objects type in it.
2266 _elua_type(lua_State *L) // Stack usage [-0, +1, m]
2268 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2269 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2271 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2272 t = evas_object_type_get(elo->evas_obj);
2274 lua_pushstring(L, t); // Stack usage [-0, +1, m]
2281 @subsubsection evas_pass evas_object:pass(pass)
2283 Get (and optionally set) whether this object ignores events, passing them to the
2284 next object underneath it.
2286 Wraps evas_object_pass_events_set().
2288 @param pass A boolean saying if this object passes events.
2290 Note that the argument is optional, without it this function just queries the
2293 @return A boolean saying if this object passes events.
2296 _elua_pass(lua_State *L) // Stack usage [-0, +1, -]
2298 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2299 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2301 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2302 n = lua_gettop(L); // Stack usage [-0, +0, -]
2305 if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -]
2307 evas_object_pass_events_set(elo->evas_obj, lua_toboolean(L, 2));
2308 // Stack usage [-0, +0, -]
2311 lua_pushboolean(L, evas_object_pass_events_get(elo->evas_obj));
2312 // Stack usage [-0, +1, -]
2318 @subsubsection evas_precise evas_object:precise(precise)
2320 Get (and optionally set) whether to use precise (usually expensive) point
2321 collision detection for this object.
2323 Wraps evas_object_precise_is_inside_set().
2325 @param precise A boolean saying if this object is precisely detected.
2327 Note that the argument is optional, without it this function just queries the
2330 @return A boolean saying if this object is precisely detected.
2333 _elua_precise(lua_State *L) // Stack usage [-0, +1, -]
2335 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2336 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2338 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2339 n = lua_gettop(L); // Stack usage [-0, +0, -]
2342 if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -]
2344 evas_object_precise_is_inside_set(elo->evas_obj, lua_toboolean(L, 2));
2345 // Stack usage [-0, +0, -]
2348 lua_pushboolean(L, evas_object_precise_is_inside_get(elo->evas_obj));
2349 // Stack usage [-0, +1, -]
2355 @subsubsection evas_repeat evas_object:repeat(repeat)
2357 Get (and optionally set) whether this object repeats events.
2359 Wraps evas_object_repeat_events_set().
2361 @param repeat A boolean saying if this object repeats events to lower objects.
2363 Note that the argument is optional, without it this function just queries the
2366 @return A boolean saying if this object repeats events.
2369 _elua_repeat(lua_State *L) // Stack usage [-0, +1, -]
2371 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2372 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2374 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2375 n = lua_gettop(L); // Stack usage [-0, +0, -]
2378 if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -]
2380 evas_object_repeat_events_set(elo->evas_obj, lua_toboolean(L, 2));
2381 // Stack usage [-0, +0, -]
2384 lua_pushboolean(L, evas_object_repeat_events_get(elo->evas_obj));
2385 // Stack usage [-0, +1, -]
2392 @subsubsection evas_colour evas_object:color(r, g, b, a)
2394 Gets (and optionally sets) this objects colour.
2396 Wraps evas_object_color_set().
2398 @param r The new red value.
2399 @param g The new green value.
2400 @param b The new blue value.
2401 @param a The new alpha value.
2403 Note that the arguments are optional, without them this function just queries
2404 the current values. The arguments can be separate values, or named fields in a
2407 @return A table with these fields:
2408 - integer r: The red value.
2409 - integer g: The green value.
2410 - integer b: The blue value.
2411 - integer a: The alpha value.
2414 _elua_color(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
2416 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2417 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2420 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2421 if (_elua_scan_params(L, 2, "%r %g %b %a", &r, &g, &b, &a) > 0)
2422 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
2423 _elua_color_fix(&r, &g, &b, &a);
2424 evas_object_color_set(elo->evas_obj, r, g, b, a);
2426 evas_object_color_get(elo->evas_obj, &r, &g, &b, &a);
2427 _elua_ret(L, "%r %g %b %a", r, g, b, a);
2428 // Stack usage [-8, +9, em]
2435 @subsubsection evas_map evas_object:map(map)
2437 Attach a map to this object.
2439 Wraps evas_object_map_set().
2441 @param map The map to attach.
2446 _elua_obj_map(lua_State *L) // Stack usage [-0, +0, -]
2448 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2449 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2450 Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); // Stack usage [-0, +0, -]
2451 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj2;
2452 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2453 if (!_elua_isa(obj2, _elua_evas_map_meta)) return 0;
2455 evas_object_map_set(elo->evas_obj, elm->map);
2462 @subsubsection evas_map_enable evas_object:map_enable(enable)
2464 Enable or disable the map attached to this object.
2466 Wraps evas_object_map_enable_set().
2468 @param enable A booleon that controls if the attached map is enabled or not.
2470 @return A boolean reflecting the map enabled status of this object.
2475 _elua_obj_map_enable(lua_State *L) // Stack usage [-0, +1, -]
2477 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2478 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2480 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2482 n = lua_gettop(L); // Stack usage [-0, +0, -]
2485 evas_object_map_enable_set(elo->evas_obj, lua_toboolean(L, 2));
2486 // Stack usage [-0, +0, -]
2488 lua_pushboolean(L, evas_object_map_enable_get(elo->evas_obj));
2489 // Stack usage [-0, +1, -]
2497 @subsection ecore_animator Ecore animator class.
2499 The lua ecore animator class includes functions for dealing with ecore animator objects.
2500 The ecore animator objects must have been previously created by lua using the lua
2501 edje object creation function edje:animator() or edje:transition().
2503 In the following, "animator_object" is a place holder for any lua variable that
2504 holds a reference to an ecore animator object.
2506 static const char *_elua_ecore_animator_api = "ecore_animator";
2507 static const struct luaL_Reg _elua_ecore_animator_funcs [] =
2516 @subsection ecore_timer Ecore timer class.
2518 The lua ecore timer class includes functions for dealing with ecore timer objects.
2519 The ecore timer objects must have been previously created by lua using the lua
2520 edje object creation function edje:timer().
2522 In the following, "timer_object" is a place holder for any lua variable that
2523 holds a reference to an ecore timer object.
2526 static const char *_elua_ecore_timer_api = "ecore_timer";
2527 static const struct luaL_Reg _elua_ecore_timer_funcs [] =
2536 @subsection evas_edje Evas edje class.
2538 The lua evas edje class includes functions for dealing with evas edje objects.
2539 The evas edje objects must have been previously created by lua using the lua
2540 edje object creation function edje:edje().
2542 In the following, "edje_object" is a place holder for any lua variable that
2543 holds a reference to an evas edje object. NOT the edje class specified earlier
2549 static int _elua_edje_file(lua_State *L);
2551 static const char *_elua_evas_edje_api = "evas_edje";
2552 static const char *_elua_evas_edje_parent = "evas_edje_parent";
2553 static const struct luaL_Reg _elua_evas_edje_funcs [] =
2555 {"file", _elua_edje_file}, // get or set edje file and group
2562 @subsubsection edje_file edje_object:file(file, group)
2564 Load an edje group into this edje object.
2566 Wraps edje_object_file_set().
2568 @param file An edje file name (ignored, sandboxed to the file this lua script is in).
2569 @param group The group within the edje file to be loaded.
2571 Note that the arguments are optional, without them this function just queries
2572 the current values. The arguments can be separate values, or named fields in a
2573 table. The file argument is optional, and ignored anyway.
2575 @return A table with these fields:
2576 - string file: The name of the edje file this edje's group is loaded from.
2577 - string group: The name of the group this edje is loaded from.
2582 _elua_edje_file(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2584 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2585 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2586 const char *file = NULL, *group = NULL;
2587 int n = lua_gettop(L); // Stack usage [-0, +0, -]
2589 if (!_elua_isa(obj, _elua_evas_edje_meta)) return 0;
2591 n = _elua_scan_params(L, 2, "$file $group", &file, &group);
2592 // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
2595 file = (char *) obj->ed->file->path;
2596 group = (char *) lua_tostring(L, 2); // Stack usage [-0, +0, m]
2602 // Sandbox lua - Only allow access to groups within the same file.
2603 // By the simple expedient of completely ignoring what file was requested.
2604 file = (char *) obj->ed->file->path;
2605 if (!edje_object_file_set(elo->evas_obj, file, group))
2607 Edje_Load_Error err = edje_object_load_error_get(elo->evas_obj);
2611 case EDJE_LOAD_ERROR_NONE : LE("Edje file loading errer %s %s - no error happened, but you should not see this.", obj->ed->file->path, group); break;
2612 case EDJE_LOAD_ERROR_GENERIC : LE("Edje file loading errer %s %s - generic error.", obj->ed->file->path, group); break;
2613 case EDJE_LOAD_ERROR_DOES_NOT_EXIST : LE("Edje file loading errer %s %s - file does not exist.", obj->ed->file->path, group); break;
2614 case EDJE_LOAD_ERROR_PERMISSION_DENIED : LE("Edje file loading errer %s %s - permission denied reading the file.", obj->ed->file->path, group); break;
2615 case EDJE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED : LE("Edje file loading errer %s %s - resource allocation failed.", obj->ed->file->path, group); break;
2616 case EDJE_LOAD_ERROR_CORRUPT_FILE : LE("Edje file loading errer %s %s - corrupt file.", obj->ed->file->path, group); break;
2617 case EDJE_LOAD_ERROR_UNKNOWN_FORMAT : LE("Edje file loading errer %s %s - unknown file format.", obj->ed->file->path, group); break;
2618 case EDJE_LOAD_ERROR_INCOMPATIBLE_FILE : LE("Edje file loading errer %s %s - incompatible file.", obj->ed->file->path, group); break;
2619 case EDJE_LOAD_ERROR_UNKNOWN_COLLECTION : LE("Edje file loading errer %s %s - unknown group.", obj->ed->file->path, group); break;
2620 case EDJE_LOAD_ERROR_RECURSIVE_REFERENCE : LE("Edje file loading errer %s %s - recursive reference in group.", obj->ed->file->path, group); break;
2624 edje_object_file_get(elo->evas_obj, &file, &group);
2625 _elua_ret(L, "$file $group", file, group);
2626 // Stack usage [-4, +5, em]
2634 @subsection evas_image Evas image class.
2636 The lua evas image class includes functions for dealing with evas image objects.
2637 The evas image objects must have been previously created by lua using the lua
2638 image object creation function edje:image().
2640 In the following, "image_object" is a place holder for any lua variable that
2641 holds a reference to an evas image object.
2646 static int _elua_image_fill(lua_State *L);
2647 static int _elua_image_filled(lua_State *L);
2648 static int _elua_image_image(lua_State *L);
2650 static const char *_elua_evas_image_api = "evas_image";
2651 static const char *_elua_evas_image_parent = "evas_image_parent";
2652 static const struct luaL_Reg _elua_evas_image_funcs [] =
2654 {"fill", _elua_image_fill}, // get or set the fill parameters
2655 {"filled", _elua_image_filled}, // get or set the filled state (overrides fill())
2656 {"image", _elua_image_image}, // get or set image
2663 @subsubsection image_fill image_object:fill(x, y, w, h)
2665 Gets (and optionally sets) how to fill this image's drawing rectangle given the
2666 (real) image bound to it.
2668 Wraps evas_object_image_fill_set().
2670 @param x The x coordinate (from the top left corner of the bound image) to start drawing from.
2671 @param y The y coordinate (from the top left corner of the bound image) to start drawing from.
2672 @param w The width the bound image will be displayed at.
2673 @param h The height the bound image will be displayed at.
2675 Note that the arguments are optional, without them this function just queries
2676 the current values. The arguments can be separate values, or named fields in a
2679 @return A table with these fields:
2680 - integer x: The x coordinate (from the top left corner of the bound image) to start drawing from.
2681 - integer y: The y coordinate (from the top left corner of the bound image) to start drawing from.
2682 - integer w: The width the bound image will be displayed at.
2683 - integer h: The height the bound image will be displayed at.
2688 _elua_image_fill(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
2690 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2691 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2692 Evas_Coord x, y, w, h;
2694 if (!_elua_isa(obj, _elua_evas_image_meta)) return 0;
2696 if (_elua_scan_params(L, 2, "%x %y %w %h", &x, &y, &w, &h) > 0)
2697 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
2698 evas_object_image_fill_set(elo->evas_obj, x, y, w, h);
2700 evas_object_image_fill_get(elo->evas_obj, &x, &y, &w, &h);
2701 _elua_ret(L, "%x %y %w %h", x, y, w, h);
2702 // Stack usage [-8, +9, em]
2708 @subsubsection image_filled image_object:filled(filled)
2710 Get (and optionally set) whether this image fills the object.
2712 Wraps evas_object_image_filled_set().
2714 @param filled A boolean saying if this image fills the object.
2716 Note that the argument is optional, without it this function just queries the
2719 @return A boolean saying if this image fills the object.
2724 _elua_image_filled(lua_State *L) // Stack usage [-0, +0, -]
2726 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2727 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2730 if (!_elua_isa(obj, _elua_evas_image_meta)) return 0;
2732 n = lua_gettop(L); // Stack usage [-0, +0, -]
2735 evas_object_image_filled_set(elo->evas_obj, lua_toboolean(L, 2));
2736 // Stack usage [-0, +0, -]
2738 lua_pushboolean(L, evas_object_image_filled_get(elo->evas_obj));
2739 // Stack usage [-0, +0, -]
2745 @subsubsection image_image image_object:image(file, key)
2747 Load an image into this edje object.
2749 Wraps evas_object_image_file_set().
2751 @param file An edje file name (ignored, sandboxed to the file this lua script is in).
2752 @param group The name of an image.
2754 Note that the arguments are optional, without them this function just queries
2755 the current values. The arguments can be separate values, or named fields in a
2756 table. The file argument is optional, and ignored anyway.
2758 @return A table with these fields:
2759 - string file: The name of the edje file the image is loaded from.
2760 - string key: The name of the image within the edje file.
2765 _elua_image_image(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2767 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2768 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2769 const char *file = NULL, *key = NULL;
2772 if (!_elua_isa(obj, _elua_evas_image_meta)) return 0;
2774 n = _elua_scan_params(L, 2, "$file $key", &file, &key);
2775 // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
2778 file = (char *) obj->ed->file->path;
2779 key = (char *) lua_tostring(L, 2); // Stack usage [-0, +0, m]
2785 if (obj->ed->file->image_dir)
2787 Edje_Image_Directory_Entry *de;
2792 if ((name = strrchr(key, '/'))) name++;
2793 else name = (char *)key;
2795 /* Loop through image directory to find if image exists */
2796 for (i = 0; i < obj->ed->file->image_dir->entries_count; ++i)
2798 de = obj->ed->file->image_dir->entries + i;
2802 if (strcmp(name, de->entry) == 0)
2807 // This is copied from _edje_image_recalc_apply()), dunno if it provides any benefit over sprintf().
2808 /* Replace snprint("edje/images/%i") == memcpy + itoa */
2809 #define IMAGES "edje/images/"
2810 memcpy(buf, IMAGES, strlen(IMAGES));
2811 eina_convert_itoa(id, buf + strlen(IMAGES)); /* No need to check length as 2³² need only 10 characters. */
2812 evas_object_image_file_set(elo->evas_obj, obj->ed->file->path, buf);
2821 LE("Image %s not found in our edje file.", key);
2822 /* Sandbox lua - Only allow access to images within the same edje file. I'm not so sure we need this level of sandboxing though. So leaving it here, just in case.
2823 LI("Image %s not found in our edje file, trying external image file %s.", key, file);
2824 evas_object_image_file_set(elo->evas_obj, file, key);
2828 evas_object_image_file_get(elo->evas_obj, &file, &key);
2829 _elua_ret(L, "$file $key", file, key);
2830 // Stack usage [-4, +5, em]
2838 @subsection evas_line Evas line class.
2840 The lua evas line class includes functions for dealing with evas line objects.
2841 The evas line objects must have been previously created by lua using the lua
2842 line object creation function edje:line().
2844 In the following, "line_object" is a place holder for any lua variable that
2845 holds a reference to an evas line object.
2850 static int _elua_line_xy(lua_State *L);
2852 static const char *_elua_evas_line_api = "evas_line";
2853 static const char *_elua_evas_line_parent = "evas_line_parent";
2854 static const struct luaL_Reg _elua_evas_line_funcs [] =
2856 {"xy", _elua_line_xy}, // get or set line coords
2863 @subsubsection line_xy line_object:xy(x1, y1, x2, y2)
2865 Sets the end points of this line.
2867 Wraps evas_object_line_xy_set().
2869 @param x1 The X coordinate of the first line end.
2870 @param y1 The Y coordinate of the first line end.
2871 @param x2 The X coordinate of the other line end.
2872 @param y2 The Y coordinate of the other line end.
2874 Note that the arguments are optional, without them this function just queries
2875 the current values. The arguments can be separate values, or named fields in a
2878 @return A table with these fields:
2879 - integer x1: The X coordinate of the first line end.
2880 - integer y1: The Y coordinate of the first line end.
2881 - integer x2: The X coordinate of the other line end.
2882 - integer y2: The Y coordinate of the other line end.
2886 static int _elua_line_xy(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
2888 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2889 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2890 Evas_Coord x1, y1, x2, y2;
2892 if (!_elua_isa(obj, _elua_evas_line_meta)) return 0;
2894 if (_elua_scan_params(L, 2, "%x1 %y1 %x2 %y2", &x1, &y1, &x2, &y2) > 0)
2895 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
2896 evas_object_line_xy_set(elo->evas_obj, x1, y1, x2, y2);
2898 evas_object_line_xy_get(elo->evas_obj, &x1, &y1, &x2, &y2);
2899 _elua_ret(L, "%x1 %y1 %x2 %y2", x1, y1, x2, y2);
2900 // Stack usage [-8, +9, em]
2908 @subsection evas_object_map Evas map class.
2910 The lua evas map class includes functions for dealing with evas map objects.
2911 The evas map objects must have been previously created by lua using the lua
2912 map object creation function edje:map(). The evas map system is complex, rather
2913 than repeat the copious documentation here, please refer to the evas map
2914 documentation. It has pictures and everything. B-)
2916 In the following, "map_object" is a place holder for any lua variable that
2917 holds a reference to an evas map object.
2922 static int _elua_map_alpha(lua_State *L);
2923 static int _elua_map_clockwise(lua_State *L);
2924 static int _elua_map_colour(lua_State *L);
2925 static int _elua_map_coord(lua_State *L);
2926 static int _elua_map_lighting(lua_State *L);
2927 static int _elua_map_perspective(lua_State *L);
2928 static int _elua_map_populate(lua_State *L);
2929 static int _elua_map_rotate(lua_State *L);
2930 static int _elua_map_rotate3d(lua_State *L);
2931 static int _elua_map_smooth(lua_State *L);
2932 static int _elua_map_uv(lua_State *L);
2933 static int _elua_map_zoom(lua_State *L);
2935 static const char *_elua_evas_map_api = "ewas_map";
2936 static const struct luaL_Reg _elua_evas_map_funcs [] =
2938 {"alpha", _elua_map_alpha},
2939 // {"dup", _elua_map_dup}, // not sure of proper api for this.
2940 {"clockwise", _elua_map_clockwise},
2941 {"color", _elua_map_colour},
2942 {"coord", _elua_map_coord},
2943 {"lighting", _elua_map_lighting},
2944 {"perspective", _elua_map_perspective},
2945 {"populate", _elua_map_populate},
2946 {"rotate", _elua_map_rotate},
2947 {"rotate3d", _elua_map_rotate3d},
2948 // {"size", _elua_map_size}, // not sure of proper API for this
2949 {"smooth", _elua_map_smooth},
2950 {"uv", _elua_map_uv},
2951 {"zoom", _elua_map_zoom},
2958 @subsubsection map_alpha map_object:alpha(alpha)
2960 Get (and optionally set) the maps alpha mode.
2962 Wraps evas_map_alpha_set().
2964 @param alpha The alpha mode.
2966 Note that the argument is optional, without it this function just queries the
2969 @return A boolean reflecting the alpha mode.
2974 _elua_map_alpha(lua_State *L) // Stack usage [-0, +1, -]
2976 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2977 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
2980 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
2982 n = lua_gettop(L); // Stack usage [-0, +0, -]
2985 evas_map_alpha_set(elm->map, lua_toboolean(L, 2));
2986 // Stack usage [-0, +0, -]
2988 lua_pushboolean(L, evas_map_alpha_get(elm->map)); // Stack usage [-0, +1, -]
2994 @subsubsection map_clockwise map_object:clockwise()
2996 Get the maps clockwise state.
2998 Wraps evas_map_util_clockwise_get().
3000 @return A boolean reflecting if the map is clockwise or not.
3005 _elua_map_clockwise(lua_State *L) // Stack usage [-0, +1, -]
3007 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3008 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3010 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3012 lua_pushboolean(L, evas_map_util_clockwise_get(elm->map)); // Stack usage [-0, +1, -]
3018 @subsubsection map_colour map_object:colour(index, r, g, b, a)
3020 Gets or sets colour information for the map. There are two variations, with or
3021 without the index. With the index parameter it gets (and optionally sets) the
3022 colour of the point the index refers to, without it sets the colour for the
3025 Wraps evas_map_point_color_set() or evas_map_util_points_color_set()
3027 @param index Which point to change the colour of.
3028 @param r The new red value.
3029 @param g The new green value.
3030 @param b The new blue value.
3031 @param a The new alpha value.
3033 Note that the arguments are optional, without them this function just queries
3034 the current values. The colour arguments can be separate values, or named
3037 @return A table with these fields:
3038 - integer r: The red value.
3039 - integer g: The green value.
3040 - integer b: The blue value.
3041 - integer a: The alpha value.
3046 _elua_map_colour(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
3048 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3049 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3053 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3054 n = lua_gettop(L); // Stack usage [-0, +0, -]
3060 if (_elua_scan_params(L, 2, "%r %g %b %a", &r, &g, &b, &a) > 0)
3061 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
3062 evas_map_util_points_color_set(elm->map, r, g, b, a);
3070 if (_elua_scan_params(L, 3, "%r %g %b %a", &r, &g, &b, &a) > 0)
3071 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
3072 evas_map_point_color_set(elm->map, lua_tointeger(L, 2), r, g, b, a);
3073 // Stack usage [-0, +0, -]
3075 evas_map_point_color_get(elm->map, lua_tointeger(L, 2), &r, &g, &b, &a);
3076 // Stack usage [-0, +0, -]
3077 _elua_ret(L, "%r %g %b %a", r, g, b, a);
3078 // Stack usage [-8, +9, em]
3088 @subsubsection map_coord map_object:coord(index, x, y, z)
3090 Gets (and optionally sets) the 3D coordinates of a point on the map.
3092 Wraps evas_map_point_coord_set().
3094 @param x The x coordinate of the point.
3095 @param y The y coordinate of the point.
3096 @param z The z coordinate of the point.
3098 Note that the arguments are optional, without them this function just queries
3099 the current values. The coordinate arguments can be separate values, or named
3102 @return A table with these fields:
3103 - integer x: The x coordinate of the point.
3104 - integer y: The y coordinate of the point.
3105 - integer z: The z coordinate of the point.
3110 _elua_map_coord(lua_State *L) // Stack usage [-(6|9), +(7|10), em]
3112 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3113 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3117 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3118 n = lua_gettop(L); // Stack usage [-0, +0, -]
3119 if (2 > n) return 0;
3121 if (_elua_scan_params(L, 2, "%x %y %z", &x, &y, &z) > 0)
3122 { // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3123 evas_map_point_coord_set(elm->map, lua_tointeger(L, 2), x, y, z);
3124 // Stack usage [-0, +0, -]
3126 evas_map_point_coord_get(elm->map, lua_tointeger(L, 2), &x, &y, &z);
3127 // Stack usage [-0, +0, -]
3128 _elua_ret(L, "%x %y %z", x, y, z);
3129 // Stack usage [-6, +7, em]
3135 @subsubsection map_lighting map_object:lighting(x, y, z, r, g, b, ar, ag, ab)
3137 Set the 3D lights for the map. The three triplets can be tables.
3139 Wraps evas_map_util_3d_lighting().
3141 @param x The x coordinate of the light point.
3142 @param y The y coordinate of the light point.
3143 @param z The z coordinate of the light point.
3144 @param r The new red value of the light point.
3145 @param g The new green value of the light point.
3146 @param b The new blue value of the light point.
3147 @param ar The new red value of the ambient light.
3148 @param ag The new green value of the ambient light.
3149 @param ab The new blue value of the ambient light.
3154 _elua_map_lighting(lua_State *L) // Stack usage [-(0|9), +(0|9), e]
3156 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3157 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3159 int r, g, b, r1, g1, b1;
3162 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3164 if ((n = _elua_scan_params(L, 2, "%x %y %z", &x, &y, &z)) > 0)
3165 // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3166 if (n += _elua_scan_params(L, 2 + n, "%r %g %b", &r, &g, &b) > 0)
3167 // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3168 if (_elua_scan_params(L, 2 + n, "%r %g %b", &r1, &g1, &b1) > 0)
3169 { // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3170 evas_map_util_3d_lighting(elm->map, x, y, z, r, g, b, r1, g1, b1);
3177 @subsubsection map_perspective map_object:perspective(x, y, z, f)
3179 Apply a perspective transform to the map.
3181 Wraps evas_map_util_3d_perspective().
3183 The arguments can be separate values, or named fields in a table.
3185 @param x The perspective distance X coordinate
3186 @param y The perspective distance Y coordinate
3187 @param z The "0" z plane value
3188 @param f The focal distance
3193 _elua_map_perspective(lua_State *L) // Stack usage [-(0|4), +(0|4), e]
3195 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3196 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3197 Evas_Coord x, y, z, f;
3199 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3201 if (_elua_scan_params(L, 2, "%x %y %z %f", &x, &y, &z, &f) > 0)
3202 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
3203 evas_map_util_3d_perspective(elm->map, x, y, z, f);
3210 @subsubsection map_populate map_object:populate(...)
3212 Populate the points in a map, in one of three different methods.
3214 1) Wraps evas_map_util_points_populate_from_object().
3216 @param source An evas object to copy points from.
3218 2) Wraps evas_map_util_paints_populate_from_object_full().
3220 @param source An evas object to copy points from.
3221 @param z Common Z coordinate hint for all four points.
3223 3) Wraps evas_map_util_points_populate_from_geometry().
3225 The first four arguments can be separate values, or named fields in a table.
3227 @param x Point X coordinate
3228 @param y Point Y coordinate
3229 @param w Width to use to calculate second and third points.
3230 @param h Height to use to calculate third and fourth points.
3231 @param z Common Z coordinate hint for all four points.
3236 _elua_map_populate(lua_State *L) // Stack usage [-(0|4), +(0|4), e]
3238 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3239 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3242 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3243 n = lua_gettop(L); // Stack usage [-0, +0, -]
3249 Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); // Stack usage [-0, +0, -]
3250 const Edje_Lua_Evas_Object *source = (Edje_Lua_Evas_Object *)obj2;
3252 if (!_elua_isa(obj2, _elua_evas_meta)) return 0;
3253 evas_map_util_points_populate_from_object(elm->map, source->evas_obj);
3259 Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); // Stack usage [-0, +0, -]
3260 const Edje_Lua_Evas_Object *source = (Edje_Lua_Evas_Object *)obj2;
3261 Evas_Coord z = lua_tointeger(L, 3);
3263 if (!_elua_isa(obj2, _elua_evas_meta)) return 0;
3264 evas_map_util_points_populate_from_object_full(elm->map, source->evas_obj, z);
3270 Evas_Coord x, y, w, h;
3272 if ((n = _elua_scan_params(L, 2, "%x %y %w %h", &x, &y, &w, &h)) > 0)
3273 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
3274 evas_map_util_points_populate_from_geometry(elm->map, x, y, w, h, lua_tointeger(L, 2 + n));
3284 @subsubsection map_rotate map_object:rotate(degrees, x, y)
3286 Rotate the maps coordinates in 2D.
3288 Wraps evas_map_util_rotate().
3290 The coordinates can be separate values, or named fields in a table.
3292 @param degrees Amount of degrees from 0.0 to 360.0 to rotate.
3293 @param x Rotation's centre horizontal position.
3294 @param y Rotation's centre vertical position.
3299 _elua_map_rotate(lua_State *L) // Stack usage [-(0|2), +(0|2), e]
3301 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3302 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3307 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3308 n = lua_gettop(L); // Stack usage [-0, +0, -]
3309 if (4 != n) return 0;
3311 degrees = lua_tonumber(L, 2);
3312 if (_elua_scan_params(L, 3, "%x %y", &x, &y) > 0)
3313 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3314 evas_map_util_rotate(elm->map, degrees, x, y);
3321 @subsubsection map_rotate3d map_object:rotate3d(dx, dy, dz, x, y, z)
3323 Rotate the maps coordinates in 3D.
3325 Wraps evas_map_util_3d_rotate().
3327 The coordinates can be separate values, or named fields in a table. The same
3330 @param dx Amount of degrees from 0.0 to 360.0 to rotate around X axis.
3331 @param dy Amount of degrees from 0.0 to 360.0 to rotate around Y axis.
3332 @param dz Amount of degrees from 0.0 to 360.0 to rotate around Z axis.
3333 @param x Rotation's centre horizontal position.
3334 @param y Rotation's centre vertical position.
3335 @param z Rotation's centre vertical position.
3340 _elua_map_rotate3d(lua_State *L) // Stack usage [-(0|6), +(0|6), e]
3342 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3343 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3348 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3350 if ((n = _elua_scan_params(L, 2, "#x #y #z", &zx, &zy, &zz)) > 0)
3351 // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3352 if (_elua_scan_params(L, 2 + n, "%x %y %z", &x, &y, &z) > 0)
3353 { // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3354 evas_map_util_3d_rotate(elm->map, zx, zy, zz, x, y, z);
3361 @subsubsection map_smooth map_object:smooth(smooth)
3363 Get (and optionally set) the maps smooth mode.
3365 Wraps evas_map_smooth_set().
3367 @param smooth The smooth mode.
3369 Note that the argument is optional, without it this function just queries the
3372 @return A boolean reflecting the smooth mode.
3377 _elua_map_smooth(lua_State *L) // Stack usage [-0, +1, -]
3379 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3380 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3383 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3385 n = lua_gettop(L); // Stack usage [-0, +0, -]
3388 evas_map_smooth_set(elm->map, lua_toboolean(L, 2));
3389 // Stack usage [-0, +0, -]
3391 lua_pushboolean(L, evas_map_smooth_get(elm->map)); // Stack usage [-0, +1, -]
3397 @subsubsection map_uv map_object:uv(index, u, v)
3399 Gets (and optionally sets) the texture U and V texture coordinates for this map.
3401 Wraps evas_map_point_image_uv_set().
3403 @param index Index of the point to change. Must be smaller than map size.
3404 @param u The X coordinate within the image/texture source.
3405 @param v The Y coordinate within the image/texture source.
3407 Note that the U,V arguments are optional, without them this function just queries
3408 the current values. The coordinate arguments can be separate values, or named
3411 @return A table with these fields:
3412 - number u: The X coordinate within the image/texture source.
3413 - number v: The Y coordinate within the image/texture source.
3418 _elua_map_uv(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
3420 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3421 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3425 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3426 n = lua_gettop(L); // Stack usage [-0, +0, -]
3427 if (2 > n) return 0;
3429 if (_elua_scan_params(L, 3, "#u #v", &u, &v) > 0)
3430 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3431 evas_map_point_image_uv_set(elm->map, lua_tonumber(L, 2), u, v);
3432 // Stack usage [-0, +0, -]
3434 evas_map_point_image_uv_get(elm->map, lua_tonumber(L, 2), &u, &v);
3435 // Stack usage [-0, +0, -]
3436 _elua_ret(L, "#u #v", u, v);
3437 // Stack usage [-4, +5, em]
3443 @subsubsection map_zoom map_object:zoom(x, y, x, y)
3445 Apply a zoom to the map.
3447 Wraps evas_map_util_zoom().
3449 The arguments can be two separate values, or named fields in a table.
3451 @param x The horizontal zoom amount.
3452 @param y The vertical zoom amount.
3453 @param x The X coordinate of the centre of the zoom.
3454 @param y The Y coordinate of the centre of the zoom.
3459 _elua_map_zoom(lua_State *L) // Stack usage [-(0|4), +(0|4), e]
3461 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3462 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3467 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3469 if ((n = _elua_scan_params(L, 2, "#x #y", &zx, &zy)) > 0)
3470 // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3471 if (_elua_scan_params(L, 2 + n, "%x %y", &x, &y) > 0)
3472 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3473 evas_map_util_zoom(elm->map, zx, zy, x, y);
3482 @subsection evas_polygon Evas polygon class.
3484 The lua evas polygon class includes functions for dealing with evas polygon objects.
3485 The evas polygon objects must have been previously created by lua using the lua
3486 polygon object creation function edje:polygon().
3488 In the following, "polygon_object" is a place holder for any lua variable that
3489 holds a reference to an evas polygon object.
3494 static int _elua_polygon_clear(lua_State *L);
3495 static int _elua_polygon_point(lua_State *L);
3497 static const char *_elua_evas_polygon_api = "evas_polygon";
3498 static const char *_elua_evas_polygon_parent = "evas_polygon_parent";
3499 static const struct luaL_Reg _elua_evas_polygon_funcs [] =
3501 {"clear", _elua_polygon_clear}, // clear all polygon points
3502 {"point", _elua_polygon_point}, // add a polygon point
3509 @subsubsection polygon_clear polygon_object:clear()
3511 Clears all points from the polygon.
3513 Wraps evas_object_polygon_points_clear(),
3518 _elua_polygon_clear(lua_State *L) // Stack usage [-0, +0, -]
3520 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3521 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
3523 if (!_elua_isa(obj, _elua_evas_polygon_meta)) return 0;
3524 evas_object_polygon_points_clear(elo->evas_obj);
3530 @subsubsection polygon_point polygon_object:point(x, y)
3532 Adds a point to this polygon.
3534 Wraps evas_object_polygon_point_add().
3536 @param x The X coordinate of the point.
3537 @param y The Y coordinate of the point.
3542 _elua_polygon_point(lua_State *L) // Stack usage [-(0|2), +(0|2), e]
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;
3548 if (!_elua_isa(obj, _elua_evas_polygon_meta)) return 0;
3550 if (_elua_scan_params(L, 2, "%x %y", &x, &y) > 0)
3551 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3552 evas_object_polygon_point_add(elo->evas_obj, x, y);
3562 @subsection evas_text Evas text class.
3564 The lua evas text class includes functions for dealing with evas text objects.
3565 The evas text objects must have been previously created by lua using the lua
3566 text object creation function edje:text().
3568 In the following, "text_object" is a place holder for any lua variable that
3569 holds a reference to an evas text object.
3574 static int _elua_text_font(lua_State *L);
3575 static int _elua_text_text(lua_State *L);
3577 static const char *_elua_evas_text_api = "evas_text";
3578 static const char *_elua_evas_text_parent = "evas_text_parent";
3579 static const struct luaL_Reg _elua_evas_text_funcs [] =
3581 {"font", _elua_text_font}, // get or set text font
3582 {"text", _elua_text_text}, // get or set text
3583 // {"text_class", _elua_object_text_class}, // get or set object text class
3590 @subsubsection text_font text_object:font(font, size)
3592 Gets, (and optionally sets) the font for this text object.
3594 Wraps evas_object_text_font_set().
3596 @param font The new font name.
3597 @param size The new font size.
3599 Note that the font and size arguments are optional, without them this function
3600 just queries the current values. The font and size arguments can be separate
3601 values, or named fields in a table. The font name can refer to a font in the
3602 edje file, or an external font.
3604 @return A table with these fields:
3605 - string font: The font name.
3606 - integer size: The font size.
3611 _elua_text_font(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
3613 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3614 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
3615 char *font, *font2 = NULL;
3616 Evas_Font_Size size;
3617 int inlined_font = 0;
3619 if (!_elua_isa(obj, _elua_evas_text_meta)) return 0;
3621 if (_elua_scan_params(L, 2, "$font %size", &font, &size) > 0)
3622 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3623 /* Check if the font is embedded in the .edj
3624 * This is a simple check.
3625 * There is a much more complicated version in edje_text.c _edje_text_recalc_apply().
3626 * If we need to get more complicated, we can do that later,
3627 * and maybe refactor things.
3629 if (obj->ed->file->fonts)
3631 Edje_Font_Directory_Entry *fnt = eina_hash_find(obj->ed->file->fonts, font);
3635 size_t len = strlen(font) + sizeof("edje/fonts/") + 1;
3636 font2 = alloca(len);
3637 sprintf(font2, "edje/fonts/%s", font);
3644 if (inlined_font) evas_object_text_font_source_set(elo->evas_obj, obj->ed->path);
3645 else evas_object_text_font_source_set(elo->evas_obj, NULL);
3647 evas_object_text_font_set(elo->evas_obj, font, size);
3650 // When one external API says it's gotta be const, and another one says not, then one of them's gotta be cast. :-P
3651 evas_object_text_font_get(elo->evas_obj, (const char **) &font, &size);
3652 _elua_ret(L, "$font %size", font, size);
3653 // Stack usage [-4, +5, em]
3659 @subsubsection text_text text_object:text(text)
3661 Get (and optionally set) the actual text for this text object.
3663 Wraps evas_object_text_text_set().
3665 @param text The text to set for this text object.
3667 Note that the argument is optional, without it this function just queries the
3670 @return A string of the text on this text object.
3675 _elua_text_text(lua_State *L) // Stack usage [-0, +1, m]
3677 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3678 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
3681 if (!_elua_isa(obj, _elua_evas_text_meta)) return 0;
3682 n = lua_gettop(L); // Stack usage [-0, +0, -]
3685 if (lua_isstring(L, 2))
3689 if ((str = lua_tostring(L, 2))) // Extra parenthesis, coz Mikes compiler has a lisp.
3690 // Stack usage [-0, +0, m]
3691 evas_object_text_text_set(elo->evas_obj, str);
3694 lua_pushstring(L, evas_object_text_text_get(elo->evas_obj)); // Stack usage [-0, +1, m]
3699 //--------------------------------------------------------------------------//
3701 // A metatable and functions so that calling non existant API does not crash Lua scripts.
3703 static int _elua_bogan_nilfunc(lua_State *L);
3704 static int _elua_bogan_index(lua_State *L);
3706 static const struct luaL_Reg _elua_bogan_funcs [] =
3708 {"nilfunc", _elua_bogan_nilfunc}, // Just return a nil.
3709 {"__index", _elua_bogan_index}, // Return the above func.
3715 _elua_bogan_nilfunc(lua_State *L)
3717 lua_getglobal(L, "nil");
3722 _elua_bogan_index(lua_State *L)
3726 key = lua_tostring(L, 2);
3727 LE("%s does not exist!", key);
3728 lua_pushcfunction(L, _elua_bogan_nilfunc);
3733 _elua_bogan_protect(lua_State *L) // Stack usage [-3, +3, m]
3735 lua_pushnil(L); // Stack usage [-0, +1, -]
3736 luaL_newmetatable(L, "bogan"); // Stack usage [-0, +1, m]
3737 luaL_register(L, 0, _elua_bogan_funcs); // Stack usage [-1, +1, m]
3738 lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
3739 lua_pop(L, 1); // Stack usage [-1, +0, -]
3742 //--------------------------------------------------------------------------//
3744 // Brain dead inheritance thingy, built for speed. Kinda. Part 1.
3746 _elua_add_functions(lua_State *L, const char *api, const luaL_Reg *funcs, const char *meta, const char *parent, const char *base) // Stack usage [-3, +5, m] if inheriting [-6, +11, em]
3748 // Create an api table, fill it full of the methods.
3749 luaL_register(L, api, funcs); // Stack usage [-0, +1, m]
3750 // Set the api metatable to the bogan metatable.
3751 luaL_getmetatable(L, "bogan"); // Stack usage [-0, +1, -]
3752 lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
3753 // Creat a meta metatable.
3754 luaL_newmetatable(L, meta); // Stack usage [-0, +1, m]
3755 // Put the gc functions in the metatable.
3756 luaL_register(L, 0, _elua_edje_gc_funcs); // Stack usage [-1, +1, m]
3757 // Create an __index entry in the metatable, make it point to the api table.
3758 lua_pushliteral(L, "__index"); // Stack usage [-0, +1, m]
3759 lua_pushvalue(L, -3); // Stack usage [-0, +1, -]
3760 lua_rawset(L, -3); // Stack usage [-2, +0, m]
3761 // Later this metatable is used as the metatable for newly created objects of this class.
3765 // Inherit from base
3766 lua_getglobal(L, base); // Stack usage [-0, +1, e]
3767 // Create a new parent metatable.
3768 luaL_newmetatable(L, parent); // Stack usage [-0, +1, m]
3769 // Create an __index entry in the metatable, make it point to the base table.
3770 lua_pushliteral(L, "__index"); // Stack usage [-0, +1, m]
3771 lua_pushvalue(L, -3); // Stack usage [-0, +1, -]
3772 lua_rawset(L, -3); // Stack usage [-2, +0, m]
3773 // Set the metatable for the api table to the parent metatable.
3774 lua_getglobal(L, api); // Stack usage [-0, +1, e]
3775 luaL_getmetatable(L, parent); // Stack usage [-0, +1, -]
3776 lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
3780 // Brain dead inheritance thingy, built for speed. Kinda. Part 2.
3782 _elua_isa(Edje_Lua_Obj *obj, const char *type)
3784 Eina_Bool isa = EINA_FALSE;
3786 if (!obj) return isa;
3787 if (obj->meta == type)
3789 if (_elua_evas_meta == type)
3791 if (obj->meta == _elua_evas_image_meta)
3793 else if (obj->meta == _elua_evas_text_meta)
3795 else if (obj->meta == _elua_evas_edje_meta)
3797 else if (obj->meta == _elua_evas_line_meta)
3799 else if (obj->meta == _elua_evas_polygon_meta)
3805 #ifndef RASTER_FORGOT_WHY
3807 _elua_init(void) // Stack usage [-16, +20, em]
3809 static Edje_Lua_Alloc ela = { MAX_LUA_MEM, 0 };
3815 lstate = L = lua_newstate(_elua_alloc, &ela); // Stack usage [-0, +0, -]
3816 lua_atpanic(L, _elua_custom_panic); // Stack usage [-0, +0, -]
3818 // FIXME: figure out optimal gc settings later
3819 // lua_gc(L, LUA_GCSETPAUSE, 200); // Stack usage [-0, +0, e]
3820 // lua_gc(L, LUA_GCSETSTEPMUL, 200); // Stack usage [-0, +0, e]
3822 for (l = _elua_libs; l->func; l++) // Currently * 4
3824 lua_pushcfunction(L, l->func); // Stack usage [-0, +1, m]
3825 lua_pushstring(L, l->name); // Stack usage [-0, +1, m]
3826 lua_call(L, 1, 0); // Stack usage [-2, +0, e]
3829 luaL_register(L, _elua_edje_api, _elua_edje_funcs); // Stack usage [-0, +1, m]
3830 luaL_newmetatable(L, _elua_edje_meta); // Stack usage [-0, +1, m]
3831 luaL_register(L, 0, _elua_edje_gc_funcs); // Stack usage [-1, +1, m]
3833 _elua_add_functions(L, _elua_evas_api, _elua_evas_funcs, _elua_evas_meta, NULL, NULL); // Stack usage [-3, +5, m]
3835 // weak table for our objects
3836 lua_pushlightuserdata(L, &_elua_objs); // Stack usage [-0, +1, -]
3837 lua_newtable(L); // Stack usage [-0, +1, m]
3838 lua_pushstring(L, "__mode"); // Stack usage [-0, +1, m]
3839 lua_pushstring(L, "v"); // Stack usage [-0, +1, m]
3840 lua_rawset(L, -3); // Stack usage [-2, +0, m]
3841 lua_rawset(L, LUA_REGISTRYINDEX); // Stack usage [-2, +0, m]
3846 _edje_lua2_script_init(Edje *ed) // Stack usage [-63, +99, em]
3848 static Edje_Lua_Alloc ela = { MAX_LUA_MEM, 0 };
3856 if (0 > _log_domain)
3857 _log_domain = eina_log_domain_register("lua", NULL);
3858 if (0 <= _log_domain)
3861 eina_log_domain_level_set("lua", EINA_LOG_LEVEL_WARN);
3864 #ifndef RASTER_FORGOT_WHY
3865 _elua_init(); // This is actually truly pointless, even if raster remembers.
3867 L = ed->L = lua_newstate(_elua_alloc, &ela); // Stack usage [-0, +0, -]
3868 lua_atpanic(L, _elua_custom_panic); // Stack usage [-0, +0, -]
3870 // FIXME: figure out optimal gc settings later
3871 // lua_gc(L, LUA_GCSETPAUSE, 200); // Stack usage [-0, +0, e]
3872 // lua_gc(L, LUA_GCSETSTEPMUL, 200); // Stack usage [-0, +0, e]
3874 for (l = _elua_libs; l->func; l++) // Currently * 4
3876 lua_pushcfunction(L, l->func); // Stack usage [-0, +1, m]
3877 lua_pushstring(L, l->name); // Stack usage [-0, +1, m]
3878 lua_call(L, 1, 0); // Stack usage [-2, +0, m]
3881 _elua_bogan_protect(L); // Stack usage [+3, -3, m]
3883 luaL_register(L, _elua_edje_api, _elua_edje_funcs); // Stack usage [-0, +1, m]
3884 luaL_getmetatable(L, "bogan"); // Stack usage [-0, +1, -]
3885 lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
3886 luaL_newmetatable(L, _elua_edje_meta); // Stack usage [-0, +1, m]
3887 luaL_register(L, 0, _elua_edje_gc_funcs); // Stack usage [-1, +1, m]
3889 lua_pop(L, 2); // Stack usage [-n, +0, -]
3891 _elua_add_functions(L, _elua_evas_api, _elua_evas_funcs, _elua_evas_meta, NULL, NULL);
3892 // Stack usage [-3, +5, m]
3893 _elua_add_functions(L, _elua_ecore_timer_api, _elua_ecore_timer_funcs, _elua_ecore_timer_meta, NULL, NULL);
3894 // Stack usage [-3, +5, m]
3895 _elua_add_functions(L, _elua_ecore_animator_api, _elua_ecore_animator_funcs, _elua_ecore_animator_meta, NULL, NULL);
3896 // Stack usage [-6, +11, m]
3897 _elua_add_functions(L, _elua_evas_edje_api, _elua_evas_edje_funcs, _elua_evas_edje_meta, _elua_evas_edje_parent, _elua_evas_api);
3898 // Stack usage [-6, +11, em]
3899 _elua_add_functions(L, _elua_evas_image_api, _elua_evas_image_funcs, _elua_evas_image_meta, _elua_evas_image_parent, _elua_evas_api);
3900 // Stack usage [-6, +11, em]
3901 _elua_add_functions(L, _elua_evas_line_api, _elua_evas_line_funcs, _elua_evas_line_meta, _elua_evas_line_parent, _elua_evas_api);
3902 // Stack usage [-6, +11, em]
3903 _elua_add_functions(L, _elua_evas_map_api, _elua_evas_map_funcs, _elua_evas_map_meta, NULL, NULL);
3904 // Stack usage [-3, +5, m]
3905 _elua_add_functions(L, _elua_evas_polygon_api, _elua_evas_polygon_funcs, _elua_evas_polygon_meta, _elua_evas_polygon_parent, _elua_evas_api);
3906 // Stack usage [-6, +11, em]
3907 _elua_add_functions(L, _elua_evas_text_api, _elua_evas_text_funcs, _elua_evas_text_meta, _elua_evas_text_parent, _elua_evas_api);
3908 // Stack usage [-6, +11, em]
3910 // weak table for our objects
3911 lua_pushlightuserdata(L, &_elua_objs); // Stack usage [-0, +1, -]
3912 lua_newtable(L); // Stack usage [-0, +1, m]
3913 lua_pushstring(L, "__mode"); // Stack usage [-0, +1, m]
3914 lua_pushstring(L, "v"); // Stack usage [-0, +1, m]
3915 lua_rawset(L, -3); // Stack usage [-2, +0, m]
3916 lua_rawset(L, LUA_REGISTRYINDEX); // Stack usage [-2, +0, m]
3918 _elua_table_ptr_set(L, _elua_key, ed); // Stack usage [-2, +2, e]
3920 snprintf(buf, sizeof(buf), "edje/scripts/lua/%i", ed->collection->id);
3921 data = eet_read(ed->file->ef, buf, &size);
3927 /* This ends up pushing a function onto the stack for the lua_pcall() below to use.
3928 * The function is the compiled code. */
3929 err = luaL_loadbuffer(L, data, size, "edje_lua_script"); // Stack usage [-0, +1, m]
3932 if (err == LUA_ERRSYNTAX)
3933 ERR("Lua load syntax error: %s",
3934 lua_tostring(L, -1)); // Stack usage [-0, +0, m]
3935 else if (err == LUA_ERRMEM)
3936 ERR("Lua load memory allocation error: %s",
3937 lua_tostring(L, -1)); // Stack usage [-0, +0, m]
3940 /* This is not needed, pcalls don't longjmp(), that's why they are protected.
3941 if (setjmp(panic_jmp) == 1)
3943 ERR("Lua script init panic");
3947 if ((err = lua_pcall(L, 0, 0, 0))) // Stack usage [-1, +0, -]
3948 _edje_lua2_error(L, err); // Stack usage [-0, +0, m]
3953 _edje_lua2_script_shutdown(Edje *ed)
3956 lua_close(ed->L); // Stack usage irrelevant, as it's all gone now.
3958 while (ed->lua_objs)
3960 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)ed->lua_objs;
3963 ERR("uncollected Lua object %p", obj);
3964 ed->lua_objs = eina_inlist_remove(ed->lua_objs, ed->lua_objs);
3968 ERR("dangling Lua object %p", obj);
3969 ed->lua_objs = eina_inlist_remove(ed->lua_objs, ed->lua_objs);
3973 if (0 <= _log_domain)
3976 if (0 >= _log_count)
3978 eina_log_domain_unregister(_log_domain);
3985 _edje_lua2_script_load(Edje_Part_Collection *edc __UNUSED__, void *data __UNUSED__, int size __UNUSED__) // Stack usage [-16, +20, em]
3987 #ifndef RASTER_FORGOT_WHY
3988 _elua_init(); // Stack usage [-16, +20, em]
3993 _edje_lua2_script_unload(Edje_Part_Collection *edc __UNUSED__) // Stack usage [-0, +0, e]
3995 #ifndef RASTER_FORGOT_WHY
3998 if (!lstate) return;
4000 lua_gc(L, LUA_GCCOLLECT, 0); // Stack usage [-0, +0, e]
4005 _edje_lua2_error_full(const char *file, const char *fnc, int line,
4006 lua_State *L, int err_code) // Stack usage [-0, +0, m]
4008 const char *err_type;
4013 err_type = "runtime";
4016 err_type = "syntax";
4019 err_type = "memory allocation";
4022 err_type = "error handler";
4025 err_type = "unknown";
4029 (_edje_default_log_dom, EINA_LOG_LEVEL_ERR, file, fnc, line,
4030 "Lua %s error: %s", err_type, lua_tostring(L, -1)); // Stack usage [-0, +0, m]
4035 @section callbacks Lua callbacks
4037 These are lua functions that are called by the lua edje system when certain
4038 events occur. If the functions don't exist in the lua group, they don't get
4045 @subsection edje_shutdown Edje shutdown() callback.
4047 If a function called "shutdown" exists in a lua edje group, then it is called when
4048 that edje gets deleted.
4051 _edje_lua2_script_func_shutdown(Edje *ed) // Stack usage [-1, +1, em]
4055 lua_getglobal(ed->L, "shutdown"); // Stack usage [-0, +1, e]
4056 if (!lua_isnil(ed->L, -1)) // Stack usage [-0, +0, -]
4058 if ((err = lua_pcall(ed->L, 0, 0, 0))) // Stack usage [-1, +0, -]
4059 _edje_lua2_error(ed->L, err); // Stack usage [-0, +0, m]
4062 lua_pop(ed->L, 1); // Stack usage [-n, +0, -]
4063 _edje_lua2_script_shutdown(ed);
4068 @subsection edje_show Edje show() callback.
4070 If a function called "show" exists in a lua edje group, then it is called when
4071 that edje gets shown.
4074 _edje_lua2_script_func_show(Edje *ed) // Stack usage [-1, +1, e]
4078 lua_getglobal(ed->L, "show");
4079 if (!lua_isnil(ed->L, -1))
4081 if ((err = lua_pcall(ed->L, 0, 0, 0)))
4082 _edje_lua2_error(ed->L, err);
4090 @subsection edje_hide Edje hide() callback.
4092 If a function called "hide" exists in a lua edje group, then it is called when
4093 that edje gets hidden.
4096 _edje_lua2_script_func_hide(Edje *ed) // Stack usage [-1, +1, e]
4100 lua_getglobal(ed->L, "hide");
4101 if (!lua_isnil(ed->L, -1))
4103 if ((err = lua_pcall(ed->L, 0, 0, 0)))
4104 _edje_lua2_error(ed->L, err);
4112 @subsection edje_move Edje move(x, y) callback.
4114 If a function called "move" exists in a lua edje group, then it is called when
4115 that edje gets moved, with the new position passed to it.
4118 _edje_lua2_script_func_move(Edje *ed) // Stack usage [-3, +3, e] or [-1, +1, e] if no matching function.
4122 // FIXME: move all objects created by script
4123 lua_getglobal(ed->L, "move"); // Stack usage [-0, +1, e]
4124 if (!lua_isnil(ed->L, -1)) // Stack usage [-0, +0, -]
4126 lua_pushinteger(ed->L, ed->x); // Stack usage [-0, +1, -]
4127 lua_pushinteger(ed->L, ed->y); // Stack usage [-0, +1, -]
4128 if ((err = lua_pcall(ed->L, 2, 0, 0))) // Stack usage [-3, +0, -]
4129 _edje_lua2_error(ed->L, err);
4132 lua_pop(ed->L, 1); // Stack usage [-n, +0, -]
4137 @subsection edje_resize Edje resize(w, h) callback.
4139 If a function called "resize" exists in a lua edje group, then it is called when
4140 that edje gets resized, with the new size passed to it.
4143 _edje_lua2_script_func_resize(Edje *ed) // Stack usage [-3, +3, e] or [-1, +1, e] if no matching function.
4147 lua_getglobal(ed->L, "resize");
4148 if (!lua_isnil(ed->L, -1))
4150 lua_pushinteger(ed->L, ed->w);
4151 lua_pushinteger(ed->L, ed->h);
4152 if ((err = lua_pcall(ed->L, 2, 0, 0)))
4153 _edje_lua2_error(ed->L, err);
4161 @subsection edje_message Edje message(id, type, ...) callback.
4163 If a function called "message" exists in a lua edje group, then it is called when
4164 that edje gets gets a message sent to it, with the message details passed to it.
4165 See edje:messagesend() for details of what each type means. The arrays are
4169 _edje_lua2_script_func_message(Edje *ed, Edje_Message *em) // Stack usage [-?, +?, em] It's complicated, but it's even at least.
4173 lua_getglobal(ed->L, "message"); // Stack usage [-0, +1, e]
4174 if (!lua_isnil(ed->L, -1)) // Stack usage [-0, +0, -]
4177 lua_pushinteger(ed->L, em->id); // Stack usage [-0, +1, -]
4180 case EDJE_MESSAGE_NONE:
4181 lua_pushstring(ed->L, "none"); // Stack usage [-0, +1, m]
4183 case EDJE_MESSAGE_SIGNAL:
4185 case EDJE_MESSAGE_STRING:
4186 lua_pushstring(ed->L, "str"); // Stack usage [-0, +1, m]
4187 lua_pushstring(ed->L, ((Edje_Message_String *)em->msg)->str);
4188 // Stack usage [-0, +1, m]
4191 case EDJE_MESSAGE_INT:
4192 lua_pushstring(ed->L, "int"); // Stack usage [-0, +1, m]
4193 lua_pushinteger(ed->L, ((Edje_Message_Int *)em->msg)->val);
4194 // Stack usage [-0, +1, -]
4197 case EDJE_MESSAGE_FLOAT:
4198 lua_pushstring(ed->L, "float"); // Stack usage [-0, +1, m]
4199 lua_pushnumber(ed->L, ((Edje_Message_Float *)em->msg)->val);
4200 // Stack usage [-0, +1, -]
4203 case EDJE_MESSAGE_STRING_SET:
4204 lua_pushstring(ed->L, "strset"); // Stack usage [-0, +1, m]
4205 c = ((Edje_Message_String_Set *)em->msg)->count;
4206 lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4207 for (i = 0; i < c; i++)
4209 lua_pushstring(ed->L, ((Edje_Message_String_Set *)em->msg)->str[i]);
4210 // Stack usage [-0, +1, m]
4211 // It's OK to bypass the metatable in these cases,
4212 // we create the table, and know there is no metatable. B-)
4213 lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4217 case EDJE_MESSAGE_INT_SET:
4218 lua_pushstring(ed->L, "intset"); // Stack usage [-0, +1, m]
4219 c = ((Edje_Message_Int_Set *)em->msg)->count;
4220 lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4221 for (i = 0; i < c; i++)
4223 lua_pushinteger(ed->L, ((Edje_Message_Int_Set *)em->msg)->val[i]);
4224 // Stack usage [-0, +1, -]
4225 lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4229 case EDJE_MESSAGE_FLOAT_SET:
4230 lua_pushstring(ed->L, "floatset"); // Stack usage [-0, +1, m]
4231 c = ((Edje_Message_Float_Set *)em->msg)->count;
4232 lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4233 for (i = 0; i < c; i++)
4235 lua_pushnumber(ed->L, ((Edje_Message_Float_Set *)em->msg)->val[i]);
4236 // Stack usage [-0, +1, -]
4237 lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4241 case EDJE_MESSAGE_STRING_INT:
4242 lua_pushstring(ed->L, "strint"); // Stack usage [-0, +1, m]
4243 lua_pushstring(ed->L, ((Edje_Message_String_Int *)em->msg)->str);
4244 // Stack usage [-0, +1, m]
4245 lua_pushinteger(ed->L, ((Edje_Message_String_Int *)em->msg)->val);
4246 // Stack usage [-0, +1, -]
4249 case EDJE_MESSAGE_STRING_FLOAT:
4250 lua_pushstring(ed->L, "strfloat"); // Stack usage [-0, +1, m]
4251 lua_pushstring(ed->L, ((Edje_Message_String_Float *)em->msg)->str);
4252 // Stack usage [-0, +1, m]
4253 lua_pushnumber(ed->L, ((Edje_Message_String_Float *)em->msg)->val);
4254 // Stack usage [-0, +1, -]
4257 case EDJE_MESSAGE_STRING_INT_SET:
4258 lua_pushstring(ed->L, "strintset"); // Stack usage [-0, +1, m]
4259 lua_pushstring(ed->L, ((Edje_Message_String_Int_Set *)em->msg)->str);
4260 // Stack usage [-0, +1, m]
4261 c = ((Edje_Message_String_Int_Set *)em->msg)->count;
4262 lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4263 for (i = 0; i < c; i++)
4265 lua_pushinteger(ed->L, ((Edje_Message_String_Int_Set *)em->msg)->val[i]);
4266 // Stack usage [-0, +1, -]
4267 lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4271 case EDJE_MESSAGE_STRING_FLOAT_SET:
4272 lua_pushstring(ed->L, "strfloatset"); // Stack usage [-0, +1, m]
4273 lua_pushstring(ed->L, ((Edje_Message_String_Float_Set *)em->msg)->str);
4274 // Stack usage [-0, +1, m]
4275 c = ((Edje_Message_String_Float_Set *)em->msg)->count;
4276 lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4277 for (i = 0; i < c; i++)
4279 lua_pushnumber(ed->L, ((Edje_Message_String_Float_Set *)em->msg)->val[i]);
4280 // Stack usage [-0, +1, -]
4281 lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4288 if ((err = lua_pcall(ed->L, n, 0, 0))) // Stack usage [-n+1, +0, -]
4289 _edje_lua2_error(ed->L, err);
4292 lua_pop(ed->L, 1); // Stack usage [-n, +0, -]
4297 @subsection edje_signal Edje signal(signal, source) callback.
4299 If a function called "signal" exists in a lua edje group, then it is called when
4300 ever a signal arrives, with the signal details passed to it.
4304 _edje_lua2_script_func_signal(Edje *ed, const char *sig, const char *src) // Stack usage [-3, +3, em] or [-1, +1, e] if no matching function.
4308 lua_getglobal(ed->L, "signal");
4309 if (!lua_isnil(ed->L, -1))
4311 lua_pushstring(ed->L, sig);
4312 lua_pushstring(ed->L, src);
4313 if ((err = lua_pcall(ed->L, 2, 0, 0)))
4314 _edje_lua2_error(ed->L, err);