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