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, Edje_Lua_Obj *obj)
332 if (!obj->free_func) return;
333 // Free the reference, so it will actually get gc'd.
334 // It seems that being a completely weak table isn't enough.
335 lua_pushnil(L); // Stack usage [-0, +1, -]
336 _elua_ref_set(L, obj); // Stack usage [-4, +4, m]
338 obj->ed->lua_objs = eina_inlist_remove(obj->ed->lua_objs, EINA_INLIST_GET(obj));
339 obj->free_func = NULL;
344 _elua_obj_gc(lua_State *L) // Stack usage [-0, +0, -]
346 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
348 _elua_obj_free(L, obj);
353 _elua_obj_del(lua_State *L) // Stack usage [-0, +0, -]
355 return _elua_obj_gc(L); // Stack usage [-0, +0, -]
359 _elua_gc(lua_State *L) // Stack usage [-0, +0, e]
361 lua_gc(L, LUA_GCCOLLECT, 0); // Stack usage [-0, +0, e]
364 // These are what the various symbols are for each type -
369 // FIXME: Still to do, if we ever use them -
378 _elua_push_name(lua_State *L, char *q, int idx) // Stack usage [-0, +1, e or m]
383 // A simplistic scan through an identifier, it's wrong, but it's quick,
384 // and we don't mind that it's wrong, coz this is only internal.
385 while (isalnum((int)*q))
390 lua_getfield(L, idx, p); // Stack usage [-0, +1, e]
392 lua_pushstring(L, p); // Stack usage [-0, +1, m]
399 _elua_scan_params(lua_State *L, int i, char *params, ...) // Stack usage -
406 char *f = strdup(params);
408 int n = 0, j = i, count = 0;
409 Eina_Bool table = EINA_FALSE;
412 va_start(vl, params);
414 if (lua_istable(L, i)) // Stack usage [-0, +0, -]
423 Eina_Bool get = EINA_TRUE;
425 while (isspace((int)*p))
434 q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e]
436 if (lua_isnumber(L, j)) // Stack usage [-0, +0, -]
438 int *v = va_arg(vl, int *);
439 *v = lua_tointeger(L, j); // Stack usage [-0, +0, -]
448 q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e]
450 if (lua_isnumber(L, j)) // Stack usage [-0, +0, -]
452 double *v = va_arg(vl, double *);
453 *v = lua_tonumber(L, j); // Stack usage [-0, +0, -]
462 q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e]
464 if (lua_isstring(L, j)) // Stack usage [-0, +0, -]
466 char **v = va_arg(vl, char **);
468 char *temp = (char *) lua_tolstring(L, j, &len); // Stack usage [-0, +0, m]
470 len++; // Cater for the null at the end.
474 memcpy(*v, temp, len);
484 q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e]
486 if (lua_isboolean(L, j)) // Stack usage [-0, +0, -]
488 int *v = va_arg(vl, int *);
489 *v = lua_toboolean(L, j); // Stack usage [-0, +0, -]
505 // If this is a table, then we pushed a value on the stack, pop it off.
506 lua_pop(L, 1); // Stack usage [-n, +0, -]
525 _elua_ret(lua_State *L, char *params, ...) // Stack usage [-(2*n), +(2*n+1), em]
528 char *f = strdup(params);
534 lua_newtable(L); // Stack usage [-0, +1, m]
535 va_start(vl, params);
540 Eina_Bool set = EINA_TRUE;
542 while (isspace((int)*p))
549 q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m]
550 lua_pushinteger(L, va_arg(vl, int)); // Stack usage [-0, +1, -]
555 q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m]
556 lua_pushnumber(L, va_arg(vl, double)); // Stack usage [-0, +1, -]
561 q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m]
562 lua_pushstring(L, va_arg(vl, char *)); // Stack usage [-0, +1, m]
567 q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m]
568 lua_pushboolean(L, va_arg(vl, int)); // Stack usage [-0, +1, -]
580 lua_settable(L, -3); // Stack usage [-2, +0, e]
592 _elua_color_fix(int *r, int *g, int *b, int *a)
594 if (*r > *a) *r = *a;
595 if (*g > *a) *g = *a;
596 if (*b > *a) *b = *a;
599 //--------------------------------------------------------------------------//
603 @subsection edje Edje class.
605 The lua edje class includes functions for dealing with the lua script only group
606 as an edje object, basic functions, and functions to create other objects.
608 In the following, "edje" is the actual global table used to access these edje functions.
611 static int _elua_echo(lua_State *L);
613 static int _elua_date(lua_State *L);
614 static int _elua_looptime(lua_State *L);
615 static int _elua_seconds(lua_State *L);
616 static int _elua_version(lua_State *L);
618 static int _elua_objgeom(lua_State *L);
619 static int _elua_objpos(lua_State *L);
620 static int _elua_objsize(lua_State *L);
622 static int _elua_emit(lua_State *L);
623 static int _elua_messagesend(lua_State *L);
625 static int _elua_animator(lua_State *L);
626 static int _elua_timer(lua_State *L);
627 static int _elua_transition(lua_State *L);
629 static int _elua_color_class(lua_State *L);
630 static int _elua_text_class(lua_State *L);
632 static int _elua_edje(lua_State *L);
633 static int _elua_image(lua_State *L);
634 static int _elua_line(lua_State *L);
635 static int _elua_map(lua_State *L);
636 static int _elua_polygon(lua_State *L);
637 static int _elua_rect(lua_State *L);
638 static int _elua_text(lua_State *L);
639 //static int _elua_textblock(lua_State *L); /* XXX: disabled until there are enough textblock functions implemented to make it actually useful
641 static const char *_elua_edje_api = "edje";
642 static const struct luaL_Reg _elua_edje_funcs [] =
644 // add an echo too to make it more shelly
645 {"echo", _elua_echo}, // test func - echo (i know we have print. test)
646 // FIXME: add logging functions here, probably to it's own domain, or even a script defined domain.
648 // system information (time, date blah blah)
649 {"date", _elua_date}, // get date in a table
650 {"looptime", _elua_looptime}, // get loop time
651 {"seconds", _elua_seconds}, // get seconds
652 {"version", _elua_version}, // edje version
654 // query edje - size, pos
655 {"geom", _elua_objgeom}, // get while edje object geometry in canvas
656 {"pos", _elua_objpos}, // get while edje object pos in canvas
657 {"size", _elua_objsize}, // get while edje object pos in canvas
659 // talk to application/caller
660 {"emit", _elua_emit}, // emit signal + src
661 {"messagesend", _elua_messagesend}, // send a structured message
663 // time based "callback" systems
664 {"animator", _elua_animator}, // add animator
665 {"timer", _elua_timer}, // add timer
666 {"transition", _elua_transition}, // add transition
667 // FIXME: need poller
669 // set and query color / text class
670 {"color_class", _elua_color_class},
671 {"text_class", _elua_text_class},
673 // create new objects
674 {"edje", _elua_edje},
675 {"image", _elua_image}, // defaults to a filled image.
676 {"line", _elua_line},
678 {"polygon", _elua_polygon},
679 {"rect", _elua_rect},
680 {"text", _elua_text},
681 // {"textblock", _elua_textblock}, /* XXX: disabled until there are enough textblock functions implemented to make it actually useful
683 // FIXME: add the new sound stuff.
690 @subsubsection edje_echo edje:echo(text)
692 Make lua a bit shelly. Prints a string to the console
694 @param text The string to print.
697 _elua_echo(lua_State *L) // Stack usage [-0, +0, v]
699 const char *string = luaL_checkstring(L, 1); // Stack usage [-0, +0, v]
707 @subsubsection edje_date edje:date()
709 Retrieves the current time and date.
711 Wraps gettimeofday(), as passed through localtime().
713 @return A table with these fields:
714 - integer year: Year.
715 - integer month: Month of the year.
716 - integer day: Day of the month.
717 - integer yearday: Day of the year.
718 - integer weekday: Day of the week.
719 - integer hour: Hour of the day (24 hour format).
720 - integer min: Minute of the hour.
721 - number sec: Seconds as a number.
725 _elua_date(lua_State *L) // Stack usage [-16, +17, em]
727 static time_t last_tzset = 0;
728 struct timeval timev;
732 gettimeofday(&timev, NULL);
733 tt = (time_t)(timev.tv_sec);
734 if ((tt > (last_tzset + 1)) || (tt < (last_tzset - 1)))
741 { // Stack usage [-16, +17, em]
742 _elua_ret(L, "%year %month %day %yearday %weekday %hour %min #sec",
743 (int)(tm->tm_year + 1900),
744 (int)(tm->tm_mon + 1),
747 (int)((tm->tm_wday + 6) % 7),
750 (double)((double)tm->tm_sec + (((double)timev.tv_usec) / 1000000))
760 @subsubsection edje_looptime edje:looptime()
762 Retrieves the time at which the last loop stopped waiting for timeouts or events.
764 This gets the time that the main loop ceased waiting for timouts and/or events
765 to come in or for signals or any other interrupt source. This should be
766 considered a reference point for all time based activity that should calculate
767 its timepoint from the return of edje:looptime(). Use this UNLESS you absolutely
768 must get the current actual timepoint - then use edje:seconds(). Note that this
769 time is meant to be used as relative to other times obtained on this run.
771 Wraps ecore_loop_time_get().
773 @returns A number of seconds.
776 _elua_looptime(lua_State *L) // Stack usage [-0, +1, -]
778 double t = ecore_loop_time_get();
779 lua_pushnumber(L, t); // Stack usage [-0, +1, -]
785 @subsubsection edje_seconds edje:seconds()
787 Retrieves the current system time as a floating point value in seconds.
789 This uses a monotonic clock and thus never goes back in time while machine is
790 live (even if user changes time or timezone changes, however it may be reset
791 whenever the machine is restarted).
793 Wraps ecore_time_get().
795 @returns A number of seconds.
798 _elua_seconds(lua_State *L) // Stack usage [-0, +1, -]
800 double t = ecore_time_get();
801 lua_pushnumber(L, t); // Stack usage [-0, +1, -]
807 @subsubsection edje_version edje:version()
809 Retrieves the current edje version number.
811 @returns A table with these fields:
812 - integer major: The edje version major number.
813 - integer minor: The edje version minor number.
818 _elua_version(lua_State *L) // Stack usage [-4, +5, em]
820 _elua_ret(L, "%major %minor", EDJE_VERSION_MAJOR, EDJE_VERSION_MINOR); // Stack usage [-4, +5, em]
827 @subsubsection edje_geom edje:geom()
829 Retrieves the position and size of the edje object that this lua group is in.
831 @returns A table with these fields:
832 - integer x: The edjes X position.
833 - integer y: The edjes Y position.
834 - integer w: The edjes width.
835 - integer h: The edjes height.
838 _elua_objgeom(lua_State *L) // Stack usage [-10, +11, em]
840 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
841 _elua_ret(L, "%x %y %w %h", ed->x, ed->y, ed->w, ed->h); // Stack usage [-8, +9, em]
847 @subsubsection edje_pos edje:pos()
850 Retrieves the position of the edje object that this lua group is in.
852 @returns A table with these fields:
853 - integer x: The edjes X position.
854 - integer y: The edjes Y position.
857 _elua_objpos(lua_State *L) // Stack usage [-6, +7, em]
859 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
860 _elua_ret(L, "%x %y", ed->x, ed->y); // Stack usage [-4, +5, em]
866 @subsubsection edje_size edje:size()
869 Retrieves the size of the edje object that this lua group is in.
871 @returns A table with these fields:
872 - integer w: The edjes width.
873 - integer h: The edjes height.
876 _elua_objsize(lua_State *L) // Stack usage [-6, +7, em]
878 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
879 _elua_ret(L, "%w %h", ed->w, ed->h); // Stack usage [-4, +5, em]
886 @subsubsection edje_emit edje:emit(signal, source)
890 Wraps edje_object_signal_emit().
892 @param signal The signal string to send.
893 @param source The source string of the signal.
895 NOTE: The source string will have a name and a colon prepended to in when it is
896 delivered to things that are not this edje, like C and other edje groups.
897 If this edje is a top level edje, then it will be the name of the group (I think).
898 If this edje is swallowed into some other part, then it will be the name of the
903 FIXME: I actually have no idea what happens if it's swallowed into another lua
907 _elua_emit(lua_State *L) // Stack usage [-2, +2, ev]
909 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
910 const char *sig = luaL_checkstring(L, 1); // Stack usage [-0, +0, v]
911 const char *src = luaL_checkstring(L, 2); // Stack usage [-0, +0, v]
912 if ((!sig) || (!src)) return 0;
913 _edje_emit(ed, sig, src);
919 @subsubsection edje_message_send edje:messagesend(id, type, ...)
921 Send a message to this edje, and all it's child objects.
923 Wraps edje_object_message_send().
925 @param id An identification integer for the message.
926 @param type The type of message to send.
927 @param ... Zero or more things to send as part of the message, depending on the type.
929 The type can be one of:
931 - sig: The msg is two strings (signal, source), sent as a signal.
932 - str: The msg is a C string.
933 - int: The message is a C integer.
934 - float: The message is a C float.
935 - strset: The message is an array of C strings.
936 - intset: The message is an array of C integers.
937 - floatset: The message is an array of C floats.
938 - strint: The message is a C stnring and a C integer.
939 - strfloat: The message is a C string and a C float.
940 - strintset: The message is a C string and an array of C integers.
941 - strfloatset: The message is a G string and an array of C floats.
943 For the array types, the lua caller passes a table.
946 _elua_messagesend(lua_State *L) // Stack usage [-2, +2, ev] plus [-2, +2] for every element if it's an array message.
948 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
949 int id = luaL_checkinteger(L, 1); // Stack usage [-0, +0, v]
950 const char *type = luaL_checkstring(L, 2); // Stack usage [-0, +0, v]
952 if (!strcmp(type, "none"))
954 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_NONE, id, NULL);
956 else if (!strcmp(type, "sig"))
958 const char *sig = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
959 const char *src = luaL_checkstring(L, 4); // Stack usage [-0, +0, v]
960 _edje_emit(ed, sig, src);
962 else if (!strcmp(type, "str"))
964 Edje_Message_String *emsg;
965 const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
966 emsg = alloca(sizeof(Edje_Message_String));
967 emsg->str = (char *)str;
968 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING, id, emsg);
970 else if (!strcmp(type, "int"))
972 Edje_Message_Int *emsg;
973 int val = luaL_checkinteger(L, 3); // Stack usage [-0, +0, v]
974 emsg = alloca(sizeof(Edje_Message_Int));
976 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_INT, id, emsg);
978 else if (!strcmp(type, "float"))
980 Edje_Message_Float *emsg;
981 float val = luaL_checknumber(L, 3); // Stack usage [-0, +0, v]
982 emsg = alloca(sizeof(Edje_Message_Float));
984 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_FLOAT, id, emsg);
986 else if (!strcmp(type, "strset"))
988 Edje_Message_String_Set *emsg;
991 luaL_checktype(L, 3, LUA_TTABLE); // Stack usage [-0, +0, v]
992 #if LUA_VERSION_NUM >= 502
993 n = lua_rawlen(L, 3); // Stack usage [-0, +0, -]
995 n = lua_objlen(L, 3); // Stack usage [-0, +0, -]
997 emsg = alloca(sizeof(Edje_Message_String_Set) + ((n - 1) * sizeof(char *)));
999 for (i = 1; i <= n; i ++)
1001 lua_pushinteger(L, i); // Stack usage [-0, +1, -]
1002 lua_gettable(L, 3); // Stack usage [-1, +1, e]
1003 str = lua_tostring(L, -1); // Stack usage [-0, +0, m]
1004 lua_pop(L, 1); // Stack usage [-n, +0, -]
1005 emsg->str[i - 1] = (char *)str;
1007 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_SET, id, emsg);
1009 else if (!strcmp(type, "intset"))
1011 Edje_Message_Int_Set *emsg;
1013 luaL_checktype(L, 3, LUA_TTABLE); // Stack usage [-0, +0, v]
1014 #if LUA_VERSION_NUM >= 502
1015 n = lua_rawlen(L, 3); // Stack usage [-0, +0, -]
1017 n = lua_objlen(L, 3); // Stack usage [-0, +0, -]
1019 emsg = alloca(sizeof(Edje_Message_Int_Set) + ((n - 1) * sizeof(int)));
1021 for (i = 1; i <= n; i ++)
1023 lua_pushinteger(L, i); // Stack usage [-0, +1, -]
1024 lua_gettable(L, 3); // Stack usage [-1, +1, e]
1025 emsg->val[i - 1] = lua_tointeger(L, -1); // Stack usage [-0, +0, -]
1026 lua_pop(L, 1); // Stack usage [-n, +0, -]
1028 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_INT_SET, id, emsg);
1030 else if (!strcmp(type, "floatset"))
1032 Edje_Message_Float_Set *emsg;
1034 luaL_checktype(L, 3, LUA_TTABLE); // Stack usage [-0, +0, v]
1035 #if LUA_VERSION_NUM >= 502
1036 n = lua_rawlen(L, 3); // Stack usage [-0, +0, -]
1038 n = lua_objlen(L, 3); // Stack usage [-0, +0, -]
1040 emsg = alloca(sizeof(Edje_Message_Float_Set) + ((n - 1) * sizeof(double)));
1042 for (i = 1; i <= n; i ++)
1044 lua_pushinteger(L, i); // Stack usage [-0, +1, -]
1045 lua_gettable(L, 3); // Stack usage [-1, +1, e]
1046 emsg->val[i - 1] = lua_tonumber(L, -1); // Stack usage [-0, +0, -]
1047 lua_pop(L, 1); // Stack usage [-n, +0, -]
1049 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_FLOAT_SET, id, emsg);
1051 else if (!strcmp(type, "strint"))
1053 Edje_Message_String_Int *emsg;
1054 const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
1055 emsg = alloca(sizeof(Edje_Message_String_Int));
1056 emsg->str = (char *)str;
1057 emsg->val = luaL_checkinteger(L, 4); // Stack usage [-0, +0, v]
1058 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_INT, id, emsg);
1060 else if (!strcmp(type, "strfloat"))
1062 Edje_Message_String_Float *emsg;
1063 const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
1064 emsg = alloca(sizeof(Edje_Message_String_Float));
1065 emsg->str = (char *)str;
1066 emsg->val = luaL_checknumber(L, 4); // Stack usage [-0, +0, v]
1067 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_FLOAT, id, emsg);
1069 else if (!strcmp(type, "strintset"))
1071 Edje_Message_String_Int_Set *emsg;
1073 const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
1075 luaL_checktype(L, 4, LUA_TTABLE); // Stack usage [-0, +0, v]
1076 #if LUA_VERSION_NUM >= 502
1077 n = lua_rawlen(L, 4); // Stack usage [-0, +0, -]
1079 n = lua_objlen(L, 4); // Stack usage [-0, +0, -]
1081 emsg = alloca(sizeof(Edje_Message_String_Int_Set) + ((n - 1) * sizeof(int)));
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_tointeger(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_INT_SET, id, emsg);
1093 else if (!strcmp(type, "strfloatset"))
1095 Edje_Message_String_Float_Set *emsg;
1097 const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
1099 luaL_checktype(L, 4, LUA_TTABLE); // Stack usage [-0, +0, v]
1100 #if LUA_VERSION_NUM >= 502
1101 n = lua_rawlen(L, 4); // Stack usage [-0, +0, -]
1103 n = lua_objlen(L, 4);
1105 emsg = alloca(sizeof(Edje_Message_String_Float_Set) + ((n - 1) * sizeof(double)));
1106 emsg->str = (char *)str;
1108 for (i = 1; i <= n; i ++)
1110 lua_pushinteger(L, i); // Stack usage [-0, +1, -]
1111 lua_gettable(L, 4); // Stack usage [-1, +1, e]
1112 emsg->val[i - 1] = lua_tonumber(L, -1); // Stack usage [-0, +0, -]
1113 lua_pop(L, 1); // Stack usage [-n, +0, -]
1115 _edje_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_FLOAT_SET, id, emsg);
1122 _elua_animator_cb(void *data) // Stack usage [-2, +2, em]
1124 Edje_Lua_Animator *ela = data;
1126 int ret = 0, err = 0;
1128 if (!ela->obj.ed) return 0;
1131 /* This is not needed, pcalls don't longjmp(), that's why they are protected.
1132 if (setjmp(panic_jmp) == 1)
1134 LE("Animator callback panic");
1135 _edje_lua2_error(L, err); // Stack usage [-0, +0, m]
1136 _elua_obj_free(L, (Edje_Lua_Obj *)ela);
1137 _elua_gc(L); // Stack usage [-0, +0, e]
1141 lua_rawgeti(L, LUA_REGISTRYINDEX, ela->fn_ref); // Stack usage [-0, +1, -]
1142 if ((err = lua_pcall(L, 0, 1, 0))) // Stack usage [-1, +1, -]
1144 _edje_lua2_error(L, err); // Stack usage [-0, +0, m]
1145 _elua_obj_free(L, (Edje_Lua_Obj *)ela);
1146 _elua_gc(L); // Stack usage [-0, +0, e]
1149 ret = lua_toboolean(L, -1); // Stack usage [-0, +0, -]
1150 lua_pop(L, 1); // Stack usage [-n, +0, -]
1151 if (ret == 0) _elua_obj_free(L, (Edje_Lua_Obj *)ela);
1152 _elua_gc(L); // Stack usage [-0, +0, e]
1157 _elua_animator_free(void *obj) // Stack usage [-0, +0, -]
1159 Edje_Lua_Animator *ela = obj;
1161 if (!ela->obj.ed) return;
1163 luaL_unref(L, LUA_REGISTRYINDEX, ela->fn_ref); // Stack usage [-0, +0, -]
1165 ecore_animator_del(ela->animator);
1166 ela->animator = NULL;
1171 @subsubsection edje_animator edje:animator(func)
1173 This function adds an animator and returns its handle on success and NULL on
1174 failure. The function func will be called every frame tick. Note that setting
1175 the frame tick is not available as a lua function, so has to be done from C.
1176 The default tick is 1/30 second.
1178 When the animator func is called, it must return a value of either true or false.
1179 If it returns true it will be called again at the next tick, or if it returns
1180 false it will be deleted automatically making any references/handles for it
1183 Wraps ecore_animator_add().
1185 @param func The function to call when the animator triggers.
1187 @returns A userdata that is an ecore animator.
1190 _elua_animator(lua_State *L) // Stack usage [-8, +9, emv]
1192 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
1193 Edje_Lua_Animator *ela;
1195 luaL_checkany(L, 1); // Stack usage [-0, +0, v]
1197 // FIXME: Allow lua to set a data to be sent back with the callback.
1198 ela = (Edje_Lua_Animator *)_elua_obj_new(L, ed, sizeof(Edje_Lua_Animator), _elua_ecore_animator_meta);
1199 // Stack usage [-5, +6, m]
1200 ela->obj.free_func = _elua_animator_free;
1201 ela->animator = ecore_animator_add(_elua_animator_cb, ela);
1202 lua_pushvalue(L, 1); // Stack usage [-0, +1, -]
1203 ela->fn_ref = luaL_ref(L, LUA_REGISTRYINDEX); // Stack usage [-1, +0, m]
1204 _elua_gc(L); // Stack usage [-0, +0, e]
1209 _elua_timer_cb(void *data) // Stack usage [-2, +2, em]
1211 Edje_Lua_Timer *elt = data;
1213 int ret = 0, err = 0;
1215 if (!elt->obj.ed) return 0;
1218 /* This is not needed, pcalls don't longjmp(), that's why they are protected.
1219 if (setjmp(panic_jmp) == 1)
1221 LE("Timer callback panic");
1222 _edje_lua2_error(L, err); // Stack usage [-0, +0, m]
1223 _elua_obj_free(L, (Edje_Lua_Obj *)elt);
1224 _elua_gc(L); // Stack usage [-0, +0, e]
1228 lua_rawgeti(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +1, -]
1229 if ((err = lua_pcall(L, 0, 1, 0))) // Stack usage [-1, +1, -]
1231 _edje_lua2_error(L, err);
1232 _elua_obj_free(L, (Edje_Lua_Obj *)elt); // Stack usage [-0, +0, m]
1233 _elua_gc(L); // Stack usage [-0, +0, e]
1236 ret = lua_toboolean(L, -1); // Stack usage [-0, +0, -]
1237 lua_pop(L, 1); // Stack usage [-n, +0, -]
1238 if (ret == 0) _elua_obj_free(L, (Edje_Lua_Obj *)elt);
1239 _elua_gc(L); // Stack usage [-0, +0, e]
1244 _elua_timer_free(void *obj) // Stack usage [-0, +0, -]
1246 Edje_Lua_Timer *elt = obj;
1248 if (!elt->obj.ed) return;
1250 luaL_unref(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +0, -]
1252 ecore_timer_del(elt->timer);
1258 @subsubsection edje_timer edje:timer(tick, func)
1260 This function adds a timer and returns its handle on success and NULL on failure.
1261 The function func will be called every tick seconds.
1263 When the timer func is called, it must return a value of either true or false.
1264 If it returns true, it will be called again at the next tick, or if it returns
1265 false it will be deleted automatically making any references/handles for it
1268 Wraps ecore_timer_add().
1270 @param tick How often, in seconds, to call the function.
1271 @param func The function to call when the timer triggers.
1273 @returns A userdata that is an ecore timer.
1276 _elua_timer(lua_State *L) // Stack usage [-8, +9, emv]
1278 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
1279 Edje_Lua_Timer *elt;
1282 val = luaL_checknumber(L, 1); // Stack usage [-0, +0, v]
1283 luaL_checkany(L, 2); // Stack usage [-0, +0, v]
1285 elt = (Edje_Lua_Timer *)_elua_obj_new(L, ed, sizeof(Edje_Lua_Timer), _elua_ecore_timer_meta);
1286 // Stack usage [-5, +6, m]
1287 elt->obj.free_func = _elua_timer_free;
1288 elt->timer = ecore_timer_add(val, _elua_timer_cb, elt);
1289 lua_pushvalue(L, 2); // Stack usage [-0, +1, -]
1290 elt->fn_ref = luaL_ref(L, LUA_REGISTRYINDEX); // Stack usage [-1, +0, m]
1291 _elua_gc(L); // Stack usage [-0, +0, e]
1296 _elua_transition_cb(void *data) // Stack usage [-3, +3, em]
1298 Edje_Lua_Transition *elt = data;
1300 int ret = 0, err = 0;
1303 if (!elt->obj.ed) return 0;
1306 t = (ecore_loop_time_get() - elt->start) / elt->transition;
1307 if (t > 1.0) t = 1.0;
1308 /* This is not needed, pcalls don't longjmp(), that's why they are protected.
1309 if (setjmp(panic_jmp) == 1)
1311 LE("Transition callback panic");
1312 _edje_lua2_error(L, err); // Stack usage [-0, +0, m]
1313 _elua_obj_free(L, (Edje_Lua_Obj *)elt);
1314 _elua_gc(L); // Stack usage [-0, +0, e]
1318 lua_rawgeti(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +1, -]
1319 lua_pushnumber(L, t); // Stack usage [-0, +1, -]
1320 if ((err = lua_pcall(L, 1, 1, 0))) // Stack usage [-2, +1, -]
1322 _edje_lua2_error(L, err);
1323 _elua_obj_free(L, (Edje_Lua_Obj *)elt); // Stack usage [-0, +0, m]
1324 _elua_gc(L); // Stack usage [-0, +0, e]
1327 ret = lua_toboolean(L, -1); // Stack usage [-0, +0, -]
1328 lua_pop(L, 1); // Stack usage [-n, +0, -]
1329 if (t >= 1.0) ret = 0;
1330 if (ret == 0) _elua_obj_free(L, (Edje_Lua_Obj *)elt);
1331 _elua_gc(L); // Stack usage [-0, +0, e]
1336 _elua_transition_free(void *obj) // Stack usage [-0, +0, -]
1338 Edje_Lua_Transition *elt = obj;
1340 if (!elt->obj.ed) return;
1342 luaL_unref(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +0, -]
1344 ecore_animator_del(elt->animator);
1345 elt->animator = NULL;
1350 @subsubsection edje_transition edje:transition(div, func)
1352 Just like edje:animator(), except that the callback function gets called with an
1353 argument. The argument is the amount of time since the transition was created,
1354 divided by the div parameter.
1356 @param div A number to divide the time since creation by.
1357 @param func The function to call when the transition triggers.
1359 @returns A userdata that is a transition (ecore animator, plus other info).
1362 _elua_transition(lua_State *L) // Stack usage [-8, +9, emv]
1364 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
1365 Edje_Lua_Transition *elt;
1368 val = luaL_checknumber(L, 1); // Stack usage [-0, +0, v]
1369 luaL_checkany(L, 2); // Stack usage [-0, +0, v]
1371 elt = (Edje_Lua_Transition *)_elua_obj_new(L, ed, sizeof(Edje_Lua_Transition), _elua_ecore_animator_meta);
1372 // Stack usage [-5, +6, m]
1373 elt->obj.free_func = _elua_transition_free;
1374 elt->animator = ecore_animator_add(_elua_transition_cb, elt);
1375 if (val < 0.0000001) val = 0.0000001;
1376 elt->transition = val;
1377 elt->start = ecore_loop_time_get();
1378 lua_pushvalue(L, 2); // Stack usage [-0, +1, -]
1379 elt->fn_ref = luaL_ref(L, LUA_REGISTRYINDEX); // Stack usage [-1, +0, m]
1380 _elua_gc(L); // Stack usage [-0, +0, e]
1387 @subsubsection edje_colour_class edje:color_class(class, r, g, b, a)
1389 Gets, (and optionally sets) the colours for a color class.
1391 Wraps edje_object_color_class_set().
1393 @param class A color class name.
1394 @param r The new red value.
1395 @param g The new green value.
1396 @param b The new blue value.
1397 @param a The new alpha value.
1399 Note that the r, g, b, and a arguments are optional, without them this function
1400 just queries the current values. The r, g, b, and a arguments can be separate
1401 values, or named fields in a table.
1403 @return A table with these fields:
1404 - integer r: The red value.
1405 - integer g: The green value.
1406 - integer b: The blue value.
1407 - integer a: The alpha value.
1412 _elua_color_class(lua_State *L) // Stack usage [-(10|14), +(11|15), ?]
1414 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
1415 Edje_Color_Class *c_class;
1416 const char *class = luaL_checkstring(L, 1); // Stack usage [-0, +0, v]
1419 if (!class) return 0;
1421 if (_elua_scan_params(L, 2, "%r %g %b %a", &r, &g, &b, &a) > 0)
1422 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
1423 _elua_color_fix(&r, &g, &b, &a);
1424 // This is the way that embryo does it -
1425 //edje_object_color_class_set(ed->obj, class, r, g, b, a, r, g, b, a, r, g, b, a);
1426 // But that deals with object scope, which is currently useless in lua,
1427 // since we have no objects that can use color_class yet.
1428 // So we do it at global scope instead.
1429 // LATER - Should do both?
1430 edje_color_class_set(class, r, g, b, a, r, g, b, a, r, g, b, a);
1433 c_class = _edje_color_class_find(ed, class);
1434 if (!c_class) return 0;
1436 _elua_ret(L, "%r %g %b %a", c_class->r, c_class->g, c_class->b, c_class->a);
1437 // Stack usage [-8, +9, em]
1443 @subsubsection edje_text_class edje:text_class(class, font, size)
1445 Gets, (and optionally sets) the details for a text class.
1447 Wraps edje_object_text_class_set().
1449 @param class A text class name.
1450 @param font The new font name.
1451 @param size The new font size.
1453 Note that the font and size arguments are optional, without them this function
1454 just queries the current values. The font and size arguments can be separate
1455 values, or named fields in a table. The font name can refer to a font in the
1456 edje file, or an external font.
1458 @return A table with these fields:
1459 - string font: The font name.
1460 - integer size: The font size.
1465 _elua_text_class(lua_State *L) // Stack usage [-(6|8), +(7|9), emv]
1467 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); // Stack usage [-2, +2, e]
1468 Edje_Text_Class *t_class;
1469 const char *class = luaL_checkstring(L, 1); // Stack usage [-0, +0, v]
1471 Evas_Font_Size size = 0;
1473 if (!class) return 0;
1475 // Just like color_class above, this does things differently from embryo,
1476 // for the same reason.
1477 if (_elua_scan_params(L, 2, "$font %size", &font, &size) > 0)
1478 // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
1479 edje_text_class_set(class, font, size);
1481 t_class = _edje_text_class_find(ed, class);
1482 if (!t_class) return 0;
1484 _elua_ret(L, "$font %size", t_class->font, t_class->size);
1485 // Stack usage [-4, +5, em]
1491 _elua_evas_obj_free(void *obj)
1493 Edje_Lua_Evas_Object *elo = obj;
1495 if (!elo->obj.ed) return;
1496 evas_object_del(elo->evas_obj);
1497 elo->evas_obj = NULL;
1500 // Stack usage [-7, +8, em]
1501 #define _ELUA_PLANT_EVAS_OBJECT(type, meta, free) \
1502 Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); \
1504 elo = (type *)_elua_obj_new(L, ed, sizeof(type), meta); \
1505 elo->obj.free_func = free;
1506 // Stack usage [-2, +2, e]
1507 // Stack usage [-5, +6, m]
1510 _elua_polish_evas_object(Edje *ed, Edje_Lua_Evas_Object *elo)
1512 evas_object_smart_member_add(elo->evas_obj, ed->obj);
1513 evas_object_clip_set(elo->evas_obj, ed->base.clipper);
1514 evas_object_move(elo->evas_obj, ed->x, ed->y);
1515 evas_object_resize(elo->evas_obj, 0, 0);
1516 evas_object_data_set(elo->evas_obj, ELO, elo);
1521 @subsubsection edje_edje edje:edje()
1523 Create an edje object, and add it to the edje.
1525 Wraps edje_object_add().
1527 @returns A userdata that is an edje object.
1532 _elua_edje(lua_State *L) // Stack usage [-7, +8, em]
1534 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_edje_meta, _elua_evas_obj_free)
1535 // Stack usage [-7, +8, em]
1536 elo->evas_obj = edje_object_add(evas_object_evas_get(ed->obj));
1537 _edje_subobj_register(ed, elo->evas_obj);
1538 _elua_polish_evas_object(ed, elo);
1544 @subsubsection edje_image edje:image()
1546 Create an evas image, and add it to the edje.
1548 Wraps evas_object_image_add().
1550 @returns A userdata that is an evas image.
1555 _elua_image(lua_State *L) // Stack usage [-7, +8, em]
1557 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_image_meta, _elua_evas_obj_free)
1558 // Stack usage [-7, +8, em]
1559 elo->evas_obj = evas_object_image_filled_add(evas_object_evas_get(ed->obj));
1560 _elua_polish_evas_object(ed, elo);
1566 @subsubsection edje_line edje:line()
1568 Create an evas line, and add it to the edje.
1570 Wraps evas_object_line_add().
1572 @returns A userdata that is an evas line.
1577 _elua_line(lua_State *L) // Stack usage [-7, +8, em]
1579 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_line_meta, _elua_evas_obj_free)
1580 // Stack usage [-7, +8, em]
1581 elo->evas_obj = evas_object_line_add(evas_object_evas_get(ed->obj));
1582 _elua_polish_evas_object(ed, elo);
1587 _elua_map_free(void *obj)
1589 Edje_Lua_Map *elm = obj;
1590 if (!elm->obj.ed) return;
1591 evas_map_free(elm->map);
1597 @subsubsection edje_map edje:map()
1601 Wraps evas_map_new().
1603 @returns A userdata that is an evas map.
1608 _elua_map(lua_State *L) // Stack usage [-7, +8, emv]
1610 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Map, _elua_evas_map_meta, _elua_map_free)
1611 // Stack usage [-7, +8, em]
1612 elo->map = evas_map_new(luaL_checkinteger(L, 1)); // Stack usage [-0, +0, v]
1618 @subsubsection edje_polygon edje:polygon()
1620 Create an evas polygon, and add it to the edje.
1622 Wraps evas_object_polygon_add().
1624 @returns A userdata that is an evas polygon.
1629 _elua_polygon(lua_State *L) // Stack usage [-7, +8, em]
1631 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_polygon_meta, _elua_evas_obj_free)
1632 // Stack usage [-7, +8, em]
1633 elo->evas_obj = evas_object_polygon_add(evas_object_evas_get(ed->obj));
1634 _elua_polish_evas_object(ed, elo);
1640 @subsubsection edje_rect edje:rect()
1642 Create an evas rectangle, and add it to the edje.
1644 Wraps evas_object_rectangle_add().
1646 @returns A userdata that is an evas rectangle.
1649 _elua_rect(lua_State *L) // Stack usage [-7, +8, em]
1651 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_meta, _elua_evas_obj_free)
1652 // Stack usage [-7, +8, em]
1653 elo->evas_obj = evas_object_rectangle_add(evas_object_evas_get(ed->obj));
1654 _elua_polish_evas_object(ed, elo);
1660 @subsubsection edje_text edje:text()
1662 Create an evas text object, and add it to the edje.
1664 Wraps evas_object_text_add().
1666 @returns A userdata that is an evas text object.
1671 _elua_text(lua_State *L) // Stack usage [-7, +8, em]
1673 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_text_meta, _elua_evas_obj_free)
1674 // Stack usage [-7, +8, em]
1675 elo->evas_obj = evas_object_text_add(evas_object_evas_get(ed->obj));
1676 _elua_polish_evas_object(ed, elo);
1680 /* XXX: disabled until there are enough textblock functions implemented to make it actually useful
1681 _elua_textblock(lua_State *L) // Stack usage [-7, +8, em]
1683 _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_textblock_meta, _elua_evas_obj_free)
1684 // Stack usage [-7, +8, em]
1685 elo->evas_obj = evas_object_textblock_add(evas_object_evas_get(ed->obj));
1686 _elua_polish_evas_object(ed, elo);
1696 @subsection evas Evas class.
1698 The lua evas class includes functions for dealing with evas objects. The evas
1699 objects must have been previously created by lua using one of the lua ezas
1700 object creation functions from the lua edje class.
1702 In the following, "evas_object" is a place holder for any lua variable that
1703 holds a reference to an evas object.
1706 static int _elua_obj_del(lua_State *L);
1708 static int _elua_hide(lua_State *L);
1709 static int _elua_show(lua_State *L);
1710 static int _elua_visible(lua_State *L);
1712 static int _elua_above(lua_State *L);
1713 static int _elua_below(lua_State *L);
1714 static int _elua_bottom(lua_State *L);
1715 static int _elua_lower(lua_State *L);
1716 static int _elua_raise(lua_State *L);
1717 static int _elua_top(lua_State *L);
1719 static int _elua_geom(lua_State *L);
1720 static int _elua_move(lua_State *L);
1721 static int _elua_pos(lua_State *L);
1722 static int _elua_resize(lua_State *L);
1723 static int _elua_size(lua_State *L);
1725 static int _elua_clip(lua_State *L);
1726 static int _elua_clipees(lua_State *L);
1727 static int _elua_unclip(lua_State *L);
1729 static int _elua_type(lua_State *L);
1731 static int _elua_pass(lua_State *L);
1732 static int _elua_precise(lua_State *L);
1733 static int _elua_repeat(lua_State *L);
1735 static int _elua_color(lua_State *L);
1737 static int _elua_obj_map(lua_State *L);
1738 static int _elua_obj_map_enable(lua_State *L);
1740 static const char *_elua_evas_api = "evas";
1741 static const struct luaL_Reg _elua_evas_funcs [] =
1743 {"del", _elua_obj_del}, // generic del any object created for edje (evas objects, timers, animators, transitions... everything)
1745 {"hide", _elua_hide}, // hide, return current visibility
1746 {"show", _elua_show}, // show, return current visibility
1747 {"visible", _elua_visible}, // get object visibility
1749 {"above", _elua_above}, // get object above or stack obj above given obj
1750 {"below", _elua_below}, // get object below or stack obj below given obj
1751 {"bottom", _elua_bottom}, // get bottom
1752 {"lower", _elua_lower}, // lower to bottom
1753 {"raise", _elua_raise}, // raise to top
1754 {"top", _elua_top}, // get top
1756 {"geom", _elua_geom}, // move and resize and return current geometry
1757 {"move", _elua_move}, // move, return current position
1758 {"pos", _elua_pos}, // move, return current position
1759 {"resize", _elua_resize}, // resize, return current size
1760 {"size", _elua_size}, // resize, return current size
1762 {"clip", _elua_clip}, // set clip obj, return clip object
1763 {"clipees", _elua_clipees}, // get clip children
1764 {"unclip", _elua_unclip}, // clear clip obj
1766 {"type", _elua_type}, // get object type
1768 {"pass", _elua_pass}, // set pass events, get pass events
1769 {"precise", _elua_precise}, // set precise inside flag, get precise
1770 {"repeat", _elua_repeat}, // set repeat events, get repeat events
1772 {"color", _elua_color}, // set color, return color
1773 // {"color_class", _elua_object_color_class}, // get or set object color class
1775 // FIXME: set callbacks (mouse down, up, blah blah blah)
1777 // FIXME: set scale (explicit value)
1778 // FIXME: need to set auto-scale (same as scale: 1)
1780 // FIXME: later - set render op, anti-alias, pointer mode (autograb, nograb)
1783 {"map", _elua_obj_map},
1784 {"map_enable", _elua_obj_map_enable},
1792 @subsubsection evas_hide evas_object:hide()
1796 Wraps evas_object_hide().
1798 @returns A boolean representing the current visibility.
1801 _elua_hide(lua_State *L) // Stack usage [-0, +1, -]
1803 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1804 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1805 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1806 evas_object_hide(elo->evas_obj);
1807 lua_pushboolean(L, evas_object_visible_get(elo->evas_obj)); // Stack usage [-0, +1, -]
1813 @subsubsection evas_show evas_object:show()
1817 Wraps evas_object_show().
1819 @returns A boolean representing the current visibility.
1822 _elua_show(lua_State *L) // Stack usage [-0, +1, -]
1824 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1825 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1826 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1827 evas_object_show(elo->evas_obj);
1828 lua_pushboolean(L, evas_object_visible_get(elo->evas_obj)); // Stack usage [-0, +1, -]
1834 @subsubsection evas_visible evas_object:visible(visibility)
1836 Gets (and optionally sets) this objects visibility.
1838 Wraps evas_object_hide() or evas_object_show().
1840 @param visibility The new visibility you want to change it to.
1842 Note that the argument is optional, without it this function just queries the
1845 @returns A boolean representing the current visibility.
1848 _elua_visible(lua_State *L) // Stack usage [-0, +1, -]
1850 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1851 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1853 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1854 n = lua_gettop(L); // Stack usage [-0, +0, -]
1857 if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -]
1859 if (lua_toboolean(L, 2)) evas_object_show(elo->evas_obj);
1860 // Stack usage [-0, +0, -]
1861 else evas_object_hide(elo->evas_obj);
1864 lua_pushboolean(L, evas_object_visible_get(elo->evas_obj)); // Stack usage [-0, +1, -]
1871 @subsubsection evas_above evas_object:above()
1873 Figure out what, if anything, is above us.
1875 Wraps evas_object_above_get().
1877 Note that it may not return any value.
1879 @returns A reference to the object above this one.
1882 _elua_above(lua_State *L) // Stack usage [-3, +4, -]
1884 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1885 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1886 Edje_Lua_Evas_Object *elo2;
1888 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1889 if (!(o = evas_object_above_get(elo->evas_obj))) return 0;
1890 if (!(elo2 = evas_object_data_get(o, ELO))) return 0;
1891 _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
1897 @subsubsection evas_below evas_object:below()
1899 Figure out what, if anything, is below us.
1901 Wraps evas_object_below_get().
1903 Note that it may not return any value.
1905 @returns A reference to the object below this one.
1908 _elua_below(lua_State *L) // Stack usage [-3, +4, -]
1910 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1911 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1912 Edje_Lua_Evas_Object *elo2;
1914 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1915 if (!(o = evas_object_below_get(elo->evas_obj))) return 0;
1916 if (!(elo2 = evas_object_data_get(o, ELO))) return 0;
1917 _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
1923 @subsubsection evas_bottom evas_object:bottom()
1925 Figure out what, if anything, is waaaay below us.
1927 Note that it may not return any value.
1929 @returns A reference to the object at the bottom.
1932 _elua_bottom(lua_State *L) // Stack usage [-(0|3), +(0|4), -]
1934 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1935 Edje_Lua_Evas_Object *elo2;
1937 Eina_List *list, *l;
1938 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1939 if (!(list = (Eina_List *)evas_object_smart_members_get(obj->ed->obj))) return 0;
1940 for (l = list; l; l = l->next)
1943 if ((elo2 = evas_object_data_get(o, ELO)))
1945 _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
1954 @subsubsection evas_lower evas_object:lower()
1956 Lower this object to the bottom.
1958 Wraps evas_object_lower().
1961 _elua_lower(lua_State *L) // Stack usage [-0, +0, -]
1963 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1964 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1965 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1966 evas_object_lower(elo->evas_obj);
1972 @subsubsection evas_raise evas_object:raise()
1974 Raise this object to the top.
1976 Wraps evas_object_raise().
1979 _elua_raise(lua_State *L) // Stack usage [-0, +0, -]
1981 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
1982 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1983 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1984 evas_object_raise(elo->evas_obj);
1990 @subsubsection evas_top evas_object:top()
1992 Figure out what, if anything, is waaaay above us.
1994 Note that it may not return any value.
1996 @returns A reference to the object at the top.
1999 _elua_top(lua_State *L) // Stack usage [-(0|3), +(0|4), -]
2001 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-(0, +0, -]
2002 Edje_Lua_Evas_Object *elo2;
2004 Eina_List *list, *l;
2005 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2006 if (!(list = (Eina_List *)evas_object_smart_members_get(obj->ed->obj))) return 0;
2007 if (!list) return 0;
2008 for (l = eina_list_last(list); l; l = l->prev)
2011 if ((elo2 = evas_object_data_get(o, ELO)))
2013 _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
2023 @subsubsection evas_geom evas_object:geom(x, y, w, h)
2025 Gets (and optionally sets) this objects geometry.
2027 Wraps evas_object_move() and evas_object_resize.
2029 @param x The new X coordinate.
2030 @param y The new Y coordinate.
2031 @param w The new width.
2032 @param h The new height.
2034 Note that the arguments are optional, without them this function just queries
2035 the current values. The arguments can be separate values, or named fields in a
2038 @return A table with these fields:
2039 - integer x: X coordinate.
2040 - integer x: Y coordinate.
2042 - integer w: Height.
2045 _elua_geom(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
2047 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2048 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2049 Evas_Coord ox, oy, ow, oh;
2052 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2053 evas_object_geometry_get(elo->evas_obj, &ox, &oy, &ow, &oh);
2054 if (_elua_scan_params(L, 2, "%x %y %w %h", &x, &y, &w, &h) > 0)
2055 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
2056 if ((x != (ox - obj->ed->x)) || (y != (oy - obj->ed->y)))
2058 evas_object_move(elo->evas_obj,
2062 if ((w != ow) || (h != oh))
2064 evas_object_resize(elo->evas_obj, w, h);
2066 evas_object_geometry_get(elo->evas_obj, &ox, &oy, &ow, &oh);
2067 elo->x = ox - obj->ed->x;
2068 elo->y = oy - obj->ed->y;
2070 _elua_ret(L, "%x %y %w %h", elo->x, elo->y, ow, oh);
2071 // Stack usage [-8, +9, em]
2077 @subsubsection evas_move evas_object:move(x, y)
2079 Gets (and optionally sets) this objects position.
2081 Wraps evas_object_move().
2083 @param x The new X coordinate.
2084 @param y The new Y coordinate.
2086 Note that the arguments are optional, without them this function just queries
2087 the current values. The arguments can be separate values, or named fields in a
2090 @return A table with these fields:
2091 - integer x: X coordinate.
2092 - integer x: Y coordinate.
2095 _elua_move(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2097 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2098 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2102 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2103 evas_object_geometry_get(elo->evas_obj, &ox, &oy, NULL, NULL);
2104 if (_elua_scan_params(L, 2, "%x %y", &x, &y) > 0)
2105 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
2106 if ((x != (ox - obj->ed->x)) || (y != (oy - obj->ed->y)))
2108 evas_object_move(elo->evas_obj,
2111 evas_object_geometry_get(elo->evas_obj, &ox, &oy, NULL, NULL);
2113 elo->x = ox - obj->ed->x;
2114 elo->y = oy - obj->ed->y;
2116 _elua_ret(L, "%x %y", elo->x, elo->y);
2117 // Stack usage [-4, +5, em]
2123 @subsubsection evas_pos evas_object:pos(x, y)
2125 An alias for evas_object:move().
2128 _elua_pos(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2130 return _elua_move(L);
2135 @subsubsection evas_resize evas_object:resize(w, h)
2137 Gets (and optionally sets) this objects size.
2139 Wraps evas_object_resize().
2141 @param w The new width.
2142 @param h The new height.
2144 Note that the arguments are optional, without them this function just queries
2145 the current values. The arguments can be separate values, or named fields in a
2148 @return A table with these fields:
2150 - integer w: Height.
2153 _elua_resize(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2155 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2156 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2160 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2161 evas_object_geometry_get(elo->evas_obj, NULL, NULL, &ow, &oh);
2162 if (_elua_scan_params(L, 2, "%w %h", &w, &h) > 0)
2163 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
2164 if ((w != ow) || (h != oh))
2166 evas_object_resize(elo->evas_obj, w, h);
2167 evas_object_geometry_get(elo->evas_obj, NULL, NULL, &ow, &oh);
2170 _elua_ret(L, "%w %h", ow, oh);
2171 // Stack usage [-4, +5, em]
2177 @subsubsection evas_size evas_object:size()
2179 An alias for evas_object:resize().
2182 _elua_size(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2184 return _elua_resize(L);
2190 @subsubsection evas_clip evas_object:clip(evas_object2)
2192 Get (and optionally set) the object that clips this object.
2194 Note that the argument is optional, without it this function just queries the
2197 Wraps evas_object_clip_set().
2199 @param evas_object2 A reference to the object to clip this object with.
2201 @returns A reference to the object clipping this object, if any.
2204 _elua_clip(lua_State *L) // Stack usage [-3, +4, -]
2206 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2207 Edje_Lua_Evas_Object *elo2, *elo = (Edje_Lua_Evas_Object *)obj;
2210 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2211 n = lua_gettop(L); // Stack usage [-0, +0, -]
2214 Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); // Stack usage [-0, +0, -]
2215 elo2 = (Edje_Lua_Evas_Object *)obj2;
2216 if (!_elua_isa(obj2, _elua_evas_meta)) return 0;
2217 evas_object_clip_set(elo->evas_obj, elo2->evas_obj);
2219 o = evas_object_clip_get(elo->evas_obj);
2221 if (!(elo2 = evas_object_data_get(o, ELO))) return 0;
2222 _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
2228 @subsubsection evas_clipees evas_object:clipees()
2230 Gets the list of objects this objects clips.
2232 Wraps evas_object_clipees_get().
2234 @return A table, that holds all the objects this clips, if any,
2235 otherwise an empty table.
2238 _elua_clipees(lua_State *L) // Stack usage [-0, +1, me] plus [-5, +5] for each clipee.
2240 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2241 Edje_Lua_Evas_Object *elo2, *elo = (Edje_Lua_Evas_Object *)obj;
2242 Eina_List *list, *l;
2245 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2246 list = (Eina_List *)evas_object_clipees_get(elo->evas_obj);
2247 lua_newtable(L); // Stack usage [-0, +1, m]
2248 EINA_LIST_FOREACH(list, l, o)
2250 if (!(elo2 = evas_object_data_get(o, ELO))) continue;
2251 lua_pushinteger(L, n + 1); // Stack usage [-0, +1, -]
2252 _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
2253 lua_settable(L, -3); // Stack usage [-2, +0, e]
2261 @subsubsection evas_unclip evas_object:unclip()
2263 Remove any clipping on this object.
2265 Wraps evas_object_clip_unset().
2268 _elua_unclip(lua_State *L) // Stack usage [-0, +0, -]
2270 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2271 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2272 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2273 evas_object_clip_unset(elo->evas_obj);
2280 @subsubsection evas_type evas_object:type()
2282 Get the type of this object. See the documentation of the evas_object_type_get()
2283 C function for details.
2285 Wraps evas_object_type_get().
2287 @return A string with this objects type in it.
2290 _elua_type(lua_State *L) // Stack usage [-0, +1, m]
2292 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2293 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2295 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2296 t = evas_object_type_get(elo->evas_obj);
2298 lua_pushstring(L, t); // Stack usage [-0, +1, m]
2305 @subsubsection evas_pass evas_object:pass(pass)
2307 Get (and optionally set) whether this object ignores events, passing them to the
2308 next object underneath it.
2310 Wraps evas_object_pass_events_set().
2312 @param pass A boolean saying if this object passes events.
2314 Note that the argument is optional, without it this function just queries the
2317 @return A boolean saying if this object passes events.
2320 _elua_pass(lua_State *L) // Stack usage [-0, +1, -]
2322 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2323 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2325 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2326 n = lua_gettop(L); // Stack usage [-0, +0, -]
2329 if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -]
2331 evas_object_pass_events_set(elo->evas_obj, lua_toboolean(L, 2));
2332 // Stack usage [-0, +0, -]
2335 lua_pushboolean(L, evas_object_pass_events_get(elo->evas_obj));
2336 // Stack usage [-0, +1, -]
2342 @subsubsection evas_precise evas_object:precise(precise)
2344 Get (and optionally set) whether to use precise (usually expensive) point
2345 collision detection for this object.
2347 Wraps evas_object_precise_is_inside_set().
2349 @param precise A boolean saying if this object is precisely detected.
2351 Note that the argument is optional, without it this function just queries the
2354 @return A boolean saying if this object is precisely detected.
2357 _elua_precise(lua_State *L) // Stack usage [-0, +1, -]
2359 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2360 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2362 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2363 n = lua_gettop(L); // Stack usage [-0, +0, -]
2366 if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -]
2368 evas_object_precise_is_inside_set(elo->evas_obj, lua_toboolean(L, 2));
2369 // Stack usage [-0, +0, -]
2372 lua_pushboolean(L, evas_object_precise_is_inside_get(elo->evas_obj));
2373 // Stack usage [-0, +1, -]
2379 @subsubsection evas_repeat evas_object:repeat(repeat)
2381 Get (and optionally set) whether this object repeats events.
2383 Wraps evas_object_repeat_events_set().
2385 @param repeat A boolean saying if this object repeats events to lower objects.
2387 Note that the argument is optional, without it this function just queries the
2390 @return A boolean saying if this object repeats events.
2393 _elua_repeat(lua_State *L) // Stack usage [-0, +1, -]
2395 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2396 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2398 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2399 n = lua_gettop(L); // Stack usage [-0, +0, -]
2402 if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -]
2404 evas_object_repeat_events_set(elo->evas_obj, lua_toboolean(L, 2));
2405 // Stack usage [-0, +0, -]
2408 lua_pushboolean(L, evas_object_repeat_events_get(elo->evas_obj));
2409 // Stack usage [-0, +1, -]
2416 @subsubsection evas_colour evas_object:color(r, g, b, a)
2418 Gets (and optionally sets) this objects colour.
2420 Wraps evas_object_color_set().
2422 @param r The new red value.
2423 @param g The new green value.
2424 @param b The new blue value.
2425 @param a The new alpha value.
2427 Note that the arguments are optional, without them this function just queries
2428 the current values. The arguments can be separate values, or named fields in a
2431 @return A table with these fields:
2432 - integer r: The red value.
2433 - integer g: The green value.
2434 - integer b: The blue value.
2435 - integer a: The alpha value.
2438 _elua_color(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
2440 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2441 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2444 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2445 if (_elua_scan_params(L, 2, "%r %g %b %a", &r, &g, &b, &a) > 0)
2446 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
2447 _elua_color_fix(&r, &g, &b, &a);
2448 evas_object_color_set(elo->evas_obj, r, g, b, a);
2450 evas_object_color_get(elo->evas_obj, &r, &g, &b, &a);
2451 _elua_ret(L, "%r %g %b %a", r, g, b, a);
2452 // Stack usage [-8, +9, em]
2459 @subsubsection evas_map evas_object:map(map)
2461 Attach a map to this object.
2463 Wraps evas_object_map_set().
2465 @param map The map to attach.
2470 _elua_obj_map(lua_State *L) // Stack usage [-0, +0, -]
2472 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2473 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2474 Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); // Stack usage [-0, +0, -]
2475 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj2;
2476 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2477 if (!_elua_isa(obj2, _elua_evas_map_meta)) return 0;
2479 evas_object_map_set(elo->evas_obj, elm->map);
2486 @subsubsection evas_map_enable evas_object:map_enable(enable)
2488 Enable or disable the map attached to this object.
2490 Wraps evas_object_map_enable_set().
2492 @param enable A booleon that controls if the attached map is enabled or not.
2494 @return A boolean reflecting the map enabled status of this object.
2499 _elua_obj_map_enable(lua_State *L) // Stack usage [-0, +1, -]
2501 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2502 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2504 if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2506 n = lua_gettop(L); // Stack usage [-0, +0, -]
2509 evas_object_map_enable_set(elo->evas_obj, lua_toboolean(L, 2));
2510 // Stack usage [-0, +0, -]
2512 lua_pushboolean(L, evas_object_map_enable_get(elo->evas_obj));
2513 // Stack usage [-0, +1, -]
2521 @subsection ecore_animator Ecore animator class.
2523 The lua ecore animator class includes functions for dealing with ecore animator objects.
2524 The ecore animator objects must have been previously created by lua using the lua
2525 edje object creation function edje:animator() or edje:transition().
2527 In the following, "animator_object" is a place holder for any lua variable that
2528 holds a reference to an ecore animator object.
2530 static const char *_elua_ecore_animator_api = "ecore_animator";
2531 static const struct luaL_Reg _elua_ecore_animator_funcs [] =
2540 @subsection ecore_timer Ecore timer class.
2542 The lua ecore timer class includes functions for dealing with ecore timer objects.
2543 The ecore timer objects must have been previously created by lua using the lua
2544 edje object creation function edje:timer().
2546 In the following, "timer_object" is a place holder for any lua variable that
2547 holds a reference to an ecore timer object.
2550 static const char *_elua_ecore_timer_api = "ecore_timer";
2551 static const struct luaL_Reg _elua_ecore_timer_funcs [] =
2560 @subsection evas_edje Evas edje class.
2562 The lua evas edje class includes functions for dealing with evas edje objects.
2563 The evas edje objects must have been previously created by lua using the lua
2564 edje object creation function edje:edje().
2566 In the following, "edje_object" is a place holder for any lua variable that
2567 holds a reference to an evas edje object. NOT the edje class specified earlier
2573 static int _elua_edje_file(lua_State *L);
2575 static const char *_elua_evas_edje_api = "evas_edje";
2576 static const char *_elua_evas_edje_parent = "evas_edje_parent";
2577 static const struct luaL_Reg _elua_evas_edje_funcs [] =
2579 {"file", _elua_edje_file}, // get or set edje file and group
2586 @subsubsection edje_file edje_object:file(file, group)
2588 Load an edje group into this edje object.
2590 Wraps edje_object_file_set().
2592 @param file An edje file name (ignored, sandboxed to the file this lua script is in).
2593 @param group The group within the edje file to be loaded.
2595 Note that the arguments are optional, without them this function just queries
2596 the current values. The arguments can be separate values, or named fields in a
2597 table. The file argument is optional, and ignored anyway.
2599 @return A table with these fields:
2600 - string file: The name of the edje file this edje's group is loaded from.
2601 - string group: The name of the group this edje is loaded from.
2606 _elua_edje_file(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2608 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2609 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2610 const char *file = NULL, *group = NULL;
2611 int n = lua_gettop(L); // Stack usage [-0, +0, -]
2613 if (!_elua_isa(obj, _elua_evas_edje_meta)) return 0;
2615 n = _elua_scan_params(L, 2, "$file $group", &file, &group);
2616 // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
2619 file = (char *) obj->ed->file->path;
2620 group = (char *) lua_tostring(L, 2); // Stack usage [-0, +0, m]
2626 // Sandbox lua - Only allow access to groups within the same file.
2627 // By the simple expedient of completely ignoring what file was requested.
2628 file = (char *) obj->ed->file->path;
2629 if (!edje_object_file_set(elo->evas_obj, file, group))
2631 Edje_Load_Error err = edje_object_load_error_get(elo->evas_obj);
2635 case EDJE_LOAD_ERROR_NONE : LE("Edje file loading errer %s %s - no error happened, but you should not see this.", obj->ed->file->path, group); break;
2636 case EDJE_LOAD_ERROR_GENERIC : LE("Edje file loading errer %s %s - generic error.", obj->ed->file->path, group); break;
2637 case EDJE_LOAD_ERROR_DOES_NOT_EXIST : LE("Edje file loading errer %s %s - file does not exist.", obj->ed->file->path, group); break;
2638 case EDJE_LOAD_ERROR_PERMISSION_DENIED : LE("Edje file loading errer %s %s - permission denied reading the file.", obj->ed->file->path, group); break;
2639 case EDJE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED : LE("Edje file loading errer %s %s - resource allocation failed.", obj->ed->file->path, group); break;
2640 case EDJE_LOAD_ERROR_CORRUPT_FILE : LE("Edje file loading errer %s %s - corrupt file.", obj->ed->file->path, group); break;
2641 case EDJE_LOAD_ERROR_UNKNOWN_FORMAT : LE("Edje file loading errer %s %s - unknown file format.", obj->ed->file->path, group); break;
2642 case EDJE_LOAD_ERROR_INCOMPATIBLE_FILE : LE("Edje file loading errer %s %s - incompatible file.", obj->ed->file->path, group); break;
2643 case EDJE_LOAD_ERROR_UNKNOWN_COLLECTION : LE("Edje file loading errer %s %s - unknown group.", obj->ed->file->path, group); break;
2644 case EDJE_LOAD_ERROR_RECURSIVE_REFERENCE : LE("Edje file loading errer %s %s - recursive reference in group.", obj->ed->file->path, group); break;
2648 edje_object_file_get(elo->evas_obj, &file, &group);
2649 _elua_ret(L, "$file $group", file, group);
2650 // Stack usage [-4, +5, em]
2658 @subsection evas_image Evas image class.
2660 The lua evas image class includes functions for dealing with evas image objects.
2661 The evas image objects must have been previously created by lua using the lua
2662 image object creation function edje:image().
2664 In the following, "image_object" is a place holder for any lua variable that
2665 holds a reference to an evas image object.
2670 static int _elua_image_fill(lua_State *L);
2671 static int _elua_image_filled(lua_State *L);
2672 static int _elua_image_image(lua_State *L);
2674 static const char *_elua_evas_image_api = "evas_image";
2675 static const char *_elua_evas_image_parent = "evas_image_parent";
2676 static const struct luaL_Reg _elua_evas_image_funcs [] =
2678 {"fill", _elua_image_fill}, // get or set the fill parameters
2679 {"filled", _elua_image_filled}, // get or set the filled state (overrides fill())
2680 {"image", _elua_image_image}, // get or set image
2687 @subsubsection image_fill image_object:fill(x, y, w, h)
2689 Gets (and optionally sets) how to fill this image's drawing rectangle given the
2690 (real) image bound to it.
2692 Wraps evas_object_image_fill_set().
2694 @param x The x coordinate (from the top left corner of the bound image) to start drawing from.
2695 @param y The y coordinate (from the top left corner of the bound image) to start drawing from.
2696 @param w The width the bound image will be displayed at.
2697 @param h The height the bound image will be displayed at.
2699 Note that the arguments are optional, without them this function just queries
2700 the current values. The arguments can be separate values, or named fields in a
2703 @return A table with these fields:
2704 - integer x: The x coordinate (from the top left corner of the bound image) to start drawing from.
2705 - integer y: The y coordinate (from the top left corner of the bound image) to start drawing from.
2706 - integer w: The width the bound image will be displayed at.
2707 - integer h: The height the bound image will be displayed at.
2712 _elua_image_fill(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
2714 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2715 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2716 Evas_Coord x, y, w, h;
2718 if (!_elua_isa(obj, _elua_evas_image_meta)) return 0;
2720 if (_elua_scan_params(L, 2, "%x %y %w %h", &x, &y, &w, &h) > 0)
2721 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
2722 evas_object_image_fill_set(elo->evas_obj, x, y, w, h);
2724 evas_object_image_fill_get(elo->evas_obj, &x, &y, &w, &h);
2725 _elua_ret(L, "%x %y %w %h", x, y, w, h);
2726 // Stack usage [-8, +9, em]
2732 @subsubsection image_filled image_object:filled(filled)
2734 Get (and optionally set) whether this image fills the object.
2736 Wraps evas_object_image_filled_set().
2738 @param filled A boolean saying if this image fills the object.
2740 Note that the argument is optional, without it this function just queries the
2743 @return A boolean saying if this image fills the object.
2748 _elua_image_filled(lua_State *L) // Stack usage [-0, +0, -]
2750 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2751 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2754 if (!_elua_isa(obj, _elua_evas_image_meta)) return 0;
2756 n = lua_gettop(L); // Stack usage [-0, +0, -]
2759 evas_object_image_filled_set(elo->evas_obj, lua_toboolean(L, 2));
2760 // Stack usage [-0, +0, -]
2762 lua_pushboolean(L, evas_object_image_filled_get(elo->evas_obj));
2763 // Stack usage [-0, +0, -]
2769 @subsubsection image_image image_object:image(file, key)
2771 Load an image into this edje object.
2773 Wraps evas_object_image_file_set().
2775 @param file An edje file name (ignored, sandboxed to the file this lua script is in).
2776 @param group The name of an image.
2778 Note that the arguments are optional, without them this function just queries
2779 the current values. The arguments can be separate values, or named fields in a
2780 table. The file argument is optional, and ignored anyway.
2782 @return A table with these fields:
2783 - string file: The name of the edje file the image is loaded from.
2784 - string key: The name of the image within the edje file.
2789 _elua_image_image(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2791 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2792 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2793 const char *file = NULL, *key = NULL;
2796 if (!_elua_isa(obj, _elua_evas_image_meta)) return 0;
2798 n = _elua_scan_params(L, 2, "$file $key", &file, &key);
2799 // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
2802 file = (char *) obj->ed->file->path;
2803 key = (char *) lua_tostring(L, 2); // Stack usage [-0, +0, m]
2809 if (obj->ed->file->image_dir)
2811 Edje_Image_Directory_Entry *de;
2816 if ((name = strrchr(key, '/'))) name++;
2817 else name = (char *)key;
2819 /* Loop through image directory to find if image exists */
2820 for (i = 0; i < obj->ed->file->image_dir->entries_count; ++i)
2822 de = obj->ed->file->image_dir->entries + i;
2826 if (strcmp(name, de->entry) == 0)
2831 // This is copied from _edje_image_recalc_apply()), dunno if it provides any benefit over sprintf().
2832 /* Replace snprint("edje/images/%i") == memcpy + itoa */
2833 #define IMAGES "edje/images/"
2834 memcpy(buf, IMAGES, strlen(IMAGES));
2835 eina_convert_itoa(id, buf + strlen(IMAGES)); /* No need to check length as 2³² need only 10 characters. */
2836 evas_object_image_file_set(elo->evas_obj, obj->ed->file->path, buf);
2845 LE("Image %s not found in our edje file.", key);
2846 /* Sandbox lua - Only allow access to images within the same edje file. I'm not so sure we need this level of sandboxing though. So leaving it here, just in case.
2847 LI("Image %s not found in our edje file, trying external image file %s.", key, file);
2848 evas_object_image_file_set(elo->evas_obj, file, key);
2852 evas_object_image_file_get(elo->evas_obj, &file, &key);
2853 _elua_ret(L, "$file $key", file, key);
2854 // Stack usage [-4, +5, em]
2862 @subsection evas_line Evas line class.
2864 The lua evas line class includes functions for dealing with evas line objects.
2865 The evas line objects must have been previously created by lua using the lua
2866 line object creation function edje:line().
2868 In the following, "line_object" is a place holder for any lua variable that
2869 holds a reference to an evas line object.
2874 static int _elua_line_xy(lua_State *L);
2876 static const char *_elua_evas_line_api = "evas_line";
2877 static const char *_elua_evas_line_parent = "evas_line_parent";
2878 static const struct luaL_Reg _elua_evas_line_funcs [] =
2880 {"xy", _elua_line_xy}, // get or set line coords
2887 @subsubsection line_xy line_object:xy(x1, y1, x2, y2)
2889 Sets the end points of this line.
2891 Wraps evas_object_line_xy_set().
2893 @param x1 The X coordinate of the first line end.
2894 @param y1 The Y coordinate of the first line end.
2895 @param x2 The X coordinate of the other line end.
2896 @param y2 The Y coordinate of the other line end.
2898 Note that the arguments are optional, without them this function just queries
2899 the current values. The arguments can be separate values, or named fields in a
2902 @return A table with these fields:
2903 - integer x1: The X coordinate of the first line end.
2904 - integer y1: The Y coordinate of the first line end.
2905 - integer x2: The X coordinate of the other line end.
2906 - integer y2: The Y coordinate of the other line end.
2910 static int _elua_line_xy(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
2912 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2913 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2914 Evas_Coord x1, y1, x2, y2;
2916 if (!_elua_isa(obj, _elua_evas_line_meta)) return 0;
2918 if (_elua_scan_params(L, 2, "%x1 %y1 %x2 %y2", &x1, &y1, &x2, &y2) > 0)
2919 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
2920 evas_object_line_xy_set(elo->evas_obj, x1, y1, x2, y2);
2922 evas_object_line_xy_get(elo->evas_obj, &x1, &y1, &x2, &y2);
2923 _elua_ret(L, "%x1 %y1 %x2 %y2", x1, y1, x2, y2);
2924 // Stack usage [-8, +9, em]
2932 @subsection evas_object_map Evas map class.
2934 The lua evas map class includes functions for dealing with evas map objects.
2935 The evas map objects must have been previously created by lua using the lua
2936 map object creation function edje:map(). The evas map system is complex, rather
2937 than repeat the copious documentation here, please refer to the evas map
2938 documentation. It has pictures and everything. B-)
2940 In the following, "map_object" is a place holder for any lua variable that
2941 holds a reference to an evas map object.
2946 static int _elua_map_alpha(lua_State *L);
2947 static int _elua_map_clockwise(lua_State *L);
2948 static int _elua_map_colour(lua_State *L);
2949 static int _elua_map_coord(lua_State *L);
2950 static int _elua_map_lighting(lua_State *L);
2951 static int _elua_map_perspective(lua_State *L);
2952 static int _elua_map_populate(lua_State *L);
2953 static int _elua_map_rotate(lua_State *L);
2954 static int _elua_map_rotate3d(lua_State *L);
2955 static int _elua_map_smooth(lua_State *L);
2956 static int _elua_map_uv(lua_State *L);
2957 static int _elua_map_zoom(lua_State *L);
2959 static const char *_elua_evas_map_api = "ewas_map";
2960 static const struct luaL_Reg _elua_evas_map_funcs [] =
2962 {"alpha", _elua_map_alpha},
2963 // {"dup", _elua_map_dup}, // not sure of proper api for this.
2964 {"clockwise", _elua_map_clockwise},
2965 {"color", _elua_map_colour},
2966 {"coord", _elua_map_coord},
2967 {"lighting", _elua_map_lighting},
2968 {"perspective", _elua_map_perspective},
2969 {"populate", _elua_map_populate},
2970 {"rotate", _elua_map_rotate},
2971 {"rotate3d", _elua_map_rotate3d},
2972 // {"size", _elua_map_size}, // not sure of proper API for this
2973 {"smooth", _elua_map_smooth},
2974 {"uv", _elua_map_uv},
2975 {"zoom", _elua_map_zoom},
2982 @subsubsection map_alpha map_object:alpha(alpha)
2984 Get (and optionally set) the maps alpha mode.
2986 Wraps evas_map_alpha_set().
2988 @param alpha The alpha mode.
2990 Note that the argument is optional, without it this function just queries the
2993 @return A boolean reflecting the alpha mode.
2998 _elua_map_alpha(lua_State *L) // Stack usage [-0, +1, -]
3000 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3001 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3004 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3006 n = lua_gettop(L); // Stack usage [-0, +0, -]
3009 evas_map_alpha_set(elm->map, lua_toboolean(L, 2));
3010 // Stack usage [-0, +0, -]
3012 lua_pushboolean(L, evas_map_alpha_get(elm->map)); // Stack usage [-0, +1, -]
3018 @subsubsection map_clockwise map_object:clockwise()
3020 Get the maps clockwise state.
3022 Wraps evas_map_util_clockwise_get().
3024 @return A boolean reflecting if the map is clockwise or not.
3029 _elua_map_clockwise(lua_State *L) // Stack usage [-0, +1, -]
3031 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3032 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3034 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3036 lua_pushboolean(L, evas_map_util_clockwise_get(elm->map)); // Stack usage [-0, +1, -]
3042 @subsubsection map_colour map_object:colour(index, r, g, b, a)
3044 Gets or sets colour information for the map. There are two variations, with or
3045 without the index. With the index parameter it gets (and optionally sets) the
3046 colour of the point the index refers to, without it sets the colour for the
3049 Wraps evas_map_point_color_set() or evas_map_util_points_color_set()
3051 @param index Which point to change the colour of.
3052 @param r The new red value.
3053 @param g The new green value.
3054 @param b The new blue value.
3055 @param a The new alpha value.
3057 Note that the arguments are optional, without them this function just queries
3058 the current values. The colour arguments can be separate values, or named
3061 @return A table with these fields:
3062 - integer r: The red value.
3063 - integer g: The green value.
3064 - integer b: The blue value.
3065 - integer a: The alpha value.
3070 _elua_map_colour(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
3072 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3073 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3077 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3078 n = lua_gettop(L); // Stack usage [-0, +0, -]
3084 if (_elua_scan_params(L, 2, "%r %g %b %a", &r, &g, &b, &a) > 0)
3085 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
3086 evas_map_util_points_color_set(elm->map, r, g, b, a);
3094 if (_elua_scan_params(L, 3, "%r %g %b %a", &r, &g, &b, &a) > 0)
3095 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
3096 evas_map_point_color_set(elm->map, lua_tointeger(L, 2), r, g, b, a);
3097 // Stack usage [-0, +0, -]
3099 evas_map_point_color_get(elm->map, lua_tointeger(L, 2), &r, &g, &b, &a);
3100 // Stack usage [-0, +0, -]
3101 _elua_ret(L, "%r %g %b %a", r, g, b, a);
3102 // Stack usage [-8, +9, em]
3112 @subsubsection map_coord map_object:coord(index, x, y, z)
3114 Gets (and optionally sets) the 3D coordinates of a point on the map.
3116 Wraps evas_map_point_coord_set().
3118 @param x The x coordinate of the point.
3119 @param y The y coordinate of the point.
3120 @param z The z coordinate of the point.
3122 Note that the arguments are optional, without them this function just queries
3123 the current values. The coordinate arguments can be separate values, or named
3126 @return A table with these fields:
3127 - integer x: The x coordinate of the point.
3128 - integer y: The y coordinate of the point.
3129 - integer z: The z coordinate of the point.
3134 _elua_map_coord(lua_State *L) // Stack usage [-(6|9), +(7|10), em]
3136 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3137 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3141 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3142 n = lua_gettop(L); // Stack usage [-0, +0, -]
3143 if (2 > n) return 0;
3145 if (_elua_scan_params(L, 2, "%x %y %z", &x, &y, &z) > 0)
3146 { // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3147 evas_map_point_coord_set(elm->map, lua_tointeger(L, 2), x, y, z);
3148 // Stack usage [-0, +0, -]
3150 evas_map_point_coord_get(elm->map, lua_tointeger(L, 2), &x, &y, &z);
3151 // Stack usage [-0, +0, -]
3152 _elua_ret(L, "%x %y %z", x, y, z);
3153 // Stack usage [-6, +7, em]
3159 @subsubsection map_lighting map_object:lighting(x, y, z, r, g, b, ar, ag, ab)
3161 Set the 3D lights for the map. The three triplets can be tables.
3163 Wraps evas_map_util_3d_lighting().
3165 @param x The x coordinate of the light point.
3166 @param y The y coordinate of the light point.
3167 @param z The z coordinate of the light point.
3168 @param r The new red value of the light point.
3169 @param g The new green value of the light point.
3170 @param b The new blue value of the light point.
3171 @param ar The new red value of the ambient light.
3172 @param ag The new green value of the ambient light.
3173 @param ab The new blue value of the ambient light.
3178 _elua_map_lighting(lua_State *L) // Stack usage [-(0|9), +(0|9), e]
3180 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3181 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3183 int r, g, b, r1, g1, b1;
3186 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3188 if ((n = _elua_scan_params(L, 2, "%x %y %z", &x, &y, &z)) > 0)
3189 // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3190 if (n += _elua_scan_params(L, 2 + n, "%r %g %b", &r, &g, &b) > 0)
3191 // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3192 if (_elua_scan_params(L, 2 + n, "%r %g %b", &r1, &g1, &b1) > 0)
3193 { // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3194 evas_map_util_3d_lighting(elm->map, x, y, z, r, g, b, r1, g1, b1);
3201 @subsubsection map_perspective map_object:perspective(x, y, z, f)
3203 Apply a perspective transform to the map.
3205 Wraps evas_map_util_3d_perspective().
3207 The arguments can be separate values, or named fields in a table.
3209 @param x The perspective distance X coordinate
3210 @param y The perspective distance Y coordinate
3211 @param z The "0" z plane value
3212 @param f The focal distance
3217 _elua_map_perspective(lua_State *L) // Stack usage [-(0|4), +(0|4), e]
3219 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3220 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3221 Evas_Coord x, y, z, f;
3223 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3225 if (_elua_scan_params(L, 2, "%x %y %z %f", &x, &y, &z, &f) > 0)
3226 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
3227 evas_map_util_3d_perspective(elm->map, x, y, z, f);
3234 @subsubsection map_populate map_object:populate(...)
3236 Populate the points in a map, in one of three different methods.
3238 1) Wraps evas_map_util_points_populate_from_object().
3240 @param source An evas object to copy points from.
3242 2) Wraps evas_map_util_paints_populate_from_object_full().
3244 @param source An evas object to copy points from.
3245 @param z Common Z coordinate hint for all four points.
3247 3) Wraps evas_map_util_points_populate_from_geometry().
3249 The first four arguments can be separate values, or named fields in a table.
3251 @param x Point X coordinate
3252 @param y Point Y coordinate
3253 @param w Width to use to calculate second and third points.
3254 @param h Height to use to calculate third and fourth points.
3255 @param z Common Z coordinate hint for all four points.
3260 _elua_map_populate(lua_State *L) // Stack usage [-(0|4), +(0|4), e]
3262 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3263 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3266 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3267 n = lua_gettop(L); // Stack usage [-0, +0, -]
3273 Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); // Stack usage [-0, +0, -]
3274 const Edje_Lua_Evas_Object *source = (Edje_Lua_Evas_Object *)obj2;
3276 if (!_elua_isa(obj2, _elua_evas_meta)) return 0;
3277 evas_map_util_points_populate_from_object(elm->map, source->evas_obj);
3283 Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); // Stack usage [-0, +0, -]
3284 const Edje_Lua_Evas_Object *source = (Edje_Lua_Evas_Object *)obj2;
3285 Evas_Coord z = lua_tointeger(L, 3);
3287 if (!_elua_isa(obj2, _elua_evas_meta)) return 0;
3288 evas_map_util_points_populate_from_object_full(elm->map, source->evas_obj, z);
3294 Evas_Coord x, y, w, h;
3296 if ((n = _elua_scan_params(L, 2, "%x %y %w %h", &x, &y, &w, &h)) > 0)
3297 { // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
3298 evas_map_util_points_populate_from_geometry(elm->map, x, y, w, h, lua_tointeger(L, 2 + n));
3308 @subsubsection map_rotate map_object:rotate(degrees, x, y)
3310 Rotate the maps coordinates in 2D.
3312 Wraps evas_map_util_rotate().
3314 The coordinates can be separate values, or named fields in a table.
3316 @param degrees Amount of degrees from 0.0 to 360.0 to rotate.
3317 @param x Rotation's centre horizontal position.
3318 @param y Rotation's centre vertical position.
3323 _elua_map_rotate(lua_State *L) // Stack usage [-(0|2), +(0|2), e]
3325 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3326 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3331 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3332 n = lua_gettop(L); // Stack usage [-0, +0, -]
3333 if (4 != n) return 0;
3335 degrees = lua_tonumber(L, 2);
3336 if (_elua_scan_params(L, 3, "%x %y", &x, &y) > 0)
3337 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3338 evas_map_util_rotate(elm->map, degrees, x, y);
3345 @subsubsection map_rotate3d map_object:rotate3d(dx, dy, dz, x, y, z)
3347 Rotate the maps coordinates in 3D.
3349 Wraps evas_map_util_3d_rotate().
3351 The coordinates can be separate values, or named fields in a table. The same
3354 @param dx Amount of degrees from 0.0 to 360.0 to rotate around X axis.
3355 @param dy Amount of degrees from 0.0 to 360.0 to rotate around Y axis.
3356 @param dz Amount of degrees from 0.0 to 360.0 to rotate around Z axis.
3357 @param x Rotation's centre horizontal position.
3358 @param y Rotation's centre vertical position.
3359 @param z Rotation's centre vertical position.
3364 _elua_map_rotate3d(lua_State *L) // Stack usage [-(0|6), +(0|6), e]
3366 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3367 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3372 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3374 if ((n = _elua_scan_params(L, 2, "#x #y #z", &zx, &zy, &zz)) > 0)
3375 // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3376 if (_elua_scan_params(L, 2 + n, "%x %y %z", &x, &y, &z) > 0)
3377 { // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3378 evas_map_util_3d_rotate(elm->map, zx, zy, zz, x, y, z);
3385 @subsubsection map_smooth map_object:smooth(smooth)
3387 Get (and optionally set) the maps smooth mode.
3389 Wraps evas_map_smooth_set().
3391 @param smooth The smooth mode.
3393 Note that the argument is optional, without it this function just queries the
3396 @return A boolean reflecting the smooth mode.
3401 _elua_map_smooth(lua_State *L) // Stack usage [-0, +1, -]
3403 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3404 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3407 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3409 n = lua_gettop(L); // Stack usage [-0, +0, -]
3412 evas_map_smooth_set(elm->map, lua_toboolean(L, 2));
3413 // Stack usage [-0, +0, -]
3415 lua_pushboolean(L, evas_map_smooth_get(elm->map)); // Stack usage [-0, +1, -]
3421 @subsubsection map_uv map_object:uv(index, u, v)
3423 Gets (and optionally sets) the texture U and V texture coordinates for this map.
3425 Wraps evas_map_point_image_uv_set().
3427 @param index Index of the point to change. Must be smaller than map size.
3428 @param u The X coordinate within the image/texture source.
3429 @param v The Y coordinate within the image/texture source.
3431 Note that the U,V arguments are optional, without them this function just queries
3432 the current values. The coordinate arguments can be separate values, or named
3435 @return A table with these fields:
3436 - number u: The X coordinate within the image/texture source.
3437 - number v: The Y coordinate within the image/texture source.
3442 _elua_map_uv(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
3444 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3445 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3449 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3450 n = lua_gettop(L); // Stack usage [-0, +0, -]
3451 if (2 > n) return 0;
3453 if (_elua_scan_params(L, 3, "#u #v", &u, &v) > 0)
3454 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3455 evas_map_point_image_uv_set(elm->map, lua_tonumber(L, 2), u, v);
3456 // Stack usage [-0, +0, -]
3458 evas_map_point_image_uv_get(elm->map, lua_tonumber(L, 2), &u, &v);
3459 // Stack usage [-0, +0, -]
3460 _elua_ret(L, "#u #v", u, v);
3461 // Stack usage [-4, +5, em]
3467 @subsubsection map_zoom map_object:zoom(x, y, x, y)
3469 Apply a zoom to the map.
3471 Wraps evas_map_util_zoom().
3473 The arguments can be two separate values, or named fields in a table.
3475 @param x The horizontal zoom amount.
3476 @param y The vertical zoom amount.
3477 @param x The X coordinate of the centre of the zoom.
3478 @param y The Y coordinate of the centre of the zoom.
3483 _elua_map_zoom(lua_State *L) // Stack usage [-(0|4), +(0|4), e]
3485 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3486 Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3491 if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3493 if ((n = _elua_scan_params(L, 2, "#x #y", &zx, &zy)) > 0)
3494 // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3495 if (_elua_scan_params(L, 2 + n, "%x %y", &x, &y) > 0)
3496 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3497 evas_map_util_zoom(elm->map, zx, zy, x, y);
3506 @subsection evas_polygon Evas polygon class.
3508 The lua evas polygon class includes functions for dealing with evas polygon objects.
3509 The evas polygon objects must have been previously created by lua using the lua
3510 polygon object creation function edje:polygon().
3512 In the following, "polygon_object" is a place holder for any lua variable that
3513 holds a reference to an evas polygon object.
3518 static int _elua_polygon_clear(lua_State *L);
3519 static int _elua_polygon_point(lua_State *L);
3521 static const char *_elua_evas_polygon_api = "evas_polygon";
3522 static const char *_elua_evas_polygon_parent = "evas_polygon_parent";
3523 static const struct luaL_Reg _elua_evas_polygon_funcs [] =
3525 {"clear", _elua_polygon_clear}, // clear all polygon points
3526 {"point", _elua_polygon_point}, // add a polygon point
3533 @subsubsection polygon_clear polygon_object:clear()
3535 Clears all points from the polygon.
3537 Wraps evas_object_polygon_points_clear(),
3542 _elua_polygon_clear(lua_State *L) // Stack usage [-0, +0, -]
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;
3547 if (!_elua_isa(obj, _elua_evas_polygon_meta)) return 0;
3548 evas_object_polygon_points_clear(elo->evas_obj);
3554 @subsubsection polygon_point polygon_object:point(x, y)
3556 Adds a point to this polygon.
3558 Wraps evas_object_polygon_point_add().
3560 @param x The X coordinate of the point.
3561 @param y The Y coordinate of the point.
3566 _elua_polygon_point(lua_State *L) // Stack usage [-(0|2), +(0|2), e]
3568 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3569 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
3572 if (!_elua_isa(obj, _elua_evas_polygon_meta)) return 0;
3574 if (_elua_scan_params(L, 2, "%x %y", &x, &y) > 0)
3575 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3576 evas_object_polygon_point_add(elo->evas_obj, x, y);
3586 @subsection evas_text Evas text class.
3588 The lua evas text class includes functions for dealing with evas text objects.
3589 The evas text objects must have been previously created by lua using the lua
3590 text object creation function edje:text().
3592 In the following, "text_object" is a place holder for any lua variable that
3593 holds a reference to an evas text object.
3598 static int _elua_text_font(lua_State *L);
3599 static int _elua_text_text(lua_State *L);
3601 static const char *_elua_evas_text_api = "evas_text";
3602 static const char *_elua_evas_text_parent = "evas_text_parent";
3603 static const struct luaL_Reg _elua_evas_text_funcs [] =
3605 {"font", _elua_text_font}, // get or set text font
3606 {"text", _elua_text_text}, // get or set text
3607 // {"text_class", _elua_object_text_class}, // get or set object text class
3614 @subsubsection text_font text_object:font(font, size)
3616 Gets, (and optionally sets) the font for this text object.
3618 Wraps evas_object_text_font_set().
3620 @param font The new font name.
3621 @param size The new font size.
3623 Note that the font and size arguments are optional, without them this function
3624 just queries the current values. The font and size arguments can be separate
3625 values, or named fields in a table. The font name can refer to a font in the
3626 edje file, or an external font.
3628 @return A table with these fields:
3629 - string font: The font name.
3630 - integer size: The font size.
3635 _elua_text_font(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
3637 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3638 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
3639 char *font, *font2 = NULL;
3640 Evas_Font_Size size;
3641 int inlined_font = 0;
3643 if (!_elua_isa(obj, _elua_evas_text_meta)) return 0;
3645 if (_elua_scan_params(L, 2, "$font %size", &font, &size) > 0)
3646 { // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3647 /* Check if the font is embedded in the .edj
3648 * This is a simple check.
3649 * There is a much more complicated version in edje_text.c _edje_text_recalc_apply().
3650 * If we need to get more complicated, we can do that later,
3651 * and maybe refactor things.
3653 if (obj->ed->file->fonts)
3655 Edje_Font_Directory_Entry *fnt = eina_hash_find(obj->ed->file->fonts, font);
3659 size_t len = strlen(font) + sizeof("edje/fonts/") + 1;
3660 font2 = alloca(len);
3661 sprintf(font2, "edje/fonts/%s", font);
3668 if (inlined_font) evas_object_text_font_source_set(elo->evas_obj, obj->ed->path);
3669 else evas_object_text_font_source_set(elo->evas_obj, NULL);
3671 evas_object_text_font_set(elo->evas_obj, font, size);
3674 // When one external API says it's gotta be const, and another one says not, then one of them's gotta be cast. :-P
3675 evas_object_text_font_get(elo->evas_obj, (const char **) &font, &size);
3676 _elua_ret(L, "$font %size", font, size);
3677 // Stack usage [-4, +5, em]
3683 @subsubsection text_text text_object:text(text)
3685 Get (and optionally set) the actual text for this text object.
3687 Wraps evas_object_text_text_set().
3689 @param text The text to set for this text object.
3691 Note that the argument is optional, without it this function just queries the
3694 @return A string of the text on this text object.
3699 _elua_text_text(lua_State *L) // Stack usage [-0, +1, m]
3701 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
3702 Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
3705 if (!_elua_isa(obj, _elua_evas_text_meta)) return 0;
3706 n = lua_gettop(L); // Stack usage [-0, +0, -]
3709 if (lua_isstring(L, 2))
3713 if ((str = lua_tostring(L, 2))) // Extra parenthesis, coz Mikes compiler has a lisp.
3714 // Stack usage [-0, +0, m]
3715 evas_object_text_text_set(elo->evas_obj, str);
3718 lua_pushstring(L, evas_object_text_text_get(elo->evas_obj)); // Stack usage [-0, +1, m]
3723 //--------------------------------------------------------------------------//
3725 // A metatable and functions so that calling non existant API does not crash Lua scripts.
3727 static int _elua_bogan_nilfunc(lua_State *L);
3728 static int _elua_bogan_index(lua_State *L);
3730 static const struct luaL_Reg _elua_bogan_funcs [] =
3732 {"nilfunc", _elua_bogan_nilfunc}, // Just return a nil.
3733 {"__index", _elua_bogan_index}, // Return the above func.
3739 _elua_bogan_nilfunc(lua_State *L)
3741 lua_getglobal(L, "nil");
3746 _elua_bogan_index(lua_State *L)
3750 key = lua_tostring(L, 2);
3751 LE("%s does not exist!", key);
3752 lua_pushcfunction(L, _elua_bogan_nilfunc);
3757 _elua_bogan_protect(lua_State *L) // Stack usage [-3, +3, m]
3759 lua_pushnil(L); // Stack usage [-0, +1, -]
3760 luaL_newmetatable(L, "bogan"); // Stack usage [-0, +1, m]
3761 #if LUA_VERSION_NUM >= 502
3762 luaL_setfuncs(L, _elua_bogan_funcs, 0); // Stack usage [-0, +0, e]
3764 luaL_register(L, 0, _elua_bogan_funcs); // Stack usage [-1, +1, m]
3766 lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
3767 lua_pop(L, 1); // Stack usage [-1, +0, -]
3770 //--------------------------------------------------------------------------//
3772 // TODO - All the register / setfuncs and rlelated stuff around here should be reviewed. Works fine for 5.1, probably works fine for 5.2, but maybe there's a better way? It may also need to change if we start using LuaJIT.
3774 // Brain dead inheritance thingy, built for speed. Kinda. Part 1.
3776 _elua_add_functions(lua_State *L, const char *api, const luaL_Reg *funcs, const char *meta, const char *parent, const char *base) // Stack usage [-3, +5, m] if inheriting [-6, +11, em]
3778 // Create an api table, fill it full of the methods.
3779 #if LUA_VERSION_NUM >= 502
3780 lua_newtable(L); // Stack usage [-0, +1, e]
3781 lua_pushvalue(L, -1); // Stack usage [-0, +1, -]
3782 lua_setglobal(L, api); // Stack usage [-1, +0, e]
3783 luaL_setfuncs(L, funcs, 0); // Stack usage [-0, +0, e]
3785 luaL_register(L, api, funcs); // Stack usage [-0, +1, m]
3787 // Set the api metatable to the bogan metatable.
3788 luaL_getmetatable(L, "bogan"); // Stack usage [-0, +1, -]
3789 lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
3790 // Creat a meta metatable.
3791 luaL_newmetatable(L, meta); // Stack usage [-0, +1, m]
3792 // Put the gc functions in the metatable.
3793 #if LUA_VERSION_NUM >= 502
3794 luaL_setfuncs(L, _elua_edje_gc_funcs, 0); // Stack usage [-0, +0, e]
3796 luaL_register(L, 0, _elua_edje_gc_funcs); // Stack usage [-1, +1, m]
3798 // Create an __index entry in the metatable, make it point to the api table.
3799 lua_pushliteral(L, "__index"); // Stack usage [-0, +1, m]
3800 lua_pushvalue(L, -3); // Stack usage [-0, +1, -]
3801 lua_rawset(L, -3); // Stack usage [-2, +0, m]
3802 // Later this metatable is used as the metatable for newly created objects of this class.
3806 // Inherit from base
3807 lua_getglobal(L, base); // Stack usage [-0, +1, e]
3808 // Create a new parent metatable.
3809 luaL_newmetatable(L, parent); // Stack usage [-0, +1, m]
3810 // Create an __index entry in the metatable, make it point to the base table.
3811 lua_pushliteral(L, "__index"); // Stack usage [-0, +1, m]
3812 lua_pushvalue(L, -3); // Stack usage [-0, +1, -]
3813 lua_rawset(L, -3); // Stack usage [-2, +0, m]
3814 // Set the metatable for the api table to the parent metatable.
3815 lua_getglobal(L, api); // Stack usage [-0, +1, e]
3816 luaL_getmetatable(L, parent); // Stack usage [-0, +1, -]
3817 lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
3821 // Brain dead inheritance thingy, built for speed. Kinda. Part 2.
3823 _elua_isa(Edje_Lua_Obj *obj, const char *type)
3825 Eina_Bool isa = EINA_FALSE;
3827 if (!obj) return isa;
3828 if (obj->meta == type)
3830 if (_elua_evas_meta == type)
3832 if (obj->meta == _elua_evas_image_meta)
3834 else if (obj->meta == _elua_evas_text_meta)
3836 else if (obj->meta == _elua_evas_edje_meta)
3838 else if (obj->meta == _elua_evas_line_meta)
3840 else if (obj->meta == _elua_evas_polygon_meta)
3846 #ifndef RASTER_FORGOT_WHY
3848 _elua_init(void) // Stack usage [-16, +20, em]
3850 static Edje_Lua_Alloc ela = { MAX_LUA_MEM, 0 };
3856 lstate = L = lua_newstate(_elua_alloc, &ela); // Stack usage [-0, +0, -]
3857 lua_atpanic(L, _elua_custom_panic); // Stack usage [-0, +0, -]
3859 // FIXME: figure out optimal gc settings later
3860 // lua_gc(L, LUA_GCSETPAUSE, 200); // Stack usage [-0, +0, e]
3861 // lua_gc(L, LUA_GCSETSTEPMUL, 200); // Stack usage [-0, +0, e]
3863 for (l = _elua_libs; l->func; l++) // Currently * 4
3865 #if LUA_VERSION_NUM >= 502
3866 luaL_requiref(L, l->name, l->func, 1); // Stack usage [-0, +1, e]
3868 lua_pushcfunction(L, l->func); // Stack usage [-0, +1, m]
3869 lua_pushstring(L, l->name); // Stack usage [-0, +1, m]
3870 lua_call(L, 1, 0); // Stack usage [-2, +0, e]
3874 #if LUA_VERSION_NUM >= 502
3875 lua_newtable(L); // Stack usage [-0, +1, e]
3876 lua_pushvalue(L, -1); // Stack usage [-0, +1, -]
3877 lua_setglobal(L, _elua_edje_api); // Stack usage [-1, +0, e]
3878 luaL_setfuncs(L, _elua_edje_funcs, 0); // Stack usage [-0, +0, e]
3880 luaL_register(L, _elua_edje_api, _elua_edje_funcs); // Stack usage [-0, +1, m]
3882 luaL_newmetatable(L, _elua_edje_meta); // Stack usage [-0, +1, m]
3883 #if LUA_VERSION_NUM >= 502
3884 luaL_setfuncs(L, _elua_edje_gc_funcs, 0); // Stack usage [-0, +0, e]
3886 luaL_register(L, 0, _elua_edje_gc_funcs); // Stack usage [-1, +1, m]
3889 _elua_add_functions(L, _elua_evas_api, _elua_evas_funcs, _elua_evas_meta, NULL, NULL); // Stack usage [-3, +5, m]
3891 // weak table for our objects
3892 lua_pushlightuserdata(L, &_elua_objs); // Stack usage [-0, +1, -]
3893 lua_newtable(L); // Stack usage [-0, +1, m]
3894 lua_pushstring(L, "__mode"); // Stack usage [-0, +1, m]
3895 lua_pushstring(L, "kv"); // Stack usage [-0, +1, m]
3896 lua_rawset(L, -3); // Stack usage [-2, +0, m]
3897 lua_rawset(L, LUA_REGISTRYINDEX); // Stack usage [-2, +0, m]
3902 _edje_lua2_script_init(Edje *ed) // Stack usage [-63, +99, em]
3904 static Edje_Lua_Alloc ela = { MAX_LUA_MEM, 0 };
3912 if (0 > _log_domain)
3913 _log_domain = eina_log_domain_register("lua", NULL);
3914 if (0 <= _log_domain)
3917 eina_log_domain_level_set("lua", EINA_LOG_LEVEL_WARN);
3920 #ifndef RASTER_FORGOT_WHY
3921 _elua_init(); // This is actually truly pointless, even if raster remembers.
3923 L = ed->L = lua_newstate(_elua_alloc, &ela); // Stack usage [-0, +0, -]
3924 lua_atpanic(L, _elua_custom_panic); // Stack usage [-0, +0, -]
3926 // FIXME: figure out optimal gc settings later
3927 // lua_gc(L, LUA_GCSETPAUSE, 200); // Stack usage [-0, +0, e]
3928 // lua_gc(L, LUA_GCSETSTEPMUL, 200); // Stack usage [-0, +0, e]
3930 for (l = _elua_libs; l->func; l++) // Currently * 4
3932 #if LUA_VERSION_NUM >= 502
3933 luaL_requiref(L, l->name, l->func, 1); // Stack usage [-0, +1, e]
3935 lua_pushcfunction(L, l->func); // Stack usage [-0, +1, m]
3936 lua_pushstring(L, l->name); // Stack usage [-0, +1, m]
3937 lua_call(L, 1, 0); // Stack usage [-2, +0, m]
3941 _elua_bogan_protect(L); // Stack usage [+3, -3, m]
3943 #if LUA_VERSION_NUM >= 502
3944 lua_newtable(L); // Stack usage [-0, +1, e]
3945 lua_pushvalue(L, -1); // Stack usage [-0, +1, -]
3946 lua_setglobal(L, _elua_edje_api); // Stack usage [-1, +0, e]
3947 luaL_setfuncs(L, _elua_edje_funcs, 0); // Stack usage [-0, +0, e]
3949 luaL_register(L, _elua_edje_api, _elua_edje_funcs); // Stack usage [-0, +1, m]
3951 luaL_getmetatable(L, "bogan"); // Stack usage [-0, +1, -]
3952 lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
3953 luaL_newmetatable(L, _elua_edje_meta); // Stack usage [-0, +1, m]
3954 #if LUA_VERSION_NUM >= 502
3955 luaL_setfuncs(L, _elua_edje_gc_funcs, 0); // Stack usage [-0, +0, e]
3957 luaL_register(L, 0, _elua_edje_gc_funcs); // Stack usage [-1, +1, m]
3960 lua_pop(L, 2); // Stack usage [-n, +0, -]
3962 _elua_add_functions(L, _elua_evas_api, _elua_evas_funcs, _elua_evas_meta, NULL, NULL);
3963 // Stack usage [-3, +5, m]
3964 _elua_add_functions(L, _elua_ecore_timer_api, _elua_ecore_timer_funcs, _elua_ecore_timer_meta, NULL, NULL);
3965 // Stack usage [-3, +5, m]
3966 _elua_add_functions(L, _elua_ecore_animator_api, _elua_ecore_animator_funcs, _elua_ecore_animator_meta, NULL, NULL);
3967 // Stack usage [-6, +11, m]
3968 _elua_add_functions(L, _elua_evas_edje_api, _elua_evas_edje_funcs, _elua_evas_edje_meta, _elua_evas_edje_parent, _elua_evas_api);
3969 // Stack usage [-6, +11, em]
3970 _elua_add_functions(L, _elua_evas_image_api, _elua_evas_image_funcs, _elua_evas_image_meta, _elua_evas_image_parent, _elua_evas_api);
3971 // Stack usage [-6, +11, em]
3972 _elua_add_functions(L, _elua_evas_line_api, _elua_evas_line_funcs, _elua_evas_line_meta, _elua_evas_line_parent, _elua_evas_api);
3973 // Stack usage [-6, +11, em]
3974 _elua_add_functions(L, _elua_evas_map_api, _elua_evas_map_funcs, _elua_evas_map_meta, NULL, NULL);
3975 // Stack usage [-3, +5, m]
3976 _elua_add_functions(L, _elua_evas_polygon_api, _elua_evas_polygon_funcs, _elua_evas_polygon_meta, _elua_evas_polygon_parent, _elua_evas_api);
3977 // Stack usage [-6, +11, em]
3978 _elua_add_functions(L, _elua_evas_text_api, _elua_evas_text_funcs, _elua_evas_text_meta, _elua_evas_text_parent, _elua_evas_api);
3979 // Stack usage [-6, +11, em]
3981 // weak table for our objects
3982 lua_pushlightuserdata(L, &_elua_objs); // Stack usage [-0, +1, -]
3983 lua_newtable(L); // Stack usage [-0, +1, m]
3984 lua_pushstring(L, "__mode"); // Stack usage [-0, +1, m]
3985 lua_pushstring(L, "kv"); // Stack usage [-0, +1, m]
3986 lua_rawset(L, -3); // Stack usage [-2, +0, m]
3987 lua_rawset(L, LUA_REGISTRYINDEX); // Stack usage [-2, +0, m]
3989 _elua_table_ptr_set(L, _elua_key, ed); // Stack usage [-2, +2, e]
3991 snprintf(buf, sizeof(buf), "edje/scripts/lua/%i", ed->collection->id);
3992 data = eet_read(ed->file->ef, buf, &size);
3998 /* This ends up pushing a function onto the stack for the lua_pcall() below to use.
3999 * The function is the compiled code. */
4000 err = luaL_loadbuffer(L, data, size, "edje_lua_script"); // Stack usage [-0, +1, m]
4003 if (err == LUA_ERRSYNTAX)
4004 ERR("Lua load syntax error: %s",
4005 lua_tostring(L, -1)); // Stack usage [-0, +0, m]
4006 else if (err == LUA_ERRMEM)
4007 ERR("Lua load memory allocation error: %s",
4008 lua_tostring(L, -1)); // Stack usage [-0, +0, m]
4011 /* This is not needed, pcalls don't longjmp(), that's why they are protected.
4012 if (setjmp(panic_jmp) == 1)
4014 ERR("Lua script init panic");
4018 if ((err = lua_pcall(L, 0, 0, 0))) // Stack usage [-1, +0, -]
4019 _edje_lua2_error(L, err); // Stack usage [-0, +0, m]
4024 _edje_lua2_script_shutdown(Edje *ed)
4027 lua_close(ed->L); // Stack usage irrelevant, as it's all gone now.
4029 while (ed->lua_objs)
4031 Edje_Lua_Obj *obj = (Edje_Lua_Obj *)ed->lua_objs;
4034 ERR("uncollected Lua object %p", obj);
4035 ed->lua_objs = eina_inlist_remove(ed->lua_objs, ed->lua_objs);
4039 ERR("dangling Lua object %p", obj);
4040 ed->lua_objs = eina_inlist_remove(ed->lua_objs, ed->lua_objs);
4044 if (0 <= _log_domain)
4047 if (0 >= _log_count)
4049 eina_log_domain_unregister(_log_domain);
4056 _edje_lua2_script_load(Edje_Part_Collection *edc __UNUSED__, void *data __UNUSED__, int size __UNUSED__) // Stack usage [-16, +20, em]
4058 #ifndef RASTER_FORGOT_WHY
4059 _elua_init(); // Stack usage [-16, +20, em]
4064 _edje_lua2_script_unload(Edje_Part_Collection *edc __UNUSED__) // Stack usage [-0, +0, e]
4066 #ifndef RASTER_FORGOT_WHY
4069 if (!lstate) return;
4071 lua_gc(L, LUA_GCCOLLECT, 0); // Stack usage [-0, +0, e]
4076 _edje_lua2_error_full(const char *file, const char *fnc, int line,
4077 lua_State *L, int err_code) // Stack usage [-0, +0, m]
4079 const char *err_type;
4084 err_type = "runtime";
4087 err_type = "syntax";
4090 err_type = "memory allocation";
4093 err_type = "error handler";
4096 err_type = "unknown";
4100 (_edje_default_log_dom, EINA_LOG_LEVEL_ERR, file, fnc, line,
4101 "Lua %s error: %s", err_type, lua_tostring(L, -1)); // Stack usage [-0, +0, m]
4106 @section callbacks Lua callbacks
4108 These are lua functions that are called by the lua edje system when certain
4109 events occur. If the functions don't exist in the lua group, they don't get
4116 @subsection edje_shutdown Edje shutdown() callback.
4118 If a function called "shutdown" exists in a lua edje group, then it is called when
4119 that edje gets deleted.
4122 _edje_lua2_script_func_shutdown(Edje *ed) // Stack usage [-1, +1, em]
4126 lua_getglobal(ed->L, "shutdown"); // Stack usage [-0, +1, e]
4127 if (!lua_isnil(ed->L, -1)) // Stack usage [-0, +0, -]
4129 if ((err = lua_pcall(ed->L, 0, 0, 0))) // Stack usage [-1, +0, -]
4130 _edje_lua2_error(ed->L, err); // Stack usage [-0, +0, m]
4133 lua_pop(ed->L, 1); // Stack usage [-n, +0, -]
4134 _edje_lua2_script_shutdown(ed);
4139 @subsection edje_show Edje show() callback.
4141 If a function called "show" exists in a lua edje group, then it is called when
4142 that edje gets shown.
4145 _edje_lua2_script_func_show(Edje *ed) // Stack usage [-1, +1, e]
4149 lua_getglobal(ed->L, "show");
4150 if (!lua_isnil(ed->L, -1))
4152 if ((err = lua_pcall(ed->L, 0, 0, 0)))
4153 _edje_lua2_error(ed->L, err);
4161 @subsection edje_hide Edje hide() callback.
4163 If a function called "hide" exists in a lua edje group, then it is called when
4164 that edje gets hidden.
4167 _edje_lua2_script_func_hide(Edje *ed) // Stack usage [-1, +1, e]
4171 lua_getglobal(ed->L, "hide");
4172 if (!lua_isnil(ed->L, -1))
4174 if ((err = lua_pcall(ed->L, 0, 0, 0)))
4175 _edje_lua2_error(ed->L, err);
4183 @subsection edje_move Edje move(x, y) callback.
4185 If a function called "move" exists in a lua edje group, then it is called when
4186 that edje gets moved, with the new position passed to it.
4189 _edje_lua2_script_func_move(Edje *ed) // Stack usage [-3, +3, e] or [-1, +1, e] if no matching function.
4193 // FIXME: move all objects created by script
4194 lua_getglobal(ed->L, "move"); // Stack usage [-0, +1, e]
4195 if (!lua_isnil(ed->L, -1)) // Stack usage [-0, +0, -]
4197 lua_pushinteger(ed->L, ed->x); // Stack usage [-0, +1, -]
4198 lua_pushinteger(ed->L, ed->y); // Stack usage [-0, +1, -]
4199 if ((err = lua_pcall(ed->L, 2, 0, 0))) // Stack usage [-3, +0, -]
4200 _edje_lua2_error(ed->L, err);
4203 lua_pop(ed->L, 1); // Stack usage [-n, +0, -]
4208 @subsection edje_resize Edje resize(w, h) callback.
4210 If a function called "resize" exists in a lua edje group, then it is called when
4211 that edje gets resized, with the new size passed to it.
4214 _edje_lua2_script_func_resize(Edje *ed) // Stack usage [-3, +3, e] or [-1, +1, e] if no matching function.
4218 lua_getglobal(ed->L, "resize");
4219 if (!lua_isnil(ed->L, -1))
4221 lua_pushinteger(ed->L, ed->w);
4222 lua_pushinteger(ed->L, ed->h);
4223 if ((err = lua_pcall(ed->L, 2, 0, 0)))
4224 _edje_lua2_error(ed->L, err);
4232 @subsection edje_message Edje message(id, type, ...) callback.
4234 If a function called "message" exists in a lua edje group, then it is called when
4235 that edje gets gets a message sent to it, with the message details passed to it.
4236 See edje:messagesend() for details of what each type means. The arrays are
4240 _edje_lua2_script_func_message(Edje *ed, Edje_Message *em) // Stack usage [-?, +?, em] It's complicated, but it's even at least.
4244 lua_getglobal(ed->L, "message"); // Stack usage [-0, +1, e]
4245 if (!lua_isnil(ed->L, -1)) // Stack usage [-0, +0, -]
4248 lua_pushinteger(ed->L, em->id); // Stack usage [-0, +1, -]
4251 case EDJE_MESSAGE_NONE:
4252 lua_pushstring(ed->L, "none"); // Stack usage [-0, +1, m]
4254 case EDJE_MESSAGE_SIGNAL:
4256 case EDJE_MESSAGE_STRING:
4257 lua_pushstring(ed->L, "str"); // Stack usage [-0, +1, m]
4258 lua_pushstring(ed->L, ((Edje_Message_String *)em->msg)->str);
4259 // Stack usage [-0, +1, m]
4262 case EDJE_MESSAGE_INT:
4263 lua_pushstring(ed->L, "int"); // Stack usage [-0, +1, m]
4264 lua_pushinteger(ed->L, ((Edje_Message_Int *)em->msg)->val);
4265 // Stack usage [-0, +1, -]
4268 case EDJE_MESSAGE_FLOAT:
4269 lua_pushstring(ed->L, "float"); // Stack usage [-0, +1, m]
4270 lua_pushnumber(ed->L, ((Edje_Message_Float *)em->msg)->val);
4271 // Stack usage [-0, +1, -]
4274 case EDJE_MESSAGE_STRING_SET:
4275 lua_pushstring(ed->L, "strset"); // Stack usage [-0, +1, m]
4276 c = ((Edje_Message_String_Set *)em->msg)->count;
4277 lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4278 for (i = 0; i < c; i++)
4280 lua_pushstring(ed->L, ((Edje_Message_String_Set *)em->msg)->str[i]);
4281 // Stack usage [-0, +1, m]
4282 // It's OK to bypass the metatable in these cases,
4283 // we create the table, and know there is no metatable. B-)
4284 lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4288 case EDJE_MESSAGE_INT_SET:
4289 lua_pushstring(ed->L, "intset"); // Stack usage [-0, +1, m]
4290 c = ((Edje_Message_Int_Set *)em->msg)->count;
4291 lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4292 for (i = 0; i < c; i++)
4294 lua_pushinteger(ed->L, ((Edje_Message_Int_Set *)em->msg)->val[i]);
4295 // Stack usage [-0, +1, -]
4296 lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4300 case EDJE_MESSAGE_FLOAT_SET:
4301 lua_pushstring(ed->L, "floatset"); // Stack usage [-0, +1, m]
4302 c = ((Edje_Message_Float_Set *)em->msg)->count;
4303 lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4304 for (i = 0; i < c; i++)
4306 lua_pushnumber(ed->L, ((Edje_Message_Float_Set *)em->msg)->val[i]);
4307 // Stack usage [-0, +1, -]
4308 lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4312 case EDJE_MESSAGE_STRING_INT:
4313 lua_pushstring(ed->L, "strint"); // Stack usage [-0, +1, m]
4314 lua_pushstring(ed->L, ((Edje_Message_String_Int *)em->msg)->str);
4315 // Stack usage [-0, +1, m]
4316 lua_pushinteger(ed->L, ((Edje_Message_String_Int *)em->msg)->val);
4317 // Stack usage [-0, +1, -]
4320 case EDJE_MESSAGE_STRING_FLOAT:
4321 lua_pushstring(ed->L, "strfloat"); // Stack usage [-0, +1, m]
4322 lua_pushstring(ed->L, ((Edje_Message_String_Float *)em->msg)->str);
4323 // Stack usage [-0, +1, m]
4324 lua_pushnumber(ed->L, ((Edje_Message_String_Float *)em->msg)->val);
4325 // Stack usage [-0, +1, -]
4328 case EDJE_MESSAGE_STRING_INT_SET:
4329 lua_pushstring(ed->L, "strintset"); // Stack usage [-0, +1, m]
4330 lua_pushstring(ed->L, ((Edje_Message_String_Int_Set *)em->msg)->str);
4331 // Stack usage [-0, +1, m]
4332 c = ((Edje_Message_String_Int_Set *)em->msg)->count;
4333 lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4334 for (i = 0; i < c; i++)
4336 lua_pushinteger(ed->L, ((Edje_Message_String_Int_Set *)em->msg)->val[i]);
4337 // Stack usage [-0, +1, -]
4338 lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4342 case EDJE_MESSAGE_STRING_FLOAT_SET:
4343 lua_pushstring(ed->L, "strfloatset"); // Stack usage [-0, +1, m]
4344 lua_pushstring(ed->L, ((Edje_Message_String_Float_Set *)em->msg)->str);
4345 // Stack usage [-0, +1, m]
4346 c = ((Edje_Message_String_Float_Set *)em->msg)->count;
4347 lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4348 for (i = 0; i < c; i++)
4350 lua_pushnumber(ed->L, ((Edje_Message_String_Float_Set *)em->msg)->val[i]);
4351 // Stack usage [-0, +1, -]
4352 lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4359 if ((err = lua_pcall(ed->L, n, 0, 0))) // Stack usage [-n+1, +0, -]
4360 _edje_lua2_error(ed->L, err);
4363 lua_pop(ed->L, 1); // Stack usage [-n, +0, -]
4368 @subsection edje_signal Edje signal(signal, source) callback.
4370 If a function called "signal" exists in a lua edje group, then it is called when
4371 ever a signal arrives, with the signal details passed to it.
4375 _edje_lua2_script_func_signal(Edje *ed, const char *sig, const char *src) // Stack usage [-3, +3, em] or [-1, +1, e] if no matching function.
4379 lua_getglobal(ed->L, "signal");
4380 if (!lua_isnil(ed->L, -1))
4382 lua_pushstring(ed->L, sig);
4383 lua_pushstring(ed->L, src);
4384 if ((err = lua_pcall(ed->L, 2, 0, 0)))
4385 _edje_lua2_error(ed->L, err);