aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/edje/src/lib/edje_lua.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/edje/src/lib/edje_lua.c')
-rw-r--r--libraries/edje/src/lib/edje_lua.c5150
1 files changed, 5150 insertions, 0 deletions
diff --git a/libraries/edje/src/lib/edje_lua.c b/libraries/edje/src/lib/edje_lua.c
new file mode 100644
index 0000000..d431d75
--- /dev/null
+++ b/libraries/edje/src/lib/edje_lua.c
@@ -0,0 +1,5150 @@
1#include "edje_private.h"
2
3#if 0
4/////////////////////////////////////////////////////////////////////////////
5// the below is deprecated and here for reference only until removed. look
6// at edje_lua2.c for the active workign code
7/////////////////////////////////////////////////////////////////////////////
8
9#include <lauxlib.h>
10#include <lualib.h>
11
12#define EDJE_LUA_GET 1
13#define EDJE_LUA_SET 2
14#define EDJE_LUA_FN 3
15
16typedef struct _Edje_Lua_Alloc Edje_Lua_Alloc;
17
18typedef struct _Edje_Lua_Ref Edje_Lua_Ref;
19
20typedef struct _Edje_Lua_Reg Edje_Lua_Reg;
21
22typedef struct _Edje_Lua_Timer Edje_Lua_Timer;
23
24typedef struct _Edje_Lua_Animator Edje_Lua_Animator;
25
26typedef struct _Edje_Lua_Poller Edje_Lua_Poller;
27
28typedef struct _Edje_Lua_Transform Edje_Lua_Transform;
29
30typedef struct _Edje_Lua_Transition Edje_Lua_Transition;
31
32typedef struct _Edje_Lua_Evas_Object Edje_Lua_Evas_Object;
33
34typedef struct _Edje_Lua_Edje_Part_Object Edje_Lua_Edje_Part_Object;
35
36typedef struct _Edje_Lua_Edje_Part_Description Edje_Lua_Edje_Part_Description;
37
38struct _Edje_Lua_Alloc
39{
40 size_t max, cur; /* maximal and current memory used by Lua */
41};
42
43struct _Edje_Lua_Ref
44{
45 int id;
46 lua_State *L;
47};
48
49struct _Edje_Lua_Reg
50{
51 const luaL_Reg *mt, *get, *set, *fn;
52};
53
54struct _Edje_Lua_Timer
55{
56 lua_State *L;
57 Ecore_Timer *et;
58 Edje_Lua_Ref *cb;
59};
60
61struct _Edje_Lua_Animator
62{
63 lua_State *L;
64 Ecore_Animator *ea;
65 Edje_Lua_Ref *cb;
66};
67
68struct _Edje_Lua_Poller
69{
70 lua_State *L;
71 Ecore_Poller *ep;
72 Edje_Lua_Ref *cb;
73};
74
75struct _Edje_Lua_Transform
76{
77 lua_State *L;
78 Evas_Transform et;
79};
80
81struct _Edje_Lua_Transition
82{
83 lua_State *L;
84 Ecore_Timer *et;
85 Edje_Lua_Ref *trans;
86 Edje_Lua_Ref *cb;
87 Edje_Lua_Ref *ref;
88 double dur;
89};
90
91struct _Edje_Lua_Evas_Object
92{
93 lua_State *L;
94 Edje *ed;
95 Evas_Object *eo;
96 Eina_Bool mouse_events;
97 Eina_List *cb;
98};
99
100struct _Edje_Lua_Edje_Part_Object
101{
102 lua_State *L;
103 Edje *ed;
104 Evas_Object *eo;
105 Edje_Real_Part *rp;
106 const char *key;
107};
108
109struct _Edje_Lua_Edje_Part_Description
110{
111 lua_State *L;
112 Edje *ed;
113 Evas_Object *eo;
114 Edje_Real_Part *rp;
115 Edje_Part_Description *pd;
116};
117
118jmp_buf _edje_lua_panic_jmp;
119
120static int
121_edje_lua_custom_panic(__UNUSED__ lua_State *L)
122{
123 CRITICAL("PANIC");
124 longjmp(_edje_lua_panic_jmp, 1);
125 return 1; /* longjmp() never returns, but this keep gcc happy */
126}
127
128void
129__edje_lua_error(const char *file, const char *fnc, int line, lua_State *L, int err_code)
130{
131 char *err_type;
132
133 switch (err_code)
134 {
135 case LUA_ERRRUN:
136 err_type = "runtime";
137 break;
138 case LUA_ERRSYNTAX:
139 err_type = "syntax";
140 break;
141 case LUA_ERRMEM:
142 err_type = "memory allocation";
143 break;
144 case LUA_ERRERR:
145 err_type = "error handler";
146 break;
147 default:
148 err_type = "unknown";
149 break;
150 }
151 eina_log_print
152 (_edje_default_log_dom, EINA_LOG_LEVEL_ERR, file, fnc, line,
153 "Lua %s error: %s", err_type, lua_tostring(L, -1));
154 // don't exit. this is BAD. lua script bugs will cause thngs like e to
155 // exit mysteriously ending your x session. bad!
156 // exit(-1);
157}
158
159lua_State *
160_edje_lua_new_thread(Edje *ed, lua_State *L)
161{
162#if 1 // newlua
163 lua_newtable(L);
164 ed->lua_ref = luaL_ref(L, LUA_REGISTRYINDEX);
165 /* inherit new environment from global environment */
166 lua_createtable(L, 1, 0);
167 lua_pushvalue(L, LUA_GLOBALSINDEX);
168 lua_setfield(L, -2, "__index");
169 lua_setmetatable(L, -2);
170 lua_setfenv(L, -2);
171 return L;
172#else
173 /* create new thread */
174 lua_State *thread = lua_newthread(L);
175 //printf ("new thread %d->%d\n", L, thread);
176 /* create new environment for new thread */
177 lua_newtable(L);
178 /* inherit new environment from global environment */
179 lua_createtable(L, 1, 0);
180 lua_pushvalue(L, LUA_GLOBALSINDEX);
181 lua_setfield(L, -2, "__index");
182 lua_setmetatable(L, -2);
183 lua_setfenv(L, -2);
184 return thread;
185#endif
186}
187
188void
189_edje_lua_free_thread(Edje *ed, lua_State *L)
190{
191#if 1 // newlua
192 luaL_unref(L, LUA_REGISTRYINDEX, ed->lua_ref);
193 lua_gc(L, LUA_GCCOLLECT, 0);
194#else
195 lua_pushthread(L);
196 lua_getfenv(L, -1);
197 lua_pushnil(L);
198 while (lua_next(L, -2))
199 {
200 // key at -2, value at -1
201 lua_pop(L, 1);
202 lua_pushvalue(L, -1);
203 lua_pushnil(L);
204 lua_rawset(L, -4);
205 }
206 lua_settop(L, 0);
207 lua_gc(L, LUA_GCCOLLECT, 0);
208#endif
209}
210
211/*
212 * only for debug, returns number of objects in registry
213 */
214static int
215_edje_lua_reg_count (lua_State *L)
216{
217 int count = 0;
218 lua_pushvalue(L, LUA_REGISTRYINDEX);
219 lua_pushnil(L);
220 while (lua_next(L, -2))
221 {
222 // key at -2, value at -1
223 lua_pop(L, 1);
224 count++;
225 }
226 lua_pop(L, 1);
227 return count;
228}
229
230static Edje_Lua_Ref *
231_edje_lua_new_ref(lua_State *L, int index)
232{
233 lua_pushvalue(L, index);
234 Edje_Lua_Ref *ref = malloc(sizeof(Edje_Lua_Ref));
235 ref->id = luaL_ref(L, LUA_REGISTRYINDEX);
236 ref->L = L;
237 return ref;
238}
239
240static void
241_edje_lua_get_ref(lua_State *L, Edje_Lua_Ref *ref)
242{
243 lua_rawgeti(L, LUA_REGISTRYINDEX, ref->id);
244}
245
246static void
247_edje_lua_free_ref(lua_State *L, Edje_Lua_Ref *ref)
248{
249 //printf ("_edje_lua_free_ref %d %d %d\n", L, lua_objlen(L, LUA_REGISTRYINDEX), _edje_lua_reg_count(L));
250 luaL_unref(L, LUA_REGISTRYINDEX, ref->id);
251 free(ref);
252 lua_gc(L, LUA_GCCOLLECT, 0);
253}
254
255void
256_edje_lua_new_reg(lua_State *L, int index, void *ptr)
257{
258 //printf ("_edje_lua_new_reg %d %d %d\n", L, ptr, _edje_lua_reg_count(L));
259 lua_pushvalue(L, index);
260 lua_pushlightuserdata(L, ptr);
261 lua_insert(L, -2);
262 lua_rawset(L, LUA_REGISTRYINDEX); /* freed in _edje_lua_free_reg */
263}
264
265void
266_edje_lua_get_reg(lua_State *L, void *ptr)
267{
268 //printf ("_edje_lua_get_reg %d %d\n", L, ptr);
269 lua_pushlightuserdata(L, ptr);
270 lua_rawget(L, LUA_REGISTRYINDEX);
271}
272
273void
274_edje_lua_free_reg(lua_State *L, void *ptr)
275{
276 //printf ("_edje_lua_free_reg %d %d %d\n", L, ptr, _edje_lua_reg_count(L));
277 lua_pushlightuserdata(L, ptr);
278 lua_pushnil(L);
279 lua_rawset(L, LUA_REGISTRYINDEX); /* created in _edje_lua_new_reg */
280 lua_gc(L, LUA_GCCOLLECT, 0);
281}
282
283static void
284_edje_lua_rawsetfield(lua_State *L, int index, const char *key)
285{
286 lua_pushstring(L, key);
287 lua_insert(L, -2);
288 if (index < 0)
289 lua_rawset(L, index - 1);
290 else
291 lua_rawset(L, index);
292}
293
294static void
295_edje_lua_rawgetfield(lua_State *L, int index, const char *key)
296{
297 lua_pushstring(L, key);
298 if (index < 0)
299 lua_rawget(L, index - 1);
300 else
301 lua_rawget(L, index);
302}
303
304static void
305_edje_lua_new_const(lua_State *L, const char *id, int val)
306{
307 lua_pushnumber(L, val);
308 lua_setglobal(L, id);
309}
310
311static void
312_edje_lua_new_metatable(lua_State *L, const Edje_Lua_Reg ** class)
313{
314 lua_newtable(L);
315 lua_pushlightuserdata(L, class);
316 lua_pushvalue(L, -2);
317 lua_rawset(L, LUA_REGISTRYINDEX); /* freed in _edje_lua_free_metatable */
318 lua_pushvalue(L, -1);
319 lua_pushlightuserdata(L, class);
320 lua_rawset(L, LUA_REGISTRYINDEX); /* freed in _edje_lua_free_metatable */
321}
322
323static void
324_edje_lua_get_metatable(lua_State *L, const Edje_Lua_Reg ** class)
325{
326 lua_pushlightuserdata(L, class);
327 lua_rawget(L, LUA_REGISTRYINDEX);
328}
329
330static void
331_edje_lua_free_metatable(lua_State *L, const Edje_Lua_Reg ** class)
332{
333 lua_pushlightuserdata(L, class);
334 lua_rawget(L, LUA_REGISTRYINDEX);
335 lua_pushnil(L);
336 lua_rawset(L, LUA_REGISTRYINDEX); /* created in _edje_lua_new_metatable */
337 lua_pushlightuserdata(L, class);
338 lua_pushnil(L);
339 lua_rawset(L, LUA_REGISTRYINDEX); /* created in _edje_lua_new_metatable */
340 lua_gc(L, LUA_GCCOLLECT, 0);
341}
342
343static void *
344_edje_lua_checkudata(lua_State *L, int pos, const Edje_Lua_Reg * module)
345{
346 luaL_checktype(L, pos, LUA_TUSERDATA);
347 lua_getmetatable(L, pos);
348 lua_rawget(L, LUA_REGISTRYINDEX);
349 Edje_Lua_Reg **class = lua_touserdata(L, -1);
350 lua_pop(L, 1); // class
351 int flag = 0;
352 int ptr = 0;
353 while (class[ptr] && !flag)
354 if (class[ptr++] == module)
355 flag = 1;
356 if (!flag)
357 {
358 lua_pushstring(L, "class type mismatch");
359 lua_error(L);
360 }
361 return lua_touserdata(L, pos);
362}
363
364static void
365_edje_lua_new_class(lua_State *L, const Edje_Lua_Reg ** class)
366{
367 int n = 0;
368 _edje_lua_new_metatable(L, class);
369 while (class && (class[n] != NULL))
370 {
371 luaL_register(L, NULL, class[n]->mt);
372 lua_pushstring(L, "hands off, it's none of your business!");
373 _edje_lua_rawsetfield(L, -2, "__metatable");
374
375 if (n == 0)
376 {
377 lua_newtable(L);
378 luaL_register(L, NULL, class[n]->set);
379 lua_rawseti (L, -2, EDJE_LUA_SET);
380
381 lua_newtable(L);
382 luaL_register(L, NULL, class[n]->get);
383 lua_rawseti (L, -2, EDJE_LUA_GET);
384
385 lua_newtable(L);
386 luaL_register(L, NULL, class[n]->fn);
387 lua_rawseti (L, -2, EDJE_LUA_FN);
388 }
389 else
390 {
391 lua_rawgeti(L, -1, EDJE_LUA_SET);
392 luaL_register(L, NULL, class[n]->set);
393 lua_pop(L, 1);
394
395 lua_rawgeti(L, -1, EDJE_LUA_GET);
396 luaL_register(L, NULL, class[n]->get);
397 lua_pop(L, 1);
398
399 lua_rawgeti(L, -1, EDJE_LUA_FN);
400 luaL_register(L, NULL, class[n]->fn);
401 lua_pop(L, 1);
402 }
403 n += 1;
404 }
405}
406
407static void
408_edje_lua_set_class(lua_State *L, int index, const Edje_Lua_Reg ** class)
409{
410 lua_newtable(L);
411 if (index < 0)
412 lua_setfenv(L, index - 1);
413 else
414 lua_setfenv(L, index);
415
416 _edje_lua_get_metatable(L, class);
417 if (index < 0)
418 lua_setmetatable(L, index - 1);
419 else
420 lua_setmetatable(L, index);
421}
422
423static int
424_edje_lua_look_fn(lua_State *L)
425{
426 lua_rawgeti(L, -1, EDJE_LUA_FN);
427 lua_pushvalue(L, 2); // key
428 lua_rawget(L, -2); // .fn[key]
429 if (lua_iscfunction(L, -1))
430 return 1;
431 else
432 {
433 lua_pop(L, 2); // .fn[key], .fn
434 return 0;
435 }
436}
437
438static int
439_edje_lua_look_get(lua_State *L)
440{
441 lua_rawgeti(L, -1, EDJE_LUA_GET);
442 lua_pushvalue(L, 2); // key
443 lua_rawget(L, -2); // .get[key]
444 if (lua_iscfunction(L, -1))
445 {
446 int err_code;
447
448 lua_pushvalue(L, 1);
449
450 if ((err_code = lua_pcall(L, 1, 1, 0)))
451 _edje_lua_error(L, err_code);
452 return 1;
453 }
454 else
455 {
456 lua_pop(L, 2); // .get[key], .get
457 return 0;
458 }
459}
460
461static int
462_edje_lua_look_set(lua_State *L)
463{
464 lua_rawgeti(L, -1, EDJE_LUA_SET);
465 lua_pushvalue(L, 2); // key
466 lua_rawget(L, -2); // .set[key]
467 if (lua_iscfunction(L, -1))
468 {
469 int err_code;
470
471 lua_pushvalue(L, 1); // obj
472 lua_pushvalue(L, 3); // value
473
474 if ((err_code = lua_pcall(L, 2, 0, 0))) // .set[key](obj,key,value)
475 _edje_lua_error(L, err_code);
476 return 1;
477 }
478 else
479 {
480 lua_pop(L, 2); // .set[key], .set
481 return 0;
482 }
483}
484
485/*
486 * Lua Class bindings
487 */
488
489const luaL_Reg lNil[] = {
490 {NULL, NULL} // sentinel
491};
492
493const luaL_Reg lClass_mt[];
494
495const luaL_Reg lClass_fn[];
496
497const Edje_Lua_Reg mClass = {
498 lClass_mt,
499 lNil,
500 lNil,
501 lClass_fn
502};
503
504static int
505_edje_lua_class_mt_index(lua_State *L)
506{
507 _edje_lua_checkudata(L, 1, &mClass);
508 lua_getmetatable(L, 1);
509 if (!_edje_lua_look_fn(L)) // look in lClass_fn
510 if (!_edje_lua_look_get(L)) // look in lClass_get
511 { // look in obj ref hash
512 lua_getfenv(L, 1);
513 lua_pushvalue(L, 2); // key
514 lua_rawget(L, -2);
515 }
516 return 1;
517}
518
519static int
520_edje_lua_class_mt_newindex(lua_State *L)
521{
522 _edje_lua_checkudata(L, 1, &mClass);
523 lua_getmetatable(L, 1);
524 if (!_edje_lua_look_set(L)) // look in lClass_set
525 { // look in obj ref hash
526 lua_getfenv(L, 1);
527 lua_pushvalue(L, 2);
528 lua_pushvalue(L, 3);
529 lua_rawset(L, -3);
530 }
531 return 0;
532}
533
534static int
535_edje_lua_class_mt_gc(lua_State *L)
536{
537 _edje_lua_checkudata(L, 1, &mClass);
538 //printf("_edje_lua_class_mt_gc\n");
539 /* FIXME has to be commented to not raise an error, solve differently
540 lua_getfield(L, 1, "del");
541 if (!lua_isnil(L, -1))
542 {
543 lua_pushvalue(L, 1);
544 int err_code;
545
546 if (err_code = lua_pcall(L, 1, 0, 0))
547 _edje_lua_error(L, err_code);
548 }
549 lua_pop(L, 1);
550 */
551 return 0;
552}
553
554static int
555_edje_lua_class_fn_set(lua_State *L)
556{
557 _edje_lua_checkudata(L, 1, &mClass);
558 /*
559 * for k,v in pairs(table) do
560 * obj[k] = v
561 * end
562 */
563 lua_pushnil(L);
564 while (lua_next(L, 2))
565 {
566 // key at -2, value at -1
567 lua_pushvalue(L, -2);
568 lua_insert(L, -2);
569 lua_settable(L, 1);
570 }
571 return 0;
572}
573
574static int
575_edje_lua_class_fn_get(lua_State *L)
576{
577 _edje_lua_checkudata(L, 1, &mClass);
578 /*
579 * res = {}
580 * mtG = getmetatable(obj)['.get']
581 * for k,v in pairs(mtG) do
582 * res[k] = obj[k]
583 * end
584 */
585 lua_newtable(L); // res
586 lua_getmetatable(L, 1); // mt
587 lua_getfield(L, -1, ".get");
588 lua_remove(L, -2); // mt
589
590 lua_pushnil(L);
591 while (lua_next(L, -2))
592 {
593 // key at -2, value at -1
594 lua_pop(L, 1); // value = cfunction
595 lua_pushvalue(L, -1); // key
596 lua_pushvalue(L, -1); // key
597 lua_gettable(L, 1); // obj[key]
598 lua_settable(L, 2); // res[key]
599 }
600 lua_pop(L, 1); // .get
601 return 1;
602}
603
604static int
605_edje_lua_class_itr_call(lua_State *L, int id)
606{
607 int err_code;
608
609 _edje_lua_checkudata(L, 1, &mClass);
610 lua_getmetatable(L, 1); // mt
611 lua_rawgeti(L, -1, id);
612 lua_remove(L, -2); // mt
613 lua_getglobal(L, "pairs");
614 lua_insert(L, -2);
615
616 if ((err_code = lua_pcall(L, 1, 3, 0)))
617 _edje_lua_error(L, err_code);
618 return 3;
619}
620
621static int
622_edje_lua_class_fn_gpairs(lua_State *L)
623{
624 _edje_lua_checkudata(L, 1, &mClass);
625 return _edje_lua_class_itr_call(L, EDJE_LUA_GET);
626}
627
628static int
629_edje_lua_class_fn_spairs(lua_State *L)
630{
631 _edje_lua_checkudata(L, 1, &mClass);
632 return _edje_lua_class_itr_call(L, EDJE_LUA_SET);
633}
634
635static int
636_edje_lua_class_fn_fpairs(lua_State *L)
637{
638 _edje_lua_checkudata(L, 1, &mClass);
639 return _edje_lua_class_itr_call(L, EDJE_LUA_FN);
640}
641
642static int
643_edje_lua_class_fn_pairs(lua_State *L)
644{
645 int err_code;
646
647 _edje_lua_checkudata(L, 1, &mClass);
648 lua_getfenv(L, 1);
649 lua_getglobal(L, "pairs");
650 lua_insert(L, -2);
651
652 if ((err_code = lua_pcall(L, 1, 3, 0)))
653 _edje_lua_error(L, err_code);
654 return 3;
655}
656
657static int
658_edje_lua_class_fn_ipairs(lua_State *L)
659{
660 int err_code;
661
662 _edje_lua_checkudata(L, 1, &mClass);
663 lua_getfenv(L, 1);
664 lua_getglobal(L, "ipairs");
665 lua_insert(L, -2);
666
667 if ((err_code = lua_pcall(L, 1, 3, 0)))
668 _edje_lua_error(L, err_code);
669 return 3;
670}
671
672const luaL_Reg lClass_mt[] = {
673 {"__index", _edje_lua_class_mt_index},
674 {"__newindex", _edje_lua_class_mt_newindex},
675 {"__gc", _edje_lua_class_mt_gc},
676 {NULL, NULL} // sentinel
677};
678
679const luaL_Reg lClass_fn[] = {
680 {"get", _edje_lua_class_fn_get},
681 {"set", _edje_lua_class_fn_set},
682 {"gpairs", _edje_lua_class_fn_gpairs},
683 {"spairs", _edje_lua_class_fn_spairs},
684 {"fpairs", _edje_lua_class_fn_fpairs},
685 {"pairs", _edje_lua_class_fn_pairs},
686 {"ipairs", _edje_lua_class_fn_ipairs},
687 {NULL, NULL} // sentinel
688};
689
690
691const luaL_Reg lTimer_get[];
692
693const luaL_Reg lTimer_set[];
694
695const luaL_Reg lTimer_fn[];
696
697const Edje_Lua_Reg mTimer = {
698 lNil,
699 lTimer_get,
700 lTimer_set,
701 lTimer_fn
702};
703
704const Edje_Lua_Reg *cTimer[] = {
705 &mClass,
706 &mTimer,
707 NULL // sentinel
708};
709
710static Eina_Bool
711_edje_lua_timer_cb(void *data)
712{
713 Edje_Lua_Timer *obj = data;
714 lua_State *L = obj->L;
715 int err_code;
716 Eina_Bool res;
717
718 _edje_lua_get_ref(L, obj->cb); // callback function
719 _edje_lua_get_reg(L, obj);
720
721 if ((err_code = lua_pcall(L, 1, 1, 0)))
722 {
723 _edje_lua_error(L, err_code);
724 return ECORE_CALLBACK_CANCEL;
725 }
726
727 res = luaL_optint(L, -1, ECORE_CALLBACK_CANCEL);
728 lua_pop(L, 1); // -- res
729
730/*
731 if (_edje_lua_panic_here())
732 printf("blahc\n");
733 else
734 lua_pop(L, 1); // -- res
735 */
736 if (res == ECORE_CALLBACK_CANCEL)
737 {
738 // delete object
739 _edje_lua_get_reg(L, obj);
740 lua_pushvalue(L, -1);
741 lua_pushstring(L, "del");
742 lua_gettable(L, -2);
743 lua_insert(L, -2);
744 if ((err_code = lua_pcall(L, 1, 0, 0)))
745 _edje_lua_error(L, err_code);
746 }
747 return res;
748}
749
750static int
751_edje_lua_timer_get_pending(lua_State *L)
752{
753 Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer);
754 if (obj->et)
755 lua_pushnumber(L, ecore_timer_pending_get(obj->et));
756 else
757 lua_pushnil(L);
758 return 1;
759}
760
761static int
762_edje_lua_timer_get_precision(lua_State *L)
763{
764 Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer);
765
766 if (obj->et)
767 lua_pushnumber(L, ecore_timer_precision_get());
768 else
769 lua_pushnil(L);
770
771 return 1;
772}
773
774static int
775_edje_lua_timer_get_interval(lua_State *L)
776{
777 Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer);
778
779 if (obj->et)
780 lua_pushnumber(L, ecore_timer_interval_get(obj->et));
781 else
782 lua_pushnil(L);
783
784 return 1;
785}
786
787const luaL_Reg lTimer_get[] = {
788 {"pending", _edje_lua_timer_get_pending},
789 {"precision", _edje_lua_timer_get_precision},
790 {"interval", _edje_lua_timer_get_interval},
791 {NULL, NULL} // sentinel
792};
793
794static int
795_edje_lua_timer_set_interval(lua_State *L)
796{
797 Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer);
798 if (obj->et)
799 ecore_timer_interval_set(obj->et, luaL_checknumber(L, 2));
800 return 0;
801}
802
803const luaL_Reg lTimer_set[] = {
804 {"interval", _edje_lua_timer_set_interval},
805 {NULL, NULL} // sentinel
806};
807
808static int
809_edje_lua_timer_fn_del(lua_State *L)
810{
811 Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer);
812 if (obj->et)
813 {
814 ecore_timer_del(obj->et);
815 obj->et = NULL;
816 }
817 if (obj->cb)
818 {
819 _edje_lua_free_ref(L, obj->cb); // created in _edje_lua_group_fn_timer
820 obj->cb = NULL;
821 }
822 _edje_lua_free_reg(L, obj); // created in _edje_lua_group_fn_timer
823 return 0;
824}
825
826static int
827_edje_lua_timer_fn_freeze(lua_State *L)
828{
829 Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer);
830 if (obj->et)
831 ecore_timer_freeze(obj->et);
832 return 0;
833}
834
835static int
836_edje_lua_timer_fn_thaw(lua_State *L)
837{
838 Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer);
839 if (obj->et)
840 ecore_timer_thaw(obj->et);
841 return 0;
842}
843
844static int
845_edje_lua_timer_fn_delay(lua_State *L)
846{
847 Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer);
848 if (obj->et)
849 ecore_timer_delay(obj->et, luaL_checknumber(L, 2));
850 return 0;
851}
852
853const luaL_Reg lTimer_fn[] = {
854 {"del", _edje_lua_timer_fn_del},
855 {"freeze", _edje_lua_timer_fn_freeze},
856 {"thaw", _edje_lua_timer_fn_thaw},
857 {"delay", _edje_lua_timer_fn_delay},
858 {NULL, NULL} // sentinel
859};
860
861const luaL_Reg lAnimator_get[];
862
863const luaL_Reg lAnimator_fn[];
864
865const Edje_Lua_Reg mAnimator = {
866 lNil,
867 lAnimator_get,
868 lNil,
869 lAnimator_fn
870};
871
872const Edje_Lua_Reg *cAnimator[] = {
873 &mClass,
874 &mAnimator,
875 NULL // sentinel
876};
877
878static Eina_Bool
879_edje_lua_animator_cb(void *data)
880{
881 Eina_Bool res;
882 int err;
883 Edje_Lua_Animator *obj = data;
884 lua_State *L = obj->L;
885
886 _edje_lua_get_ref(L, obj->cb);
887 _edje_lua_get_reg(L, obj);
888
889 if ((err = lua_pcall(L, 1, 1, 0)))
890 {
891 _edje_lua_error(L, err);
892 return ECORE_CALLBACK_CANCEL;
893 }
894
895 res = luaL_checkint(L, -1);
896 lua_pop(L, 1); // Pop res off the stack
897 if (res == ECORE_CALLBACK_CANCEL)
898 {
899 /* delete animator */
900 _edje_lua_get_reg(L, obj);
901 lua_pushvalue(L, -1);
902 lua_pushstring(L, "del");
903 lua_gettable(L, -2);
904 lua_insert(L, -2);
905 if ((err = lua_pcall(L, 1, 0, 0)))
906 _edje_lua_error(L, err);
907 }
908
909 return res;
910}
911
912static int
913_edje_lua_animator_get_frametime(lua_State *L)
914{
915 Edje_Lua_Animator *obj = _edje_lua_checkudata(L, 1, &mAnimator);
916
917 if (obj->ea)
918 lua_pushnumber(L, ecore_animator_frametime_get());
919 else
920 lua_pushnil(L);
921
922 return 1;
923}
924
925const luaL_Reg lAnimator_get[] = {
926 {"frametime", _edje_lua_animator_get_frametime},
927 {NULL, NULL}
928};
929
930static int
931_edje_lua_animator_fn_del(lua_State *L)
932{
933 Edje_Lua_Animator *obj = _edje_lua_checkudata(L, 1, &mAnimator);
934 if (obj->ea)
935 {
936 ecore_animator_del(obj->ea);
937 obj->ea = NULL;
938 }
939 if (obj->cb)
940 {
941 _edje_lua_free_ref(L, obj->cb); // created in _edje_lua_group_fn_animator
942 obj->cb = NULL;
943 }
944 _edje_lua_free_reg(L, obj); // created in _edje_lua_group_fn_animator
945 return 0;
946}
947
948const luaL_Reg lAnimator_fn[] = {
949 {"del", _edje_lua_animator_fn_del},
950 {NULL, NULL} // sentinel
951};
952
953const luaL_Reg lPoller_get[];
954
955const luaL_Reg lPoller_fn[];
956
957const Edje_Lua_Reg mPoller = {
958 lNil,
959 lPoller_get,
960 lNil,
961 lPoller_fn
962};
963
964const Edje_Lua_Reg *cPoller[] = {
965 &mClass,
966 &mPoller,
967 NULL // sentinel
968};
969
970static Eina_Bool
971_edje_lua_poller_cb(void *data)
972{
973 Eina_Bool res;
974 int err;
975 Edje_Lua_Poller *obj = data;
976 lua_State *L = obj->L;
977
978 _edje_lua_get_ref(L, obj->cb);
979 _edje_lua_get_reg(L, obj);
980
981 if ((err = lua_pcall(L, 1, 1, 0)))
982 {
983 _edje_lua_error(L, err);
984 return ECORE_CALLBACK_CANCEL;
985 }
986
987 res = luaL_checkint(L, -1);
988 lua_pop(L, 1); // Pop res off the stack
989 if (res == ECORE_CALLBACK_CANCEL)
990 {
991 /* delete poller */
992 _edje_lua_get_reg(L, obj);
993 lua_pushvalue(L, -1);
994 lua_pushstring(L, "del");
995 lua_gettable(L, -2);
996 lua_insert(L, -2);
997 if ((err = lua_pcall(L, 1, 0, 0)))
998 _edje_lua_error(L, err);
999 }
1000
1001 return res;
1002}
1003
1004static int
1005_edje_lua_poller_get_interval(lua_State *L)
1006{
1007 Edje_Lua_Poller *obj = _edje_lua_checkudata(L, 1, &mPoller);
1008
1009 if (obj->ep)
1010 lua_pushnumber(L, ecore_poller_poll_interval_get(ECORE_POLLER_CORE));
1011 else
1012 lua_pushnil(L);
1013
1014 return 1;
1015}
1016
1017const luaL_Reg lPoller_get[] = {
1018 {"interval", _edje_lua_poller_get_interval},
1019 {NULL, NULL}
1020};
1021
1022static int
1023_edje_lua_poller_fn_del(lua_State *L)
1024{
1025 Edje_Lua_Poller *obj = _edje_lua_checkudata(L, 1, &mPoller);
1026 if (obj->ep)
1027 {
1028 ecore_poller_del(obj->ep);
1029 obj->ep = NULL;
1030 }
1031
1032 if (obj->cb)
1033 {
1034 _edje_lua_free_ref(L, obj->cb); // created in _edje_lua_group_fn_poller
1035 obj->cb = NULL;
1036 }
1037 _edje_lua_free_reg(L, obj); // created in _edje_lua_group_fn_poller
1038
1039 return 0;
1040}
1041
1042const luaL_Reg lPoller_fn[] = {
1043 {"del", _edje_lua_poller_fn_del},
1044 {NULL, NULL}
1045};
1046
1047/*
1048 * Lua Edje Transform bindings
1049 */
1050
1051const luaL_Reg lTransform_get[];
1052
1053const luaL_Reg lTransform_set[];
1054
1055const luaL_Reg lTransform_fn[];
1056
1057const Edje_Lua_Reg mTransform = {
1058 lNil,
1059 lTransform_get,
1060 lTransform_set,
1061 lTransform_fn
1062};
1063
1064const Edje_Lua_Reg *cTransform[] = {
1065 &mClass,
1066 &mTransform,
1067 NULL // sentinel
1068};
1069
1070static int
1071_edje_lua_transform_get_matrix(lua_State *L)
1072{
1073 Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform);
1074 lua_createtable(L, 3, 0);
1075 lua_createtable(L, 3, 0);
1076 lua_pushnumber(L, obj->et.mxx); lua_rawseti(L, -2, 1);
1077 lua_pushnumber(L, obj->et.mxy); lua_rawseti(L, -2, 2);
1078 lua_pushnumber(L, obj->et.mxz); lua_rawseti(L, -2, 3);
1079 lua_rawseti(L, -2, 1);
1080 lua_createtable(L, 3, 0);
1081 lua_pushnumber(L, obj->et.myx); lua_rawseti(L, -2, 1);
1082 lua_pushnumber(L, obj->et.myy); lua_rawseti(L, -2, 2);
1083 lua_pushnumber(L, obj->et.myz); lua_rawseti(L, -2, 3);
1084 lua_rawseti(L, -2, 2);
1085 lua_createtable(L, 3, 0);
1086 lua_pushnumber(L, obj->et.mzx); lua_rawseti(L, -2, 1);
1087 lua_pushnumber(L, obj->et.mzy); lua_rawseti(L, -2, 2);
1088 lua_pushnumber(L, obj->et.mzz); lua_rawseti(L, -2, 3);
1089 lua_rawseti(L, -2, 3);
1090 return 1;
1091}
1092
1093const luaL_Reg lTransform_get[] = {
1094 {"matrix", _edje_lua_transform_get_matrix},
1095 {NULL, NULL} // sentinel
1096};
1097
1098static int
1099_edje_lua_transform_set_matrix(lua_State *L)
1100{
1101 Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform);
1102 luaL_checktype(L, 2, LUA_TTABLE);
1103 lua_rawgeti(L, 2, 1);
1104 luaL_checktype(L, -1, LUA_TTABLE);
1105 lua_rawgeti(L, -1, 1); obj->et.mxx = luaL_checknumber(L, -1); lua_pop(L, 1);
1106 lua_rawgeti(L, -1, 2); obj->et.mxy = luaL_checknumber(L, -1); lua_pop(L, 1);
1107 lua_rawgeti(L, -1, 3); obj->et.mxz = luaL_checknumber(L, -1); lua_pop(L, 1);
1108 lua_pop(L, 1);
1109 lua_rawgeti(L, 2, 2);
1110 luaL_checktype(L, -1, LUA_TTABLE);
1111 lua_rawgeti(L, -1, 1); obj->et.myx = luaL_checknumber(L, -1); lua_pop(L, 1);
1112 lua_rawgeti(L, -1, 2); obj->et.myy = luaL_checknumber(L, -1); lua_pop(L, 1);
1113 lua_rawgeti(L, -1, 3); obj->et.myz = luaL_checknumber(L, -1); lua_pop(L, 1);
1114 lua_pop(L, 1);
1115 lua_rawgeti(L, 2, 3);
1116 luaL_checktype(L, -1, LUA_TTABLE);
1117 lua_rawgeti(L, -1, 1); obj->et.mzx = luaL_checknumber(L, -1); lua_pop(L, 1);
1118 lua_rawgeti(L, -1, 2); obj->et.mzy = luaL_checknumber(L, -1); lua_pop(L, 1);
1119 lua_rawgeti(L, -1, 3); obj->et.mzz = luaL_checknumber(L, -1); lua_pop(L, 1);
1120 lua_pop(L, 1);
1121 return 0;
1122}
1123
1124const luaL_Reg lTransform_set[] = {
1125 {"matrix", _edje_lua_transform_set_matrix},
1126 {NULL, NULL} // sentinel
1127};
1128
1129static int
1130_edje_lua_transform_fn_identity(lua_State *L)
1131{
1132 Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform);
1133 evas_transform_identity_set(&(obj->et));
1134 return 0;
1135}
1136
1137static int
1138_edje_lua_transform_fn_rotate(lua_State *L)
1139{
1140 Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform);
1141 evas_transform_rotate(luaL_checknumber(L, 2), &(obj->et));
1142 return 0;
1143}
1144
1145static int
1146_edje_lua_transform_fn_translate(lua_State *L)
1147{
1148 Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform);
1149 evas_transform_translate(luaL_checknumber(L, 2), luaL_checknumber(L, 3), &(obj->et));
1150 return 0;
1151}
1152
1153static int
1154_edje_lua_transform_fn_scale(lua_State *L)
1155{
1156 Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform);
1157 evas_transform_scale(luaL_checknumber(L, 2), luaL_checknumber(L, 3), &(obj->et));
1158 return 0;
1159}
1160
1161static int
1162_edje_lua_transform_fn_shear(lua_State *L)
1163{
1164 Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform);
1165 evas_transform_shear(luaL_checknumber(L, 2), luaL_checknumber(L, 3), &(obj->et));
1166 return 0;
1167}
1168
1169static int
1170_edje_lua_transform_fn_compose(lua_State *L)
1171{
1172 Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform);
1173 Edje_Lua_Transform *tar = _edje_lua_checkudata(L, 2, &mTransform);
1174 evas_transform_compose(&(tar->et), &(obj->et));
1175 return 0;
1176}
1177
1178const luaL_Reg lTransform_fn[] = {
1179 {"identity", _edje_lua_transform_fn_identity},
1180 {"rotate", _edje_lua_transform_fn_rotate},
1181 {"translate", _edje_lua_transform_fn_translate},
1182 {"scale", _edje_lua_transform_fn_scale},
1183 {"shear", _edje_lua_transform_fn_shear},
1184 {"compose", _edje_lua_transform_fn_compose},
1185 {NULL, NULL} // sentinel
1186};
1187
1188/*
1189 * Lua Edje Transition bindings
1190 */
1191
1192const luaL_Reg lTransition_get[];
1193
1194const luaL_Reg lTransition_set[];
1195
1196const luaL_Reg lTransition_fn[];
1197
1198const Edje_Lua_Reg mTransition = {
1199 lNil,
1200 lTransition_get,
1201 lTransition_set,
1202 lTransition_fn
1203};
1204
1205const Edje_Lua_Reg *cTransition[] = {
1206 &mClass,
1207 &mTransition,
1208 NULL // sentinel
1209};
1210
1211const luaL_Reg lTransition_get[] = {
1212 {NULL, NULL} // sentinel
1213};
1214
1215const luaL_Reg lTransition_set[] = {
1216 {NULL, NULL} // sentinel
1217};
1218
1219const luaL_Reg lTransition_fn[] = {
1220 {NULL, NULL} // sentinel
1221};
1222
1223const luaL_Reg lObject_get[];
1224
1225const luaL_Reg lObject_set[];
1226
1227const luaL_Reg lObject_fn[];
1228
1229const Edje_Lua_Reg mObject = {
1230 lNil,
1231 lObject_get,
1232 lObject_set,
1233 lObject_fn
1234};
1235
1236static void
1237_edje_lua_object_del_cb(void *data, __UNUSED__ Evas * e, Evas_Object * obj, __UNUSED__ void *event_info)
1238{
1239 //printf("_edje_lua_object_delete_cb\n");
1240 lua_State *L = data;
1241 _edje_lua_get_reg(L, obj);
1242 Edje_Lua_Evas_Object *udata = _edje_lua_checkudata(L, -1, &mObject);
1243 lua_pop(L, 1);
1244 _edje_lua_free_reg(L, udata); // created in EDJE_LUA_SCRIPT_FN_ADD
1245 _edje_lua_free_reg(L, obj); // created in EDJE_LUA_SCRIPT_FN_ADD
1246
1247 Edje_Lua_Ref *ref;
1248 EINA_LIST_FREE(udata->cb, ref)
1249 _edje_lua_free_ref(L, ref);
1250}
1251
1252static int
1253_edje_lua_object_fn_del(lua_State *L)
1254{
1255 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1256
1257 if (obj->eo)
1258 {
1259 evas_object_del(obj->eo);
1260 obj->eo = NULL;
1261 obj->ed = NULL;
1262 }
1263 return 0;
1264}
1265
1266static int
1267_edje_lua_object_fn_show(lua_State *L)
1268{
1269 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1270 evas_object_show(obj->eo);
1271 return 0;
1272}
1273
1274static int
1275_edje_lua_object_fn_hide(lua_State *L)
1276{
1277 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1278 evas_object_hide(obj->eo);
1279 return 0;
1280}
1281
1282static int
1283_edje_lua_object_fn_move(lua_State *L)
1284{
1285 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1286 //printf ("%i %i %i %i\n", obj->ed->x, obj->ed->y, luaL_checkint (L, 2), luaL_checkint (L, 3));
1287 evas_object_move(obj->eo,
1288 obj->ed->x + luaL_checkint(L, 2),
1289 obj->ed->y + luaL_checkint(L, 3));
1290 return 0;
1291}
1292
1293static int
1294_edje_lua_object_fn_resize(lua_State *L)
1295{
1296 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1297 evas_object_resize(obj->eo, luaL_checkint(L, 2), luaL_checkint(L, 3));
1298 return 0;
1299}
1300
1301static int
1302_edje_lua_object_fn_raise(lua_State *L)
1303{
1304 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1305 evas_object_raise(obj->eo);
1306 return 0;
1307}
1308
1309static int
1310_edje_lua_object_fn_lower(lua_State *L)
1311{
1312 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1313 evas_object_lower(obj->eo);
1314 return 0;
1315}
1316
1317static int
1318_edje_lua_object_fn_stack_above(lua_State *L)
1319{
1320 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1321 Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject);
1322 evas_object_stack_above(obj->eo, tar->eo);
1323 return 0;
1324}
1325
1326static int
1327_edje_lua_object_fn_stack_below(lua_State *L)
1328{
1329 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1330 Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject);
1331 evas_object_stack_below(obj->eo, tar->eo);
1332 return 0;
1333}
1334
1335static int
1336_edje_lua_object_fn_clip_unset(lua_State *L)
1337{
1338 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1339 evas_object_clip_unset(obj->eo);
1340 return 0;
1341}
1342
1343const luaL_Reg lObject_fn[] = {
1344 {"del", _edje_lua_object_fn_del},
1345 {"show", _edje_lua_object_fn_show},
1346 {"hide", _edje_lua_object_fn_hide},
1347 {"move", _edje_lua_object_fn_move},
1348 {"resize", _edje_lua_object_fn_resize},
1349 {"raise", _edje_lua_object_fn_raise},
1350 {"lower", _edje_lua_object_fn_lower},
1351 {"stack_above", _edje_lua_object_fn_stack_above},
1352 {"stack_below", _edje_lua_object_fn_stack_below},
1353 {"clip_unset", _edje_lua_object_fn_clip_unset},
1354 {NULL, NULL} // sentinel
1355};
1356
1357static int
1358_edje_lua_object_get_name(lua_State *L)
1359{
1360 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1361 lua_pushstring(L, evas_object_name_get(obj->eo));
1362 return 1;
1363}
1364
1365static int
1366_edje_lua_object_get_geometry(lua_State *L)
1367{
1368 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1369 int x, y, w, h;
1370 evas_object_geometry_get(obj->eo, &x, &y, &w, &h);
1371 lua_createtable(L, 4, 0);
1372 lua_pushnumber(L, x);
1373 lua_rawseti(L, -2, 1);
1374 lua_pushnumber(L, y);
1375 lua_rawseti(L, -2, 2);
1376 lua_pushnumber(L, w);
1377 lua_rawseti(L, -2, 3);
1378 lua_pushnumber(L, h);
1379 lua_rawseti(L, -2, 4);
1380 return 1;
1381}
1382
1383static int
1384_edje_lua_object_get_type(lua_State *L)
1385{
1386 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1387 lua_pushstring(L, evas_object_type_get(obj->eo));
1388 return 1;
1389}
1390
1391static int
1392_edje_lua_object_get_layer(lua_State *L)
1393{
1394 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1395 lua_pushnumber(L, evas_object_layer_get(obj->eo));
1396 return 1;
1397}
1398
1399static int
1400_edje_lua_object_get_above(lua_State *L)
1401{
1402 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1403 Evas_Object *above = evas_object_above_get(obj->eo);
1404 _edje_lua_get_reg(L, above);
1405 // TODO create object if it does not already exist?
1406 return 1;
1407}
1408
1409static int
1410_edje_lua_object_get_below(lua_State *L)
1411{
1412 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1413 Evas_Object *below = evas_object_below_get(obj->eo);
1414 _edje_lua_get_reg(L, below);
1415 // TODO create object if it does not already exist?
1416 return 1;
1417}
1418
1419static int
1420_edje_lua_object_get_size_hint_min(lua_State *L)
1421{
1422 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1423 int w, h;
1424 evas_object_size_hint_min_get(obj->eo, &w, &h);
1425 lua_createtable(L, 2, 0);
1426 lua_pushnumber(L, w);
1427 lua_rawseti(L, -2, 1);
1428 lua_pushnumber(L, h);
1429 lua_rawseti(L, -2, 2);
1430 return 1;
1431}
1432
1433static int
1434_edje_lua_object_get_size_hint_max(lua_State *L)
1435{
1436 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1437 int w, h;
1438 evas_object_size_hint_max_get(obj->eo, &w, &h);
1439 lua_createtable(L, 2, 0);
1440 lua_pushnumber(L, w);
1441 lua_rawseti(L, -2, 1);
1442 lua_pushnumber(L, h);
1443 lua_rawseti(L, -2, 2);
1444 return 1;
1445}
1446
1447static int
1448_edje_lua_object_get_size_hint_request(lua_State *L)
1449{
1450 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1451 int w, h;
1452 evas_object_size_hint_request_get(obj->eo, &w, &h);
1453 lua_createtable(L, 2, 0);
1454 lua_pushnumber(L, w);
1455 lua_rawseti(L, -2, 1);
1456 lua_pushnumber(L, h);
1457 lua_rawseti(L, -2, 2);
1458 return 1;
1459}
1460
1461static int
1462_edje_lua_object_get_size_hint_aspect(lua_State *L)
1463{
1464 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1465 Evas_Aspect_Control a;
1466 int w, h;
1467 evas_object_size_hint_aspect_get(obj->eo, &a, &w, &h);
1468 lua_createtable(L, 3, 0);
1469 lua_pushnumber(L, a);
1470 lua_rawseti(L, -2, 1);
1471 lua_pushnumber(L, w);
1472 lua_rawseti(L, -2, 2);
1473 lua_pushnumber(L, h);
1474 lua_rawseti(L, -2, 3);
1475 return 1;
1476}
1477
1478static int
1479_edje_lua_object_get_size_hint_align(lua_State *L)
1480{
1481 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1482 double w, h;
1483 evas_object_size_hint_align_get(obj->eo, &w, &h);
1484 lua_createtable(L, 2, 0);
1485 lua_pushnumber(L, w);
1486 lua_rawseti(L, -2, 1);
1487 lua_pushnumber(L, h);
1488 lua_rawseti(L, -2, 2);
1489 return 1;
1490}
1491
1492static int
1493_edje_lua_object_get_size_hint_weight(lua_State *L)
1494{
1495 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1496 double w, h;
1497 evas_object_size_hint_weight_get(obj->eo, &w, &h);
1498 lua_createtable(L, 2, 0);
1499 lua_pushnumber(L, w);
1500 lua_rawseti(L, -2, 1);
1501 lua_pushnumber(L, h);
1502 lua_rawseti(L, -2, 2);
1503 return 1;
1504}
1505
1506static int
1507_edje_lua_object_get_size_hint_padding(lua_State *L)
1508{
1509 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1510 int l, r, t, b;
1511 evas_object_size_hint_padding_get(obj->eo, &l, &r, &t, &b);
1512 lua_createtable(L, 4, 0);
1513 lua_pushnumber(L, l);
1514 lua_rawseti(L, -2, 1);
1515 lua_pushnumber(L, r);
1516 lua_rawseti(L, -2, 2);
1517 lua_pushnumber(L, t);
1518 lua_rawseti(L, -2, 3);
1519 lua_pushnumber(L, b);
1520 lua_rawseti(L, -2, 4);
1521 return 1;
1522}
1523
1524static int
1525_edje_lua_object_get_visible(lua_State *L)
1526{
1527 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1528 lua_pushboolean(L, evas_object_visible_get(obj->eo));
1529 return 1;
1530}
1531
1532static int
1533_edje_lua_object_get_render_op(lua_State *L)
1534{
1535 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1536 lua_pushnumber(L, evas_object_render_op_get(obj->eo));
1537 return 1;
1538}
1539
1540static int
1541_edje_lua_object_get_anti_alias(lua_State *L)
1542{
1543 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1544 lua_pushboolean(L, evas_object_anti_alias_get(obj->eo));
1545 return 1;
1546}
1547
1548static int
1549_edje_lua_object_get_scale(lua_State *L)
1550{
1551 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1552 lua_pushnumber(L, evas_object_scale_get(obj->eo));
1553 return 1;
1554}
1555
1556static int
1557_edje_lua_object_get_color(lua_State *L)
1558{
1559 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1560 int r, g, b, a;
1561 evas_object_color_get(obj->eo, &r, &g, &b, &a);
1562 lua_createtable(L, 4, 0);
1563 lua_pushnumber(L, r);
1564 lua_rawseti(L, -2, 1);
1565 lua_pushnumber(L, g);
1566 lua_rawseti(L, -2, 2);
1567 lua_pushnumber(L, b);
1568 lua_rawseti(L, -2, 3);
1569 lua_pushnumber(L, a);
1570 lua_rawseti(L, -2, 4);
1571 return 1;
1572}
1573
1574static int
1575_edje_lua_object_get_color_interpolation(lua_State *L)
1576{
1577 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1578 lua_pushnumber(L, evas_object_color_interpolation_get(obj->eo));
1579 return 1;
1580}
1581
1582static int
1583_edje_lua_object_get_clip(lua_State *L)
1584{
1585 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1586 Evas_Object *clip = evas_object_clip_get(obj->eo);
1587 _edje_lua_get_reg(L, clip);
1588 // TODO create object if it does not already exist?
1589 return 1;
1590}
1591
1592static int
1593_edje_lua_object_get_clipees(lua_State *L)
1594{
1595 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1596 Eina_List *clipees = (Eina_List *) evas_object_clipees_get(obj->eo);
1597 Eina_List *l;
1598 Evas_Object *clip;
1599 int i = 1;
1600 lua_createtable(L, eina_list_count(clipees), 0);
1601 EINA_LIST_FOREACH(clipees, l, clip)
1602 {
1603 _edje_lua_get_reg(L, clip);
1604 // TODO create object if it does not already exist?
1605 lua_rawseti(L, -2, i++);
1606 }
1607 return 1;
1608}
1609
1610static int
1611_edje_lua_object_get_evas(lua_State *L)
1612{
1613 //Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1614 lua_pushnil(L);
1615 // FIXME implement Evas class in the first place?
1616 return 1;
1617}
1618
1619static int
1620_edje_lua_object_get_pass_events(lua_State *L)
1621{
1622 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1623 lua_pushboolean(L, evas_object_pass_events_get(obj->eo));
1624 return 1;
1625}
1626
1627static int
1628_edje_lua_object_get_repeat_events(lua_State *L)
1629{
1630 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1631 lua_pushboolean(L, evas_object_repeat_events_get(obj->eo));
1632 return 1;
1633}
1634
1635static int
1636_edje_lua_object_get_propagate_events(lua_State *L)
1637{
1638 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1639 lua_pushboolean(L, evas_object_propagate_events_get(obj->eo));
1640 return 1;
1641}
1642
1643static int
1644_edje_lua_object_get_focus(lua_State *L)
1645{
1646 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1647 lua_pushboolean(L, evas_object_focus_get(obj->eo));
1648 return 1;
1649}
1650
1651static int
1652_edje_lua_object_get_pointer_mode(lua_State *L)
1653{
1654 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1655 lua_pushnumber(L, evas_object_pointer_mode_get(obj->eo));
1656 return 1;
1657}
1658
1659static int
1660_edje_lua_object_get_precise_is_inside(lua_State *L)
1661{
1662 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1663 lua_pushboolean(L, evas_object_precise_is_inside_get(obj->eo));
1664 return 1;
1665}
1666
1667static int
1668_edje_lua_object_get_mouse_events(lua_State *L)
1669{
1670 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1671 lua_pushboolean(L, obj->mouse_events);
1672 return 1;
1673}
1674
1675const luaL_Reg lObject_get[] = {
1676 {"name", _edje_lua_object_get_name},
1677 {"geometry", _edje_lua_object_get_geometry},
1678 {"type", _edje_lua_object_get_type},
1679 {"layer", _edje_lua_object_get_layer},
1680 {"above", _edje_lua_object_get_above},
1681 {"below", _edje_lua_object_get_below},
1682 {"size_hint_min", _edje_lua_object_get_size_hint_min},
1683 {"size_hint_max", _edje_lua_object_get_size_hint_max},
1684 {"size_hint_request", _edje_lua_object_get_size_hint_request},
1685 {"size_hint_aspect", _edje_lua_object_get_size_hint_aspect},
1686 {"size_hint_align", _edje_lua_object_get_size_hint_align},
1687 {"size_hint_weight", _edje_lua_object_get_size_hint_weight},
1688 {"size_hint_padding", _edje_lua_object_get_size_hint_padding},
1689 {"visible", _edje_lua_object_get_visible},
1690 {"render_op", _edje_lua_object_get_render_op},
1691 {"anti_alias", _edje_lua_object_get_anti_alias},
1692 {"scale", _edje_lua_object_get_scale},
1693 {"color", _edje_lua_object_get_color},
1694 {"color_interpolation", _edje_lua_object_get_color_interpolation},
1695 {"clip", _edje_lua_object_get_clip},
1696 {"clipees", _edje_lua_object_get_clipees},
1697 {"evas", _edje_lua_object_get_evas},
1698 {"pass_events", _edje_lua_object_get_pass_events},
1699 {"repeat_events", _edje_lua_object_get_repeat_events},
1700 {"propagate_events", _edje_lua_object_get_propagate_events},
1701 {"focus", _edje_lua_object_get_focus},
1702 {"pointer_mode", _edje_lua_object_get_pointer_mode},
1703 {"precise_is_inside", _edje_lua_object_get_precise_is_inside},
1704 {"mouse_events", _edje_lua_object_get_mouse_events},
1705 {NULL, NULL} // sentinel
1706};
1707
1708static int
1709_edje_lua_object_set_name(lua_State *L)
1710{
1711 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1712 evas_object_name_set(obj->eo, luaL_checkstring(L, 2));
1713 return 0;
1714}
1715
1716static int
1717_edje_lua_object_set_layer(lua_State *L)
1718{
1719 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1720 evas_object_layer_set(obj->eo, luaL_checkint(L, 2));
1721 return 0;
1722}
1723
1724static int
1725_edje_lua_object_set_size_hint_min(lua_State *L)
1726{
1727 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1728 luaL_checktype(L, 2, LUA_TTABLE);
1729 lua_rawgeti(L, 2, 1);
1730 lua_rawgeti(L, 2, 2);
1731 evas_object_size_hint_min_set(obj->eo,
1732 luaL_checkint(L, -2),
1733 luaL_checkint(L, -1));
1734 return 0;
1735}
1736
1737static int
1738_edje_lua_object_set_size_hint_max(lua_State *L)
1739{
1740 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1741 luaL_checktype(L, 2, LUA_TTABLE);
1742 lua_rawgeti(L, 2, 1);
1743 lua_rawgeti(L, 2, 2);
1744 evas_object_size_hint_max_set(obj->eo,
1745 luaL_checkint(L, -2),
1746 luaL_checkint(L, -1));
1747 return 0;
1748}
1749
1750static int
1751_edje_lua_object_set_size_hint_request(lua_State *L)
1752{
1753 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1754 luaL_checktype(L, 2, LUA_TTABLE);
1755 lua_rawgeti(L, 2, 1);
1756 lua_rawgeti(L, 2, 2);
1757 evas_object_size_hint_request_set(obj->eo,
1758 luaL_checkint(L, -2),
1759 luaL_checkint(L, -1));
1760 return 0;
1761}
1762
1763static int
1764_edje_lua_object_set_size_hint_aspect(lua_State *L)
1765{
1766 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1767 luaL_checktype(L, 2, LUA_TTABLE);
1768 lua_rawgeti(L, 2, 1);
1769 lua_rawgeti(L, 2, 2);
1770 lua_rawgeti(L, 2, 3);
1771 evas_object_size_hint_aspect_set(obj->eo,
1772 luaL_checkint(L, -3),
1773 luaL_checkint(L, -2),
1774 luaL_checkint(L, -1));
1775 return 0;
1776}
1777
1778static int
1779_edje_lua_object_set_size_hint_align(lua_State *L)
1780{
1781 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1782 luaL_checktype(L, 2, LUA_TTABLE);
1783 lua_rawgeti(L, 2, 1);
1784 lua_rawgeti(L, 2, 2);
1785 evas_object_size_hint_align_set(obj->eo,
1786 luaL_checknumber(L, -2),
1787 luaL_checknumber(L, -1));
1788 return 0;
1789}
1790
1791static int
1792_edje_lua_object_set_size_hint_weight(lua_State *L)
1793{
1794 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1795 luaL_checktype(L, 2, LUA_TTABLE);
1796 lua_rawgeti(L, 2, 1);
1797 lua_rawgeti(L, 2, 2);
1798 evas_object_size_hint_weight_set(obj->eo,
1799 luaL_checknumber(L, -2),
1800 luaL_checknumber(L, -1));
1801 return 0;
1802}
1803
1804static int
1805_edje_lua_object_set_size_hint_padding(lua_State *L)
1806{
1807 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1808 luaL_checktype(L, 2, LUA_TTABLE);
1809 lua_rawgeti(L, 2, 1);
1810 lua_rawgeti(L, 2, 2);
1811 lua_rawgeti(L, 2, 3);
1812 lua_rawgeti(L, 2, 4);
1813 evas_object_size_hint_padding_set(obj->eo,
1814 luaL_checknumber(L, -4),
1815 luaL_checknumber(L, -3),
1816 luaL_checknumber(L, -2),
1817 luaL_checknumber(L, -1));
1818 return 0;
1819}
1820
1821static int
1822_edje_lua_object_set_render_op(lua_State *L)
1823{
1824 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1825 evas_object_render_op_set(obj->eo, luaL_checkint(L, 2));
1826 return 0;
1827}
1828
1829static int
1830_edje_lua_object_set_anti_alias(lua_State *L)
1831{
1832 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1833 evas_object_anti_alias_set(obj->eo, lua_toboolean(L, 2));
1834 return 0;
1835}
1836
1837static int
1838_edje_lua_object_set_scale(lua_State *L)
1839{
1840 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1841 evas_object_scale_set(obj->eo, luaL_checknumber(L, 2));
1842 return 0;
1843}
1844
1845static int
1846_edje_lua_object_set_color(lua_State *L)
1847{
1848 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1849 luaL_checktype(L, 2, LUA_TTABLE);
1850 lua_rawgeti(L, 2, 1);
1851 lua_rawgeti(L, 2, 2);
1852 lua_rawgeti(L, 2, 3);
1853 lua_rawgeti(L, 2, 4);
1854 evas_object_color_set(obj->eo,
1855 luaL_checkint(L, -4),
1856 luaL_checkint(L, -3),
1857 luaL_checkint(L, -2),
1858 luaL_checkint(L, -1));
1859 return 0;
1860}
1861
1862static int
1863_edje_lua_object_set_color_interpolation(lua_State *L)
1864{
1865 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1866 evas_object_color_interpolation_set(obj->eo, luaL_checkint(L, 2));
1867 return 0;
1868}
1869
1870static int
1871_edje_lua_object_set_clip(lua_State *L)
1872{
1873 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1874 Edje_Lua_Evas_Object *clip = _edje_lua_checkudata(L, 2, &mObject);
1875 evas_object_clip_set(obj->eo, clip->eo);
1876 return 0;
1877}
1878
1879static int
1880_edje_lua_object_set_pass_events(lua_State *L)
1881{
1882 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1883 evas_object_pass_events_set(obj->eo, lua_toboolean(L, 2));
1884 return 0;
1885}
1886
1887static int
1888_edje_lua_object_set_repeat_events(lua_State *L)
1889{
1890 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1891 evas_object_repeat_events_set(obj->eo, lua_toboolean(L, 2));
1892 return 0;
1893}
1894
1895static int
1896_edje_lua_object_set_propagate_events(lua_State *L)
1897{
1898 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1899 evas_object_propagate_events_set(obj->eo, lua_toboolean(L, 2));
1900 return 0;
1901}
1902
1903static int
1904_edje_lua_object_set_focus(lua_State *L)
1905{
1906 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1907 evas_object_focus_set(obj->eo, lua_toboolean(L, 2));
1908 return 0;
1909}
1910
1911static int
1912_edje_lua_object_set_pointer_mode(lua_State *L)
1913{
1914 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1915 evas_object_pointer_mode_set(obj->eo, luaL_checkint(L, 2));
1916 return 0;
1917}
1918
1919static int
1920_edje_lua_object_set_precise_is_inside(lua_State *L)
1921{
1922 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
1923 evas_object_precise_is_inside_set(obj->eo, lua_toboolean(L, 2));
1924 return 0;
1925}
1926
1927#define OBJECT_CB_MACRO(KEY) \
1928 lua_State *L = data; \
1929 _edje_lua_get_reg(L, obj); \
1930 lua_getfield(L, -1, KEY); \
1931 if (lua_type(L, -1) != LUA_TFUNCTION) \
1932 { \
1933 lua_pop(L, 2); \
1934 return; \
1935 } \
1936 lua_insert(L, -2);
1937
1938static void
1939_edje_lua_object_cb_mouse_in(void *data, __UNUSED__ Evas * e, Evas_Object * obj,
1940 void *event_info)
1941{
1942 OBJECT_CB_MACRO("mouse_in");
1943 Evas_Event_Mouse_In * ev = event_info;
1944 int err_code;
1945
1946 lua_pushnumber(L, ev->output.x);
1947 lua_pushnumber(L, ev->output.y);
1948 lua_pushnumber(L, ev->canvas.x);
1949 lua_pushnumber(L, ev->canvas.y);
1950
1951 if ((err_code = lua_pcall(L, 5, 0, 0)))
1952 _edje_lua_error(L, err_code);
1953}
1954
1955static void
1956_edje_lua_object_cb_mouse_out(void *data, __UNUSED__ Evas * e, Evas_Object * obj,
1957 void *event_info)
1958{
1959 OBJECT_CB_MACRO("mouse_out");
1960 Evas_Event_Mouse_In * ev = event_info;
1961 int err_code;
1962
1963 lua_pushnumber(L, ev->output.x);
1964 lua_pushnumber(L, ev->output.y);
1965 lua_pushnumber(L, ev->canvas.x);
1966 lua_pushnumber(L, ev->canvas.y);
1967
1968 if ((err_code = lua_pcall(L, 5, 0, 0)))
1969 _edje_lua_error(L, err_code);
1970}
1971
1972static void
1973_edje_lua_object_cb_mouse_down(void *data, __UNUSED__ Evas * e, Evas_Object * obj,
1974 void *event_info)
1975{
1976 OBJECT_CB_MACRO("mouse_down");
1977 Evas_Event_Mouse_Down * ev = event_info;
1978 int err_code;
1979
1980 lua_pushnumber(L, ev->button);
1981 lua_pushnumber(L, ev->output.x);
1982 lua_pushnumber(L, ev->output.y);
1983 lua_pushnumber(L, ev->canvas.x);
1984 lua_pushnumber(L, ev->canvas.y);
1985
1986 if ((err_code = lua_pcall(L, 6, 0, 0)))
1987 _edje_lua_error(L, err_code);
1988}
1989
1990static void
1991_edje_lua_object_cb_mouse_up(void *data, __UNUSED__ Evas * e, Evas_Object * obj,
1992 void *event_info)
1993{
1994 OBJECT_CB_MACRO("mouse_up");
1995 Evas_Event_Mouse_Up * ev = event_info;
1996 int err_code;
1997
1998 lua_pushnumber(L, ev->button);
1999 lua_pushnumber(L, ev->output.x);
2000 lua_pushnumber(L, ev->output.y);
2001 lua_pushnumber(L, ev->canvas.x);
2002 lua_pushnumber(L, ev->canvas.y);
2003
2004 if ((err_code = lua_pcall(L, 6, 0, 0)))
2005 _edje_lua_error(L, err_code);
2006}
2007
2008static void
2009_edje_lua_object_cb_mouse_move(void *data, __UNUSED__ Evas * e, Evas_Object * obj,
2010 void *event_info)
2011{
2012 OBJECT_CB_MACRO("mouse_move");
2013 Evas_Event_Mouse_Move * ev = event_info;
2014 int err_code;
2015
2016 lua_pushnumber(L, ev->buttons);
2017 lua_pushnumber(L, ev->cur.output.x);
2018 lua_pushnumber(L, ev->cur.output.y);
2019 lua_pushnumber(L, ev->cur.canvas.x);
2020 lua_pushnumber(L, ev->cur.canvas.y);
2021
2022 if ((err_code = lua_pcall(L, 6, 0, 0)))
2023 _edje_lua_error(L, err_code);
2024}
2025
2026static void
2027_edje_lua_object_cb_mouse_wheel(void *data, __UNUSED__ Evas * e, Evas_Object * obj,
2028 void *event_info)
2029{
2030 OBJECT_CB_MACRO("mouse_wheel");
2031 Evas_Event_Mouse_Wheel * ev = event_info;
2032 int err_code;
2033
2034 lua_pushnumber(L, ev->z);
2035 lua_pushnumber(L, ev->output.x);
2036 lua_pushnumber(L, ev->output.y);
2037 lua_pushnumber(L, ev->canvas.x);
2038 lua_pushnumber(L, ev->canvas.y);
2039
2040 if ((err_code = lua_pcall(L, 6, 0, 0)))
2041 _edje_lua_error(L, err_code);
2042}
2043
2044static int
2045_edje_lua_object_set_mouse_events(lua_State *L)
2046{
2047 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
2048 obj->mouse_events = lua_toboolean(L, 2);
2049 if (obj->mouse_events)
2050 {
2051 // add all mouse events
2052 evas_object_event_callback_add(obj->eo, EVAS_CALLBACK_MOUSE_IN, _edje_lua_object_cb_mouse_in, L);
2053 evas_object_event_callback_add(obj->eo, EVAS_CALLBACK_MOUSE_OUT, _edje_lua_object_cb_mouse_out, L);
2054 evas_object_event_callback_add(obj->eo, EVAS_CALLBACK_MOUSE_DOWN, _edje_lua_object_cb_mouse_down, L);
2055 evas_object_event_callback_add(obj->eo, EVAS_CALLBACK_MOUSE_UP, _edje_lua_object_cb_mouse_up, L);
2056 evas_object_event_callback_add(obj->eo, EVAS_CALLBACK_MOUSE_MOVE, _edje_lua_object_cb_mouse_move, L);
2057 evas_object_event_callback_add(obj->eo, EVAS_CALLBACK_MOUSE_WHEEL, _edje_lua_object_cb_mouse_wheel, L);
2058 }
2059 else
2060 {
2061 // delete all mouse events
2062 evas_object_event_callback_del(obj->eo, EVAS_CALLBACK_MOUSE_IN, _edje_lua_object_cb_mouse_in);
2063 evas_object_event_callback_del(obj->eo, EVAS_CALLBACK_MOUSE_OUT, _edje_lua_object_cb_mouse_out);
2064 evas_object_event_callback_del(obj->eo, EVAS_CALLBACK_MOUSE_DOWN, _edje_lua_object_cb_mouse_down);
2065 evas_object_event_callback_del(obj->eo, EVAS_CALLBACK_MOUSE_UP, _edje_lua_object_cb_mouse_up);
2066 evas_object_event_callback_del(obj->eo, EVAS_CALLBACK_MOUSE_MOVE, _edje_lua_object_cb_mouse_move);
2067 evas_object_event_callback_del(obj->eo, EVAS_CALLBACK_MOUSE_WHEEL, _edje_lua_object_cb_mouse_wheel);
2068 }
2069 return 0;
2070}
2071
2072const luaL_Reg lObject_set[] = {
2073 {"name", _edje_lua_object_set_name},
2074 {"layer", _edje_lua_object_set_layer},
2075 {"size_hint_min", _edje_lua_object_set_size_hint_min},
2076 {"size_hint_max", _edje_lua_object_set_size_hint_max},
2077 {"size_hint_request", _edje_lua_object_set_size_hint_request},
2078 {"size_hint_aspect", _edje_lua_object_set_size_hint_aspect},
2079 {"size_hint_align", _edje_lua_object_set_size_hint_align},
2080 {"size_hint_weight", _edje_lua_object_set_size_hint_weight},
2081 {"size_hint_padding", _edje_lua_object_set_size_hint_padding},
2082 {"render_op", _edje_lua_object_set_render_op},
2083 {"anti_alias", _edje_lua_object_set_anti_alias},
2084 {"scale", _edje_lua_object_set_scale},
2085 {"color", _edje_lua_object_set_color},
2086 {"color_interpolation", _edje_lua_object_set_color_interpolation},
2087 {"clip", _edje_lua_object_set_clip},
2088 {"pass_events", _edje_lua_object_set_pass_events},
2089 {"repeat_events", _edje_lua_object_set_repeat_events},
2090 {"propagate_events", _edje_lua_object_set_propagate_events},
2091 {"focus", _edje_lua_object_set_focus},
2092 {"pointer_mode", _edje_lua_object_get_pointer_mode},
2093 {"precise_is_inside", _edje_lua_object_get_precise_is_inside},
2094 {"mouse_events", _edje_lua_object_set_mouse_events},
2095 {NULL, NULL} // sentinel
2096};
2097
2098const Edje_Lua_Reg *cRectangle[] = {
2099 &mClass,
2100 &mObject,
2101 NULL // sentinel
2102};
2103
2104const luaL_Reg lImage_get[];
2105
2106const luaL_Reg lImage_set[];
2107
2108const Edje_Lua_Reg mImage = {
2109 lNil,
2110 lImage_get,
2111 lImage_set,
2112 lNil
2113};
2114
2115const Edje_Lua_Reg *cImage[] = {
2116 &mClass,
2117 &mObject,
2118 &mImage,
2119 NULL // sentinel
2120};
2121
2122static int
2123_edje_lua_image_get_size(lua_State *L)
2124{
2125 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mImage);
2126 int w, h;
2127 evas_object_image_size_get(obj->eo, &w, &h);
2128 lua_createtable(L, 2, 0);
2129 lua_pushnumber(L, w);
2130 lua_rawseti(L, -2, 1);
2131 lua_pushnumber(L, h);
2132 lua_rawseti(L, -2, 2);
2133 return 1;
2134};
2135
2136const luaL_Reg lImage_get[] = {
2137 {"size", _edje_lua_image_get_size},
2138 {NULL, NULL} // sentinel
2139};
2140
2141static int
2142_edje_lua_image_set_file(lua_State *L)
2143{
2144 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mImage);
2145 int id = edje_edit_image_id_get(obj->ed->obj, luaL_checkstring(L, 2));
2146 char buf[256];
2147 sprintf(buf, "edje/images/%i", id);
2148 evas_object_image_file_set(obj->eo, obj->ed->path, buf);
2149 return 0;
2150}
2151
2152static int
2153_edje_lua_image_set_fill(lua_State *L)
2154{
2155 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mImage);
2156 luaL_checktype(L, 2, LUA_TTABLE);
2157 lua_rawgeti(L, 2, 1);
2158 lua_rawgeti(L, 2, 2);
2159 lua_rawgeti(L, 2, 3);
2160 lua_rawgeti(L, 2, 4);
2161 evas_object_image_fill_set(obj->eo,
2162 luaL_checkint(L, -4),
2163 luaL_checkint(L, -3),
2164 luaL_checkint(L, -2), luaL_checkint(L, -1));
2165 return 0;
2166}
2167
2168static int
2169_edje_lua_image_set_fill_transform(lua_State *L)
2170{
2171 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mImage);
2172 Edje_Lua_Transform *tar = _edje_lua_checkudata(L, 2, &mTransform);
2173 evas_object_image_fill_transform_set(obj->eo, &(tar->et));
2174 return 0;
2175}
2176
2177static int
2178_edje_lua_image_set_alpha(lua_State *L)
2179{
2180 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject);
2181 evas_object_image_alpha_set(obj->eo, lua_toboolean(L, 2));
2182 return 0;
2183}
2184
2185const luaL_Reg lImage_set[] = {
2186 {"file", _edje_lua_image_set_file},
2187 {"fill", _edje_lua_image_set_fill},
2188 {"fill_transform", _edje_lua_image_set_fill_transform},
2189 {"alpha", _edje_lua_image_set_alpha},
2190 {NULL, NULL} // sentinel
2191};
2192
2193const luaL_Reg lLine_get[];
2194const luaL_Reg lLine_set[];
2195
2196const Edje_Lua_Reg mLine = {
2197 lNil,
2198 lLine_get,
2199 lLine_set,
2200 lNil
2201};
2202
2203const Edje_Lua_Reg *cLine[] = {
2204 &mClass,
2205 &mObject,
2206 &mLine,
2207 NULL // sentinel
2208};
2209
2210static int
2211_edje_lua_line_get_xy(lua_State *L)
2212{
2213 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mLine);
2214 int x1, y1, x2, y2;
2215 evas_object_line_xy_get(obj->eo, &x1, &y1, &x2, &y2);
2216 lua_createtable(L, 4, 0);
2217 lua_pushnumber(L, x1); lua_rawseti(L, -2, 1);
2218 lua_pushnumber(L, y1); lua_rawseti(L, -2, 2);
2219 lua_pushnumber(L, x2); lua_rawseti(L, -2, 3);
2220 lua_pushnumber(L, y2); lua_rawseti(L, -2, 4);
2221 return 1;
2222}
2223
2224const luaL_Reg lLine_get[] = {
2225 {"xy", _edje_lua_line_get_xy},
2226 {NULL, NULL} // sentinel
2227};
2228
2229static int
2230_edje_lua_line_set_xy(lua_State *L)
2231{
2232 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mLine);
2233 luaL_checktype(L, 2, LUA_TTABLE);
2234 lua_rawgeti(L, 2, 1);
2235 lua_rawgeti(L, 2, 2);
2236 lua_rawgeti(L, 2, 3);
2237 lua_rawgeti(L, 2, 4);
2238 evas_object_line_xy_set(obj->eo,
2239 luaL_checkint(L, -4),
2240 luaL_checkint(L, -3),
2241 luaL_checkint(L, -2),
2242 luaL_checkint(L, -1));
2243 return 0;
2244}
2245
2246const luaL_Reg lLine_set[] = {
2247 {"xy", _edje_lua_line_set_xy},
2248 {NULL, NULL} // sentinel
2249};
2250
2251const luaL_Reg lPolygon_fn[];
2252
2253const Edje_Lua_Reg mPolygon = {
2254 lNil,
2255 lNil,
2256 lNil,
2257 lPolygon_fn
2258};
2259
2260const Edje_Lua_Reg *cPolygon[] = {
2261 &mClass,
2262 &mObject,
2263 &mPolygon,
2264 NULL // sentinel
2265};
2266
2267static int
2268_edje_lua_polygon_fn_point_add(lua_State *L)
2269{
2270 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mPolygon);
2271 evas_object_polygon_point_add(obj->eo,
2272 luaL_checknumber(L, 2),
2273 luaL_checknumber(L, 3));
2274 return 0;
2275}
2276
2277static int
2278_edje_lua_polygon_fn_points_clear(lua_State *L)
2279{
2280 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mPolygon);
2281 evas_object_polygon_points_clear(obj->eo);
2282 return 0;
2283}
2284
2285const luaL_Reg lPolygon_fn[] = {
2286 {"point_add", _edje_lua_polygon_fn_point_add},
2287 {"points_clear", _edje_lua_polygon_fn_points_clear},
2288 {NULL, NULL} // sentinel
2289};
2290
2291const luaL_Reg lTable_get[];
2292
2293const luaL_Reg lTable_set[];
2294
2295const luaL_Reg lTable_fn[];
2296
2297const Edje_Lua_Reg mTable = {
2298 lNil,
2299 lTable_get,
2300 lTable_set,
2301 lTable_fn
2302};
2303
2304const Edje_Lua_Reg *cTable[] = {
2305 &mClass,
2306 &mObject,
2307 &mTable,
2308 NULL // sentinel
2309};
2310
2311static int
2312_edje_lua_table_get_homogeneous(lua_State *L)
2313{
2314 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable);
2315 lua_pushnumber(L, evas_object_table_homogeneous_get(obj->eo));
2316 return 1;
2317}
2318
2319static int
2320_edje_lua_table_get_padding(lua_State *L)
2321{
2322 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable);
2323 int x, y;
2324 evas_object_table_padding_get(obj->eo, &x, &y);
2325 lua_createtable(L, 2, 0);
2326 lua_pushnumber(L, x);
2327 lua_rawseti(L, -2, 1);
2328 lua_pushnumber(L, y);
2329 lua_rawseti(L, -2, 2);
2330 return 1;
2331}
2332
2333static int
2334_edje_lua_table_get_align(lua_State *L)
2335{
2336 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable);
2337 double x, y;
2338 evas_object_table_align_get(obj->eo, &x, &y);
2339 lua_createtable(L, 2, 0);
2340 lua_pushnumber(L, x);
2341 lua_rawseti(L, -2, 1);
2342 lua_pushnumber(L, y);
2343 lua_rawseti(L, -2, 2);
2344 return 1;
2345}
2346
2347static int
2348_edje_lua_table_get_col_row_size(lua_State *L)
2349{
2350 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable);
2351 int x, y;
2352 evas_object_table_col_row_size_get(obj->eo, &x, &y);
2353 lua_createtable(L, 2, 0);
2354 lua_pushnumber(L, x);
2355 lua_rawseti(L, -2, 1);
2356 lua_pushnumber(L, y);
2357 lua_rawseti(L, -2, 2);
2358 return 1;
2359}
2360
2361static int
2362_edje_lua_table_get_children(lua_State *L)
2363{
2364 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable);
2365 Eina_List *children = (Eina_List *) evas_object_table_children_get(obj->eo);
2366 Eina_List *l;
2367 Evas_Object *child;
2368 int i = 1;
2369 lua_createtable(L, eina_list_count(children), 0);
2370 EINA_LIST_FOREACH(children, l, child)
2371 {
2372 _edje_lua_get_reg(L, child);
2373 // TODO create object if it does not already exist?
2374 lua_rawseti(L, -2, i++);
2375 }
2376 return 1;
2377}
2378
2379const luaL_Reg lTable_get[] = {
2380 {"homogeneous", _edje_lua_table_get_homogeneous},
2381 {"padding", _edje_lua_table_get_padding},
2382 {"align", _edje_lua_table_get_align},
2383 {"col_row_size", _edje_lua_table_get_col_row_size},
2384 {"children", _edje_lua_table_get_children},
2385 {NULL, NULL} // sentinel
2386};
2387
2388static int
2389_edje_lua_table_set_homogeneous(lua_State *L)
2390{
2391 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable);
2392 evas_object_table_homogeneous_set(obj->eo,
2393 luaL_checkint(L, 2));
2394 return 0;
2395}
2396
2397static int
2398_edje_lua_table_set_padding(lua_State *L)
2399{
2400 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable);
2401 luaL_checktype(L, 2, LUA_TTABLE);
2402 lua_rawgeti(L, 2, 1);
2403 lua_rawgeti(L, 2, 2);
2404 evas_object_table_padding_set(obj->eo,
2405 luaL_checkint(L, -2),
2406 luaL_checkint(L, -1));
2407 return 0;
2408}
2409
2410static int
2411_edje_lua_table_set_align(lua_State *L)
2412{
2413 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable);
2414 luaL_checktype(L, 2, LUA_TTABLE);
2415 lua_rawgeti(L, 2, 1);
2416 lua_rawgeti(L, 2, 2);
2417 evas_object_table_align_set(obj->eo,
2418 luaL_checknumber(L, -2),
2419 luaL_checknumber(L, -1));
2420 return 0;
2421}
2422
2423const luaL_Reg lTable_set[] = {
2424 {"homogeneous", _edje_lua_table_set_homogeneous},
2425 {"padding", _edje_lua_table_set_padding},
2426 {"align", _edje_lua_table_set_align},
2427 {NULL, NULL} // sentinel
2428};
2429
2430static int
2431_edje_lua_table_fn_pack(lua_State *L)
2432{
2433 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable);
2434 Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject);
2435 lua_pushboolean(L,
2436 evas_object_table_pack(obj->eo, tar->eo,
2437 luaL_checkint(L, 3),
2438 luaL_checkint(L, 4),
2439 luaL_checkint(L, 5),
2440 luaL_checkint(L, 6)));
2441 return 1;
2442}
2443
2444static int
2445_edje_lua_table_fn_unpack(lua_State *L)
2446{
2447 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable);
2448 Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject);
2449 lua_pushboolean(L,
2450 evas_object_table_unpack(obj->eo, tar->eo));
2451 return 1;
2452}
2453
2454static int
2455_edje_lua_table_fn_clear(lua_State *L)
2456{
2457 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable);
2458 evas_object_table_clear(obj->eo, lua_toboolean(L, 2));
2459 return 0;
2460}
2461
2462const luaL_Reg lTable_fn[] = {
2463 {"pack", _edje_lua_table_fn_pack},
2464 {"unpack", _edje_lua_table_fn_unpack},
2465 {"clear", _edje_lua_table_fn_clear},
2466 {NULL, NULL} // sentinel
2467};
2468
2469const luaL_Reg lDescription_get[];
2470
2471const luaL_Reg lDescription_set[];
2472
2473const Edje_Lua_Reg mDescription = {
2474 lNil,
2475 lDescription_get,
2476 lDescription_set,
2477 lNil
2478};
2479
2480const Edje_Lua_Reg *cDescription[] = {
2481 &mClass,
2482 &mObject,
2483 &mDescription,
2484 NULL // sentinel
2485};
2486
2487static int
2488_edje_lua_description_get_alignment(lua_State *L)
2489{
2490 Edje_Lua_Edje_Part_Description *obj =
2491 _edje_lua_checkudata(L, 1, &mDescription);
2492 if (!obj->rp->custom) return 0;
2493 lua_createtable(L, 2, 0);
2494 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->align.x));
2495 lua_rawseti(L, -2, 1);
2496 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->align.y));
2497 lua_rawseti(L, -2, 1);
2498 return 1;
2499}
2500
2501static int
2502_edje_lua_description_get_min(lua_State *L)
2503{
2504 Edje_Lua_Edje_Part_Description *obj =
2505 _edje_lua_checkudata(L, 1, &mDescription);
2506 if (!obj->rp->custom) return 0;
2507 lua_createtable(L, 2, 0);
2508 lua_pushnumber(L, obj->rp->custom->description->min.w);
2509 lua_rawseti(L, -2, 1);
2510 lua_pushnumber(L, obj->rp->custom->description->min.h);
2511 lua_rawseti(L, -2, 1);
2512 return 1;
2513}
2514
2515static int
2516_edje_lua_description_get_max(lua_State *L)
2517{
2518 Edje_Lua_Edje_Part_Description *obj =
2519 _edje_lua_checkudata(L, 1, &mDescription);
2520 if (!obj->rp->custom) return 0;
2521 lua_createtable(L, 2, 0);
2522 lua_pushnumber(L, obj->rp->custom->description->max.w);
2523 lua_rawseti(L, -2, 1);
2524 lua_pushnumber(L, obj->rp->custom->description->max.h);
2525 lua_rawseti(L, -2, 1);
2526 return 1;
2527}
2528
2529static int
2530_edje_lua_description_get_step(lua_State *L)
2531{
2532 Edje_Lua_Edje_Part_Description *obj =
2533 _edje_lua_checkudata(L, 1, &mDescription);
2534 if (!obj->rp->custom) return 0;
2535 lua_createtable(L, 2, 0);
2536 lua_pushnumber(L, obj->rp->custom->description->step.x);
2537 lua_rawseti(L, -2, 1);
2538 lua_pushnumber(L, obj->rp->custom->description->step.y);
2539 lua_rawseti(L, -2, 1);
2540 return 1;
2541}
2542
2543static int
2544_edje_lua_description_get_aspect(lua_State *L)
2545{
2546 Edje_Lua_Edje_Part_Description *obj =
2547 _edje_lua_checkudata(L, 1, &mDescription);
2548 if (!obj->rp->custom) return 0;
2549 lua_createtable(L, 2, 0);
2550 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->aspect.min));
2551 lua_rawseti(L, -2, 1);
2552 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->aspect.max));
2553 lua_rawseti(L, -2, 1);
2554 return 1;
2555}
2556
2557static int
2558_edje_lua_description_get_aspect_pref(lua_State *L)
2559{
2560 Edje_Lua_Edje_Part_Description *obj =
2561 _edje_lua_checkudata(L, 1, &mDescription);
2562 if (!obj->rp->custom) return 0;
2563 lua_pushnumber(L, obj->rp->custom->description->aspect.prefer);
2564 return 1;
2565}
2566
2567static int
2568_edje_lua_description_get_color(lua_State *L)
2569{
2570 Edje_Lua_Edje_Part_Description *obj =
2571 _edje_lua_checkudata(L, 1, &mDescription);
2572 /* check whether this part has a "custom" state */
2573 if (!obj->rp->custom) return 0;
2574 lua_createtable(L, 4, 0);
2575 lua_pushnumber(L, obj->rp->custom->description->color.r);
2576 lua_rawseti(L, -2, 1);
2577 lua_pushnumber(L, obj->rp->custom->description->color.g);
2578 lua_rawseti(L, -2, 2);
2579 lua_pushnumber(L, obj->rp->custom->description->color.b);
2580 lua_rawseti(L, -2, 3);
2581 lua_pushnumber(L, obj->rp->custom->description->color.a);
2582 lua_rawseti(L, -2, 4);
2583 return 1;
2584}
2585
2586static int
2587_edje_lua_description_get_color2(lua_State *L)
2588{
2589 Edje_Lua_Edje_Part_Description *obj =
2590 _edje_lua_checkudata(L, 1, &mDescription);
2591 if (!obj->rp->custom) return 0;
2592 lua_createtable(L, 4, 0);
2593 lua_pushnumber(L, obj->rp->custom->description->color2.r);
2594 lua_rawseti(L, -2, 1);
2595 lua_pushnumber(L, obj->rp->custom->description->color2.g);
2596 lua_rawseti(L, -2, 2);
2597 lua_pushnumber(L, obj->rp->custom->description->color2.b);
2598 lua_rawseti(L, -2, 3);
2599 lua_pushnumber(L, obj->rp->custom->description->color2.a);
2600 lua_rawseti(L, -2, 4);
2601 return 1;
2602}
2603
2604static int
2605_edje_lua_description_get_color3(lua_State *L)
2606{
2607 Edje_Lua_Edje_Part_Description *obj =
2608 _edje_lua_checkudata(L, 1, &mDescription);
2609 if (!obj->rp->custom) return 0;
2610 lua_createtable(L, 4, 0);
2611 lua_pushnumber(L, obj->rp->custom->description->color3.r);
2612 lua_rawseti(L, -2, 1);
2613 lua_pushnumber(L, obj->rp->custom->description->color3.g);
2614 lua_rawseti(L, -2, 2);
2615 lua_pushnumber(L, obj->rp->custom->description->color3.b);
2616 lua_rawseti(L, -2, 3);
2617 lua_pushnumber(L, obj->rp->custom->description->color3.a);
2618 lua_rawseti(L, -2, 4);
2619 return 1;
2620}
2621
2622static int
2623_edje_lua_description_get_color_class(lua_State *L)
2624{
2625 Edje_Lua_Edje_Part_Description *obj =
2626 _edje_lua_checkudata(L, 1, &mDescription);
2627 if (!obj->rp->custom) return 0;
2628 lua_pushstring(L, obj->rp->custom->description->color_class);
2629 return 1;
2630}
2631
2632static int
2633_edje_lua_description_get_rel1(lua_State *L)
2634{
2635 Edje_Lua_Edje_Part_Description *obj =
2636 _edje_lua_checkudata(L, 1, &mDescription);
2637 if (!obj->rp->custom) return 0;
2638 lua_createtable(L, 2, 0);
2639 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->rel1.relative_x));
2640 lua_rawseti(L, -2, 1);
2641 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->rel1.relative_y));
2642 lua_rawseti(L, -2, 2);
2643 return 1;
2644}
2645
2646static int
2647_edje_lua_description_get_rel1_to(lua_State *L)
2648{
2649 Edje_Lua_Edje_Part_Description *obj =
2650 _edje_lua_checkudata(L, 1, &mDescription);
2651 if (!obj->rp->custom) return 0;
2652 lua_createtable(L, 2, 0);
2653 lua_pushnumber(L, obj->rp->custom->description->rel1.id_x);
2654 lua_rawseti(L, -2, 1);
2655 lua_pushnumber(L, obj->rp->custom->description->rel1.id_y);
2656 lua_rawseti(L, -2, 2);
2657 return 1;
2658}
2659
2660static int
2661_edje_lua_description_get_rel1_offset(lua_State *L)
2662{
2663 Edje_Lua_Edje_Part_Description *obj =
2664 _edje_lua_checkudata(L, 1, &mDescription);
2665 if (!obj->rp->custom) return 0;
2666 lua_createtable(L, 2, 0);
2667 lua_pushnumber(L, obj->rp->custom->description->rel1.offset_x);
2668 lua_rawseti(L, -2, 1);
2669 lua_pushnumber(L, obj->rp->custom->description->rel1.offset_y);
2670 lua_rawseti(L, -2, 2);
2671 return 1;
2672}
2673
2674static int
2675_edje_lua_description_get_rel2(lua_State *L)
2676{
2677 Edje_Lua_Edje_Part_Description *obj =
2678 _edje_lua_checkudata(L, 1, &mDescription);
2679 if (!obj->rp->custom) return 0;
2680 lua_createtable(L, 2, 0);
2681 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->rel2.relative_x));
2682 lua_rawseti(L, -2, 1);
2683 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->rel2.relative_y));
2684 lua_rawseti(L, -2, 2);
2685 return 1;
2686}
2687
2688static int
2689_edje_lua_description_get_rel2_to(lua_State *L)
2690{
2691 Edje_Lua_Edje_Part_Description *obj =
2692 _edje_lua_checkudata(L, 1, &mDescription);
2693 if (!obj->rp->custom) return 0;
2694 lua_createtable(L, 2, 0);
2695 lua_pushnumber(L, obj->rp->custom->description->rel2.id_x);
2696 lua_rawseti(L, -2, 1);
2697 lua_pushnumber(L, obj->rp->custom->description->rel2.id_y);
2698 lua_rawseti(L, -2, 2);
2699 return 1;
2700}
2701
2702static int
2703_edje_lua_description_get_rel2_offset(lua_State *L)
2704{
2705 Edje_Lua_Edje_Part_Description *obj =
2706 _edje_lua_checkudata(L, 1, &mDescription);
2707 if (!obj->rp->custom) return 0;
2708 lua_createtable(L, 2, 0);
2709 lua_pushnumber(L, obj->rp->custom->description->rel2.offset_x);
2710 lua_rawseti(L, -2, 1);
2711 lua_pushnumber(L, obj->rp->custom->description->rel2.offset_y);
2712 lua_rawseti(L, -2, 2);
2713 return 1;
2714}
2715
2716static int
2717_edje_lua_description_get_image(lua_State *L)
2718{
2719 Edje_Lua_Edje_Part_Description *obj =
2720 _edje_lua_checkudata(L, 1, &mDescription);
2721 if (!obj->rp->custom) return 0;
2722 if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE))
2723 return 0;
2724 // TODO
2725 return 0;
2726}
2727
2728static int
2729_edje_lua_description_get_border(lua_State *L)
2730{
2731 Edje_Lua_Edje_Part_Description *obj =
2732 _edje_lua_checkudata(L, 1, &mDescription);
2733 if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE))
2734 return 0;
2735 if (!obj->rp->custom) return 0;
2736 lua_createtable(L, 4, 0);
2737 lua_pushnumber(L, obj->rp->custom->description->border.l);
2738 lua_rawseti(L, -2, 1);
2739 lua_pushnumber(L, obj->rp->custom->description->border.r);
2740 lua_rawseti(L, -2, 2);
2741 lua_pushnumber(L, obj->rp->custom->description->border.t);
2742 lua_rawseti(L, -2, 3);
2743 lua_pushnumber(L, obj->rp->custom->description->border.b);
2744 lua_rawseti(L, -2, 4);
2745 return 1;
2746}
2747
2748static int
2749_edje_lua_description_get_fill_smooth(lua_State *L)
2750{
2751 Edje_Lua_Edje_Part_Description *obj =
2752 _edje_lua_checkudata(L, 1, &mDescription);
2753 if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE))
2754 return 0;
2755 if (!obj->rp->custom) return 0;
2756 lua_pushboolean(L, obj->rp->custom->description->fill.smooth);
2757 return 1;
2758}
2759
2760static int
2761_edje_lua_description_get_fill_pos(lua_State *L)
2762{
2763 Edje_Lua_Edje_Part_Description *obj =
2764 _edje_lua_checkudata(L, 1, &mDescription);
2765 if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE))
2766 return 0;
2767 if (!obj->rp->custom) return 0;
2768 lua_createtable(L, 4, 0);
2769 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->fill.pos_rel_x));
2770 lua_rawseti(L, -2, 1);
2771 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->fill.pos_rel_y));
2772 lua_rawseti(L, -2, 2);
2773 lua_pushnumber(L, obj->rp->custom->description->fill.pos_abs_x);
2774 lua_rawseti(L, -2, 3);
2775 lua_pushnumber(L, obj->rp->custom->description->fill.pos_abs_y);
2776 lua_rawseti(L, -2, 4);
2777 return 1;
2778}
2779
2780static int
2781_edje_lua_description_get_fill_size(lua_State *L)
2782{
2783 Edje_Lua_Edje_Part_Description *obj =
2784 _edje_lua_checkudata(L, 1, &mDescription);
2785 if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE))
2786 return 0;
2787 if (!obj->rp->custom) return 0;
2788 lua_createtable(L, 4, 0);
2789 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->fill.rel_x));
2790 lua_rawseti(L, -2, 1);
2791 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->fill.rel_y));
2792 lua_rawseti(L, -2, 2);
2793 lua_pushnumber(L, obj->rp->custom->description->fill.abs_x);
2794 lua_rawseti(L, -2, 3);
2795 lua_pushnumber(L, obj->rp->custom->description->fill.abs_y);
2796 lua_rawseti(L, -2, 4);
2797 return 1;
2798}
2799
2800static int
2801_edje_lua_description_get_text(lua_State *L)
2802{
2803 Edje_Lua_Edje_Part_Description *obj =
2804 _edje_lua_checkudata(L, 1, &mDescription);
2805 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)
2806 && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK))
2807 return 0;
2808 if (!obj->rp->custom) return 0;
2809 lua_pushstring(L, obj->rp->custom->description->text.text);
2810 return 1;
2811}
2812
2813static int
2814_edje_lua_description_get_text_class(lua_State *L)
2815{
2816 Edje_Lua_Edje_Part_Description *obj =
2817 _edje_lua_checkudata(L, 1, &mDescription);
2818 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)
2819 && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK))
2820 return 0;
2821 if (!obj->rp->custom) return 0;
2822 lua_pushstring(L, obj->rp->custom->description->text.text_class);
2823 return 1;
2824}
2825
2826static int
2827_edje_lua_description_get_text_font(lua_State *L)
2828{
2829 Edje_Lua_Edje_Part_Description *obj =
2830 _edje_lua_checkudata(L, 1, &mDescription);
2831 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT))
2832 return 0;
2833 if (!obj->rp->custom) return 0;
2834 lua_pushstring(L, obj->rp->custom->description->text.text_class);
2835 return 1;
2836}
2837
2838static int
2839_edje_lua_description_get_text_style(lua_State *L)
2840{
2841 Edje_Lua_Edje_Part_Description *obj =
2842 _edje_lua_checkudata(L, 1, &mDescription);
2843 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK))
2844 return 0;
2845 if (!obj->rp->custom) return 0;
2846 lua_pushstring(L, obj->rp->custom->description->text.style);
2847 return 1;
2848}
2849
2850static int
2851_edje_lua_description_get_text_size(lua_State *L)
2852{
2853 Edje_Lua_Edje_Part_Description *obj =
2854 _edje_lua_checkudata(L, 1, &mDescription);
2855 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT))
2856 return 0;
2857 if (!obj->rp->custom) return 0;
2858 lua_pushnumber(L, obj->rp->custom->description->text.size);
2859 return 1;
2860}
2861
2862static int
2863_edje_lua_description_get_text_fit(lua_State *L)
2864{
2865 Edje_Lua_Edje_Part_Description *obj =
2866 _edje_lua_checkudata(L, 1, &mDescription);
2867 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT))
2868 return 0;
2869 if (!obj->rp->custom) return 0;
2870 lua_createtable(L, 2, 0);
2871 lua_pushboolean(L, obj->rp->custom->description->text.fit_x);
2872 lua_rawseti(L, -2, 1);
2873 lua_pushboolean(L, obj->rp->custom->description->text.fit_y);
2874 lua_rawseti(L, -2, 2);
2875 return 1;
2876}
2877
2878static int
2879_edje_lua_description_get_text_min(lua_State *L)
2880{
2881 Edje_Lua_Edje_Part_Description *obj =
2882 _edje_lua_checkudata(L, 1, &mDescription);
2883 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)
2884 && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK))
2885 return 0;
2886 if (!obj->rp->custom) return 0;
2887 lua_createtable(L, 2, 0);
2888 lua_pushnumber(L, obj->rp->custom->description->text.min_x);
2889 lua_rawseti(L, -2, 1);
2890 lua_pushnumber(L, obj->rp->custom->description->text.min_y);
2891 lua_rawseti(L, -2, 2);
2892 return 1;
2893}
2894
2895static int
2896_edje_lua_description_get_text_max(lua_State *L)
2897{
2898 Edje_Lua_Edje_Part_Description *obj =
2899 _edje_lua_checkudata(L, 1, &mDescription);
2900 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)
2901 && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK))
2902 return 0;
2903 if (!obj->rp->custom) return 0;
2904 lua_createtable(L, 2, 0);
2905 lua_pushnumber(L, obj->rp->custom->description->text.max_x);
2906 lua_rawseti(L, -2, 1);
2907 lua_pushnumber(L, obj->rp->custom->description->text.max_y);
2908 lua_rawseti(L, -2, 2);
2909 return 1;
2910}
2911
2912static int
2913_edje_lua_description_get_text_align(lua_State *L)
2914{
2915 Edje_Lua_Edje_Part_Description *obj =
2916 _edje_lua_checkudata(L, 1, &mDescription);
2917 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT))
2918 return 0;
2919 if (!obj->rp->custom) return 0;
2920 lua_createtable(L, 2, 0);
2921 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->text.align.x));
2922 lua_rawseti(L, -2, 1);
2923 lua_pushnumber(L, TO_DOUBLE(obj->rp->custom->description->text.align.y));
2924 lua_rawseti(L, -2, 2);
2925 return 1;
2926}
2927
2928static int
2929_edje_lua_description_get_visible(lua_State *L)
2930{
2931 Edje_Lua_Edje_Part_Description *obj =
2932 _edje_lua_checkudata(L, 1, &mDescription);
2933 if (!obj->rp->custom) return 0;
2934 lua_pushboolean(L, obj->rp->custom->description->visible);
2935 return 1;
2936}
2937
2938const luaL_Reg lDescription_get[] = {
2939 {"alignment", _edje_lua_description_get_alignment},
2940 {"min", _edje_lua_description_get_min},
2941 {"max", _edje_lua_description_get_max},
2942 {"step", _edje_lua_description_get_step},
2943 {"aspect", _edje_lua_description_get_aspect},
2944 {"aspect_pref", _edje_lua_description_get_aspect_pref},
2945 {"color", _edje_lua_description_get_color},
2946 {"color2", _edje_lua_description_get_color2},
2947 {"color3", _edje_lua_description_get_color3},
2948 {"color_class", _edje_lua_description_get_color_class},
2949 {"rel1", _edje_lua_description_get_rel1},
2950 {"rel1_to", _edje_lua_description_get_rel1_to},
2951 {"rel1_offset", _edje_lua_description_get_rel1_offset},
2952 {"rel2", _edje_lua_description_get_rel2},
2953 {"rel2_to", _edje_lua_description_get_rel2_to},
2954 {"rel2_offset", _edje_lua_description_get_rel2_offset},
2955 {"image", _edje_lua_description_get_image},
2956 {"border", _edje_lua_description_get_border},
2957 {"fill_smooth", _edje_lua_description_get_fill_smooth},
2958 {"fill_pos", _edje_lua_description_get_fill_pos},
2959 {"fill_size", _edje_lua_description_get_fill_size},
2960 {"text", _edje_lua_description_get_text},
2961 {"text_class", _edje_lua_description_get_text_class},
2962 {"text_font", _edje_lua_description_get_text_font},
2963 {"text_style", _edje_lua_description_get_text_style},
2964 {"text_size", _edje_lua_description_get_text_size},
2965 {"text_fit", _edje_lua_description_get_text_fit},
2966 {"text_min", _edje_lua_description_get_text_min},
2967 {"text_max", _edje_lua_description_get_text_max},
2968 {"text_align", _edje_lua_description_get_text_align},
2969 {"visible", _edje_lua_description_get_visible},
2970 {NULL, NULL} // sentinel
2971};
2972
2973static int
2974_edje_lua_description_set_alignment(lua_State *L)
2975{
2976 Edje_Lua_Edje_Part_Description *obj =
2977 _edje_lua_checkudata(L, 1, &mDescription);
2978 if (!obj->rp->custom) return 0;
2979 luaL_checktype(L, 2, LUA_TTABLE);
2980 lua_rawgeti(L, 2, 1);
2981 lua_rawgeti(L, 2, 2);
2982 obj->rp->custom->description->align.x = FROM_DOUBLE(luaL_checknumber(L, -2));
2983 obj->rp->custom->description->align.y = FROM_DOUBLE(luaL_checknumber(L, -1));
2984 return 0;
2985}
2986
2987static int
2988_edje_lua_description_set_min(lua_State *L)
2989{
2990 Edje_Lua_Edje_Part_Description *obj =
2991 _edje_lua_checkudata(L, 1, &mDescription);
2992 if (!obj->rp->custom) return 0;
2993 lua_rawgeti(L, 2, 1);
2994 lua_rawgeti(L, 2, 2);
2995 obj->rp->custom->description->min.w = luaL_checkint(L, -2);
2996 obj->rp->custom->description->min.h = luaL_checkint(L, -1);
2997 return 0;
2998}
2999
3000static int
3001_edje_lua_description_set_max(lua_State *L)
3002{
3003 Edje_Lua_Edje_Part_Description *obj =
3004 _edje_lua_checkudata(L, 1, &mDescription);
3005 if (!obj->rp->custom) return 0;
3006 lua_rawgeti(L, 2, 1);
3007 lua_rawgeti(L, 2, 2);
3008 obj->rp->custom->description->max.w = luaL_checkint(L, -2);
3009 obj->rp->custom->description->max.h = luaL_checkint(L, -1);
3010 return 0;
3011}
3012
3013static int
3014_edje_lua_description_set_step(lua_State *L)
3015{
3016 Edje_Lua_Edje_Part_Description *obj =
3017 _edje_lua_checkudata(L, 1, &mDescription);
3018 if (!obj->rp->custom) return 0;
3019 lua_rawgeti(L, 2, 1);
3020 lua_rawgeti(L, 2, 2);
3021 obj->rp->custom->description->step.x = luaL_checkint(L, -2);
3022 obj->rp->custom->description->step.y = luaL_checkint(L, -1);
3023 return 0;
3024}
3025
3026static int
3027_edje_lua_description_set_aspect(lua_State *L)
3028{
3029 Edje_Lua_Edje_Part_Description *obj =
3030 _edje_lua_checkudata(L, 1, &mDescription);
3031 if (!obj->rp->custom) return 0;
3032 lua_rawgeti(L, 2, 1);
3033 lua_rawgeti(L, 2, 2);
3034 obj->rp->custom->description->aspect.min = FROM_DOUBLE(luaL_checknumber(L, -2));
3035 obj->rp->custom->description->aspect.max = FROM_DOUBLE(luaL_checknumber(L, -1));
3036 return 0;
3037
3038}
3039
3040static int
3041_edje_lua_description_set_aspect_pref(lua_State *L)
3042{
3043 Edje_Lua_Edje_Part_Description *obj =
3044 _edje_lua_checkudata(L, 1, &mDescription);
3045 if (!obj->rp->custom) return 0;
3046 obj->rp->custom->description->aspect.prefer = luaL_checknumber(L, 2);
3047 return 0;
3048
3049}
3050
3051static int
3052_edje_lua_description_set_color(lua_State *L)
3053{
3054 Edje_Lua_Edje_Part_Description *obj =
3055 _edje_lua_checkudata(L, 1, &mDescription);
3056 if (!obj->rp->custom) return 0;
3057 luaL_checktype(L, 2, LUA_TTABLE);
3058 lua_rawgeti(L, 2, 1);
3059 lua_rawgeti(L, 2, 2);
3060 lua_rawgeti(L, 2, 3);
3061 lua_rawgeti(L, 2, 4);
3062 obj->rp->custom->description->color.r = luaL_checkint(L, -4);
3063 obj->rp->custom->description->color.g = luaL_checkint(L, -3);
3064 obj->rp->custom->description->color.b = luaL_checkint(L, -2);
3065 obj->rp->custom->description->color.a = luaL_checkint(L, -1);
3066 return 0;
3067}
3068
3069static int
3070_edje_lua_description_set_color2(lua_State *L)
3071{
3072 Edje_Lua_Edje_Part_Description *obj =
3073 _edje_lua_checkudata(L, 1, &mDescription);
3074 if (!obj->rp->custom) return 0;
3075 luaL_checktype(L, 2, LUA_TTABLE);
3076 lua_rawgeti(L, 2, 1);
3077 lua_rawgeti(L, 2, 2);
3078 lua_rawgeti(L, 2, 3);
3079 lua_rawgeti(L, 2, 4);
3080 obj->rp->custom->description->color2.r = luaL_checkint(L, -4);
3081 obj->rp->custom->description->color2.g = luaL_checkint(L, -3);
3082 obj->rp->custom->description->color2.b = luaL_checkint(L, -2);
3083 obj->rp->custom->description->color2.a = luaL_checkint(L, -1);
3084 return 0;
3085}
3086
3087static int
3088_edje_lua_description_set_color3(lua_State *L)
3089{
3090 Edje_Lua_Edje_Part_Description *obj =
3091 _edje_lua_checkudata(L, 1, &mDescription);
3092 if (!obj->rp->custom) return 0;
3093 luaL_checktype(L, 2, LUA_TTABLE);
3094 lua_rawgeti(L, 2, 1);
3095 lua_rawgeti(L, 2, 2);
3096 lua_rawgeti(L, 2, 3);
3097 lua_rawgeti(L, 2, 4);
3098 obj->rp->custom->description->color3.r = luaL_checkint(L, -4);
3099 obj->rp->custom->description->color3.g = luaL_checkint(L, -3);
3100 obj->rp->custom->description->color3.b = luaL_checkint(L, -2);
3101 obj->rp->custom->description->color3.a = luaL_checkint(L, -1);
3102 return 0;
3103}
3104
3105static int
3106_edje_lua_description_set_color_class(lua_State *L)
3107{
3108 Edje_Lua_Edje_Part_Description *obj =
3109 _edje_lua_checkudata(L, 1, &mDescription);
3110 if (!obj->rp->custom) return 0;
3111 obj->rp->custom->description->color_class = (char *)luaL_checkstring(L, 2);
3112 return 0;
3113}
3114
3115static int
3116_edje_lua_description_set_rel1(lua_State *L)
3117{
3118 Edje_Lua_Edje_Part_Description *obj =
3119 _edje_lua_checkudata(L, 1, &mDescription);
3120 if (!obj->rp->custom) return 0;
3121 luaL_checktype(L, 2, LUA_TTABLE);
3122 lua_rawgeti(L, 2, 1);
3123 lua_rawgeti(L, 2, 2);
3124 obj->rp->custom->description->rel1.relative_x = FROM_DOUBLE(luaL_checknumber(L, -2));
3125 obj->rp->custom->description->rel1.relative_y = FROM_DOUBLE(luaL_checknumber(L, -1));
3126 return 0;
3127}
3128
3129static int
3130_edje_lua_description_set_rel1_to(lua_State *L)
3131{
3132 Edje_Lua_Edje_Part_Description *obj =
3133 _edje_lua_checkudata(L, 1, &mDescription);
3134 if (!obj->rp->custom) return 0;
3135 luaL_checktype(L, 2, LUA_TTABLE);
3136 lua_rawgeti(L, 2, 1);
3137 lua_rawgeti(L, 2, 2);
3138 obj->rp->custom->description->rel1.id_x = luaL_checknumber(L, -2);
3139 obj->rp->custom->description->rel1.id_y = luaL_checknumber(L, -1);
3140 if (obj->rp->param1.description->rel1.id_x >= 0)
3141 obj->rp->param1.rel1_to_x = obj->ed->table_parts[obj->rp->param1.description->rel1.id_x % obj->ed->table_parts_size];
3142 if (obj->rp->param1.description->rel1.id_y >= 0)
3143 obj->rp->param1.rel1_to_y = obj->ed->table_parts[obj->rp->param1.description->rel1.id_y % obj->ed->table_parts_size];
3144 return 0;
3145}
3146
3147static int
3148_edje_lua_description_set_rel1_offset(lua_State *L)
3149{
3150 Edje_Lua_Edje_Part_Description *obj =
3151 _edje_lua_checkudata(L, 1, &mDescription);
3152 if (!obj->rp->custom) return 0;
3153 luaL_checktype(L, 2, LUA_TTABLE);
3154 lua_rawgeti(L, 2, 1);
3155 lua_rawgeti(L, 2, 2);
3156 obj->rp->custom->description->rel1.offset_x = luaL_checkint(L, -2);
3157 obj->rp->custom->description->rel1.offset_y = luaL_checkint(L, -1);
3158 return 0;
3159}
3160
3161static int
3162_edje_lua_description_set_rel2(lua_State *L)
3163{
3164 Edje_Lua_Edje_Part_Description *obj =
3165 _edje_lua_checkudata(L, 1, &mDescription);
3166 if (!obj->rp->custom) return 0;
3167 luaL_checktype(L, 2, LUA_TTABLE);
3168 lua_rawgeti(L, 2, 1);
3169 lua_rawgeti(L, 2, 2);
3170 obj->rp->custom->description->rel2.relative_x = FROM_DOUBLE(luaL_checknumber(L, -2));
3171 obj->rp->custom->description->rel2.relative_y = FROM_DOUBLE(luaL_checknumber(L, -1));
3172 return 0;
3173}
3174
3175static int
3176_edje_lua_description_set_rel2_to(lua_State *L)
3177{
3178 Edje_Lua_Edje_Part_Description *obj =
3179 _edje_lua_checkudata(L, 1, &mDescription);
3180 if (!obj->rp->custom) return 0;
3181 luaL_checktype(L, 2, LUA_TTABLE);
3182 lua_rawgeti(L, 2, 1);
3183 lua_rawgeti(L, 2, 2);
3184 obj->rp->custom->description->rel2.id_x = luaL_checknumber(L, -2);
3185 obj->rp->custom->description->rel2.id_y = luaL_checknumber(L, -1);
3186 if (obj->rp->param1.description->rel2.id_x >= 0)
3187 obj->rp->param1.rel2_to_x = obj->ed->table_parts[obj->rp->param1.description->rel2.id_x % obj->ed->table_parts_size];
3188 if (obj->rp->param1.description->rel2.id_y >= 0)
3189 obj->rp->param1.rel2_to_y = obj->ed->table_parts[obj->rp->param1.description->rel2.id_y % obj->ed->table_parts_size];
3190 return 0;
3191}
3192
3193static int
3194_edje_lua_description_set_rel2_offset(lua_State *L)
3195{
3196 Edje_Lua_Edje_Part_Description *obj =
3197 _edje_lua_checkudata(L, 1, &mDescription);
3198 if (!obj->rp->custom) return 0;
3199 luaL_checktype(L, 2, LUA_TTABLE);
3200 lua_rawgeti(L, 2, 1);
3201 lua_rawgeti(L, 2, 2);
3202 obj->rp->custom->description->rel2.offset_x = luaL_checkint(L, -2);
3203 obj->rp->custom->description->rel2.offset_y = luaL_checkint(L, -1);
3204 return 0;
3205}
3206
3207static int
3208_edje_lua_description_set_image(lua_State *L)
3209{
3210 Edje_Lua_Edje_Part_Description *obj =
3211 _edje_lua_checkudata(L, 1, &mDescription);
3212 if (!obj->rp->custom) return 0;
3213 if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE))
3214 return 0;
3215 obj->rp->custom->description->image.id =
3216 edje_edit_image_id_get(obj->ed->obj, (char *)luaL_checkstring(L, 2));
3217 return 0;
3218}
3219
3220static int
3221_edje_lua_description_set_border(lua_State *L)
3222{
3223 Edje_Lua_Edje_Part_Description *obj =
3224 _edje_lua_checkudata(L, 1, &mDescription);
3225 if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE))
3226 return 0;
3227 if (!obj->rp->custom) return 0;
3228 luaL_checktype(L, 2, LUA_TTABLE);
3229 lua_rawgeti(L, 2, 1);
3230 lua_rawgeti(L, 2, 2);
3231 lua_rawgeti(L, 2, 3);
3232 lua_rawgeti(L, 2, 4);
3233 obj->rp->custom->description->border.l = luaL_checkint(L, -2);
3234 obj->rp->custom->description->border.r = luaL_checkint(L, -1);
3235 obj->rp->custom->description->border.t = luaL_checkint(L, -2);
3236 obj->rp->custom->description->border.b = luaL_checkint(L, -1);
3237 return 0;
3238}
3239
3240static int
3241_edje_lua_description_set_fill_smooth(lua_State *L)
3242{
3243 Edje_Lua_Edje_Part_Description *obj =
3244 _edje_lua_checkudata(L, 1, &mDescription);
3245 if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE))
3246 return 0;
3247 if (!obj->rp->custom) return 0;
3248 obj->rp->custom->description->fill.smooth = lua_toboolean(L, 2);
3249 return 0;
3250}
3251
3252static int
3253_edje_lua_description_set_fill_pos(lua_State *L)
3254{
3255 Edje_Lua_Edje_Part_Description *obj =
3256 _edje_lua_checkudata(L, 1, &mDescription);
3257 if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE))
3258 return 0;
3259 if (!obj->rp->custom) return 0;
3260 luaL_checktype(L, 2, LUA_TTABLE);
3261 lua_rawgeti(L, 2, 1);
3262 lua_rawgeti(L, 2, 2);
3263 lua_rawgeti(L, 2, 3);
3264 lua_rawgeti(L, 2, 4);
3265 obj->rp->custom->description->fill.pos_rel_x = luaL_checkint(L, -2);
3266 obj->rp->custom->description->fill.pos_rel_y = luaL_checkint(L, -1);
3267 obj->rp->custom->description->fill.pos_abs_x = luaL_checkint(L, -2);
3268 obj->rp->custom->description->fill.pos_abs_y = luaL_checkint(L, -1);
3269 return 0;
3270}
3271
3272static int
3273_edje_lua_description_set_fill_size(lua_State *L)
3274{
3275 Edje_Lua_Edje_Part_Description *obj =
3276 _edje_lua_checkudata(L, 1, &mDescription);
3277 if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE))
3278 return 0;
3279 if (!obj->rp->custom) return 0;
3280 luaL_checktype(L, 2, LUA_TTABLE);
3281 lua_rawgeti(L, 2, 1);
3282 lua_rawgeti(L, 2, 2);
3283 lua_rawgeti(L, 2, 3);
3284 lua_rawgeti(L, 2, 4);
3285 obj->rp->custom->description->fill.rel_x = luaL_checkint(L, -2);
3286 obj->rp->custom->description->fill.rel_y = luaL_checkint(L, -1);
3287 obj->rp->custom->description->fill.abs_x = luaL_checkint(L, -2);
3288 obj->rp->custom->description->fill.abs_y = luaL_checkint(L, -1);
3289 return 0;
3290}
3291
3292static int
3293_edje_lua_description_set_text(lua_State *L)
3294{
3295 Edje_Lua_Edje_Part_Description *obj =
3296 _edje_lua_checkudata(L, 1, &mDescription);
3297 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)
3298 && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK))
3299 return 0;
3300 if (!obj->rp->custom) return 0;
3301 obj->rp->custom->description->text.text = (char *)luaL_checkstring(L, 2);
3302 return 0;
3303}
3304
3305static int
3306_edje_lua_description_set_text_class(lua_State *L)
3307{
3308 Edje_Lua_Edje_Part_Description *obj =
3309 _edje_lua_checkudata(L, 1, &mDescription);
3310 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)
3311 && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK))
3312 return 0;
3313 if (!obj->rp->custom) return 0;
3314 obj->rp->custom->description->text.text_class =
3315 (char *)luaL_checkstring(L, 2);
3316 return 0;
3317}
3318
3319static int
3320_edje_lua_description_set_text_font(lua_State *L)
3321{
3322 Edje_Lua_Edje_Part_Description *obj =
3323 _edje_lua_checkudata(L, 1, &mDescription);
3324 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT))
3325 return 0;
3326 if (!obj->rp->custom) return 0;
3327 obj->rp->custom->description->text.font = (char *)luaL_checkstring(L, 2);
3328 return 0;
3329}
3330
3331static int
3332_edje_lua_description_set_text_style(lua_State *L)
3333{
3334 Edje_Lua_Edje_Part_Description *obj =
3335 _edje_lua_checkudata(L, 1, &mDescription);
3336 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK))
3337 return 0;
3338 if (!obj->rp->custom) return 0;
3339 obj->rp->custom->description->text.style = (char *)luaL_checkstring(L, 2);
3340 return 0;
3341}
3342
3343static int
3344_edje_lua_description_set_text_size(lua_State *L)
3345{
3346 Edje_Lua_Edje_Part_Description *obj =
3347 _edje_lua_checkudata(L, 1, &mDescription);
3348 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT))
3349 return 0;
3350 if (!obj->rp->custom) return 0;
3351 obj->rp->custom->description->text.size = luaL_checkint(L, 2);
3352 return 0;
3353}
3354
3355static int
3356_edje_lua_description_set_text_fit(lua_State *L)
3357{
3358 Edje_Lua_Edje_Part_Description *obj =
3359 _edje_lua_checkudata(L, 1, &mDescription);
3360 if (!obj->rp->custom) return 0;
3361 luaL_checktype(L, 2, LUA_TTABLE);
3362 lua_rawgeti(L, 2, 1);
3363 lua_rawgeti(L, 2, 2);
3364 obj->rp->custom->description->text.fit_x = lua_toboolean(L, -2);
3365 obj->rp->custom->description->text.fit_y = lua_toboolean(L, -1);
3366 return 0;
3367}
3368
3369static int
3370_edje_lua_description_set_text_min(lua_State *L)
3371{
3372 Edje_Lua_Edje_Part_Description *obj =
3373 _edje_lua_checkudata(L, 1, &mDescription);
3374 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)
3375 && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK))
3376 return 0;
3377 if (!obj->rp->custom) return 0;
3378 luaL_checktype(L, 2, LUA_TTABLE);
3379 lua_rawgeti(L, 2, 1);
3380 lua_rawgeti(L, 2, 2);
3381 obj->rp->custom->description->text.min_x = luaL_checkint(L, -2);
3382 obj->rp->custom->description->text.min_y = luaL_checkint(L, -1);
3383 return 0;
3384}
3385
3386static int
3387_edje_lua_description_set_text_max(lua_State *L)
3388{
3389 Edje_Lua_Edje_Part_Description *obj =
3390 _edje_lua_checkudata(L, 1, &mDescription);
3391 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)
3392 && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK))
3393 return 0;
3394 if (!obj->rp->custom) return 0;
3395 luaL_checktype(L, 2, LUA_TTABLE);
3396 lua_rawgeti(L, 2, 1);
3397 lua_rawgeti(L, 2, 2);
3398 obj->rp->custom->description->text.max_x = luaL_checkint(L, -2);
3399 obj->rp->custom->description->text.max_y = luaL_checkint(L, -1);
3400 return 0;
3401}
3402
3403static int
3404_edje_lua_description_set_text_align(lua_State *L)
3405{
3406 Edje_Lua_Edje_Part_Description *obj =
3407 _edje_lua_checkudata(L, 1, &mDescription);
3408 if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT))
3409 return 0;
3410 if (!obj->rp->custom) return 0;
3411 luaL_checktype(L, 2, LUA_TTABLE);
3412 lua_rawgeti(L, 2, 1);
3413 lua_rawgeti(L, 2, 2);
3414 obj->rp->custom->description->text.align.x = FROM_DOUBLE(luaL_checknumber(L, -2));
3415 obj->rp->custom->description->text.align.y = FROM_DOUBLE(luaL_checknumber(L, -1));
3416 return 0;
3417}
3418
3419static int
3420_edje_lua_description_set_visible(lua_State *L)
3421{
3422 Edje_Lua_Edje_Part_Description *obj =
3423 _edje_lua_checkudata(L, 1, &mDescription);
3424 if (!obj->rp->custom) return 0;
3425 obj->rp->custom->description->visible = lua_toboolean(L, 2);
3426 return 0;
3427}
3428
3429const luaL_Reg lDescription_set[] = {
3430 {"alignment", _edje_lua_description_set_alignment},
3431 {"min", _edje_lua_description_set_min},
3432 {"max", _edje_lua_description_set_max},
3433 {"step", _edje_lua_description_set_step},
3434 {"aspect", _edje_lua_description_set_aspect},
3435 {"aspect_pref", _edje_lua_description_set_aspect_pref},
3436 {"color", _edje_lua_description_set_color},
3437 {"color2", _edje_lua_description_set_color2},
3438 {"color3", _edje_lua_description_set_color3},
3439 {"color_class", _edje_lua_description_set_color_class},
3440 {"rel1", _edje_lua_description_set_rel1},
3441 {"rel1_to", _edje_lua_description_set_rel1_to},
3442 {"rel1_offset", _edje_lua_description_set_rel1_offset},
3443 {"rel2", _edje_lua_description_set_rel2},
3444 {"rel2_to", _edje_lua_description_set_rel2_to},
3445 {"rel2_offset", _edje_lua_description_set_rel2_offset},
3446 {"image", _edje_lua_description_set_image},
3447 {"border", _edje_lua_description_set_border},
3448 {"fill_smooth", _edje_lua_description_set_fill_smooth},
3449 {"fill_pos", _edje_lua_description_set_fill_pos},
3450 {"fill_size", _edje_lua_description_set_fill_size},
3451 {"text", _edje_lua_description_set_text},
3452 {"text_class", _edje_lua_description_set_text_class},
3453 {"text_font", _edje_lua_description_set_text_font},
3454 {"text_style", _edje_lua_description_set_text_style},
3455 {"text_size", _edje_lua_description_set_text_size},
3456 {"text_fit", _edje_lua_description_set_text_fit},
3457 {"text_min", _edje_lua_description_set_text_min},
3458 {"text_max", _edje_lua_description_set_text_max},
3459 {"text_align", _edje_lua_description_set_text_align},
3460 {"visible", _edje_lua_description_set_visible},
3461 {NULL, NULL} // sentinel
3462};
3463
3464const luaL_Reg lPart_get[];
3465
3466const luaL_Reg lPart_set[];
3467
3468const luaL_Reg lPart_fn[];
3469
3470const Edje_Lua_Reg mPart = {
3471 lNil,
3472 lPart_get,
3473 lPart_set,
3474 lPart_fn
3475};
3476
3477static void
3478_edje_lua_edje_part_del_cb(void *data, __UNUSED__ Evas * e, Evas_Object * obj,
3479 __UNUSED__ void *event_info)
3480{
3481 //printf("_edje_lua_object_delete_cb\n");
3482 lua_State *L = data;
3483 _edje_lua_get_reg(L, obj);
3484 Edje_Lua_Edje_Part_Object *udata = _edje_lua_checkudata(L, -1, &mPart);
3485 lua_pop(L, 1);
3486 _edje_lua_free_reg(L, udata); // created in _edje_lua_group_mt_index
3487 _edje_lua_free_reg(L, obj); // created in _edje_lua_group_mt_index
3488}
3489
3490const Edje_Lua_Reg *cPart[] = {
3491 &mClass,
3492 &mObject,
3493 &mPart,
3494 NULL // sentinel
3495};
3496
3497static int
3498_edje_lua_part_get_swallow(lua_State *L)
3499{
3500 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3501 Evas_Object *swa = edje_object_part_swallow_get(obj->ed->obj, obj->key);
3502 _edje_lua_get_reg(L, swa);
3503 // TODO create object if it does not already exist?
3504 return 1;
3505}
3506
3507static int
3508_edje_lua_part_get_type(lua_State *L)
3509{
3510 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3511 lua_pushnumber(L, edje_edit_part_type_get(obj->ed->obj, obj->key));
3512 return 1;
3513}
3514
3515static int
3516_edje_lua_part_get_effect(lua_State *L)
3517{
3518 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3519 lua_pushnumber(L, edje_edit_part_effect_get(obj->ed->obj, obj->key));
3520 return 1;
3521}
3522
3523static int
3524_edje_lua_part_get_mouse_events(lua_State *L)
3525{
3526 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3527 lua_pushboolean(L, edje_edit_part_mouse_events_get(obj->ed->obj, obj->key));
3528 return 1;
3529}
3530
3531static int
3532_edje_lua_part_get_repeat_events(lua_State *L)
3533{
3534 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3535 lua_pushboolean(L, edje_edit_part_repeat_events_get(obj->ed->obj, obj->key));
3536 return 1;
3537}
3538
3539static int
3540_edje_lua_part_get_states_list(lua_State *L)
3541{
3542 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3543 Eina_List *slist = edje_edit_part_states_list_get(obj->ed->obj, obj->key);
3544 Eina_List *ilist;
3545 lua_newtable(L);
3546 int i = 1;
3547 for (ilist = slist; ilist; ilist = eina_list_next(ilist))
3548 {
3549 lua_pushstring(L, eina_list_data_get(ilist));
3550 lua_rawseti(L, -2, i++);
3551 }
3552 edje_edit_string_list_free(slist);
3553 return 1;
3554};
3555
3556static int
3557_edje_lua_part_get_state(lua_State *L)
3558{
3559 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3560 const char *state;
3561 double val;
3562 state = edje_object_part_state_get(obj->ed->obj, obj->key, &val);
3563 lua_createtable(L, 2, 0);
3564 lua_pushstring(L, state);
3565 lua_rawseti(L, -2, 1);
3566 lua_pushnumber(L, val);
3567 lua_rawseti(L, -2, 2);
3568 return 1;
3569};
3570
3571static int
3572_edje_lua_part_get_text(lua_State *L)
3573{
3574 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3575 lua_pushstring(L, edje_object_part_text_get(obj->ed->obj, obj->key));
3576 return 1;
3577};
3578
3579static int
3580_edje_lua_part_get_text_selection(lua_State *L)
3581{
3582 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3583 lua_pushstring(L,
3584 edje_object_part_text_selection_get(obj->ed->obj, obj->key));
3585 return 1;
3586};
3587
3588static int
3589_edje_lua_part_get_drag_dir(lua_State *L)
3590{
3591 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3592 lua_pushnumber(L, edje_object_part_drag_dir_get(obj->ed->obj, obj->key));
3593 return 1;
3594}
3595
3596static int
3597_edje_lua_part_get_drag_value(lua_State *L)
3598{
3599 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3600 double dx, dy;
3601 edje_object_part_drag_value_get(obj->ed->obj, obj->key, &dx, &dy);
3602 lua_createtable(L, 2, 0);
3603 lua_pushnumber(L, dx);
3604 lua_rawseti(L, -2, 1);
3605 lua_pushnumber(L, dy);
3606 lua_rawseti(L, -2, 2);
3607 return 1;
3608}
3609
3610static int
3611_edje_lua_part_get_drag_size(lua_State *L)
3612{
3613 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3614 double dx, dy;
3615 edje_object_part_drag_size_get(obj->ed->obj, obj->key, &dx, &dy);
3616 lua_createtable(L, 2, 0);
3617 lua_pushnumber(L, dx);
3618 lua_rawseti(L, -2, 1);
3619 lua_pushnumber(L, dy);
3620 lua_rawseti(L, -2, 2);
3621 return 1;
3622}
3623
3624static int
3625_edje_lua_part_get_drag_step(lua_State *L)
3626{
3627 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3628 double dx, dy;
3629 edje_object_part_drag_step_get(obj->ed->obj, obj->key, &dx, &dy);
3630 lua_createtable(L, 2, 0);
3631 lua_pushnumber(L, dx);
3632 lua_rawseti(L, -2, 1);
3633 lua_pushnumber(L, dy);
3634 lua_rawseti(L, -2, 2);
3635 return 1;
3636}
3637
3638static int
3639_edje_lua_part_get_drag_page(lua_State *L)
3640{
3641 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3642 double dx, dy;
3643 edje_object_part_drag_page_get(obj->ed->obj, obj->key, &dx, &dy);
3644 lua_createtable(L, 2, 0);
3645 lua_pushnumber(L, dx);
3646 lua_rawseti(L, -2, 1);
3647 lua_pushnumber(L, dy);
3648 lua_rawseti(L, -2, 2);
3649 return 1;
3650}
3651
3652static int
3653_edje_lua_part_get_text_cursor_geometry(lua_State *L)
3654{
3655 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3656 Evas_Coord x, y, w, h;
3657 edje_object_part_text_cursor_geometry_get(obj->ed->obj, obj->key,
3658 &x, &y, &w, &h);
3659 lua_createtable(L, 4, 0);
3660 lua_pushnumber(L, x);
3661 lua_rawseti(L, -2, 1);
3662 lua_pushnumber(L, y);
3663 lua_rawseti(L, -2, 2);
3664 lua_pushnumber(L, w);
3665 lua_rawseti(L, -2, 3);
3666 lua_pushnumber(L, h);
3667 lua_rawseti(L, -2, 4);
3668 return 1;
3669}
3670
3671static int
3672_edje_lua_part_get_geometry(lua_State *L)
3673{
3674 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3675 Evas_Coord x, y, w, h;
3676 edje_object_part_geometry_get(obj->ed->obj, obj->key, &x, &y, &w, &h);
3677 lua_createtable(L, 4, 0);
3678 lua_pushnumber(L, x);
3679 lua_rawseti(L, -2, 1);
3680 lua_pushnumber(L, y);
3681 lua_rawseti(L, -2, 2);
3682 lua_pushnumber(L, w);
3683 lua_rawseti(L, -2, 3);
3684 lua_pushnumber(L, h);
3685 lua_rawseti(L, -2, 4);
3686 return 1;
3687}
3688
3689static int
3690_edje_lua_part_get_table_col_row_size(lua_State *L)
3691{
3692 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3693 int cols, rows;
3694 edje_object_part_table_col_row_size_get(obj->ed->obj, obj->key, &cols, &rows);
3695 lua_createtable(L, 2, 0);
3696 lua_pushnumber(L, cols); lua_rawseti(L, -2, 1);
3697 lua_pushnumber(L, rows); lua_rawseti(L, -2, 2);
3698 return 1;
3699}
3700
3701static int _edje_lua_part_fn_custom_state(lua_State *L);
3702
3703const luaL_Reg lPart_get[] = {
3704 {"custom_state", _edje_lua_part_fn_custom_state},
3705 {"Swallow", _edje_lua_part_get_swallow}, //TODO it the capital S correct?
3706
3707 {"drag_dir", _edje_lua_part_get_drag_dir},
3708 {"drag_value", _edje_lua_part_get_drag_value},
3709 {"drag_size", _edje_lua_part_get_drag_size},
3710 {"drag_step", _edje_lua_part_get_drag_step},
3711 {"drag_page", _edje_lua_part_get_drag_page},
3712
3713 {"type", _edje_lua_part_get_type},
3714 {"effect", _edje_lua_part_get_effect},
3715 {"mouse_events", _edje_lua_part_get_mouse_events},
3716 {"repeat_events", _edje_lua_part_get_repeat_events},
3717 {"states_list", _edje_lua_part_get_states_list},
3718 {"state", _edje_lua_part_get_state},
3719
3720 {"text", _edje_lua_part_get_text},
3721 {"text_selection", _edje_lua_part_get_text_selection},
3722 {"text_cursor_geometry", _edje_lua_part_get_text_cursor_geometry},
3723
3724 {"geometry", _edje_lua_part_get_geometry},
3725 {"part_col_row_size", _edje_lua_part_get_table_col_row_size},
3726 {NULL, NULL} // sentinel
3727};
3728
3729static int
3730_edje_lua_part_set_effect(lua_State *L)
3731{
3732 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3733 edje_edit_part_effect_set(obj->ed->obj, obj->key, luaL_checkint(L, 2));
3734 return 0;
3735}
3736
3737static int
3738_edje_lua_part_set_mouse_events(lua_State *L)
3739{
3740 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3741 edje_edit_part_mouse_events_set(obj->ed->obj, obj->key, lua_toboolean(L, 2));
3742 return 0;
3743}
3744
3745static int
3746_edje_lua_part_set_repeat_events(lua_State *L)
3747{
3748 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3749 edje_edit_part_repeat_events_set(obj->ed->obj, obj->key,
3750 lua_toboolean(L, 2));
3751 return 0;
3752}
3753
3754static int
3755_edje_lua_part_set_state(lua_State *L)
3756{
3757 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3758 luaL_checktype(L, 2, LUA_TTABLE);
3759 lua_rawgeti(L, 2, 1);
3760 lua_rawgeti(L, 2, 2);
3761 _edje_part_description_apply(obj->ed, obj->rp,
3762 luaL_checkstring(L, -2), luaL_checknumber(L, -1),
3763 NULL, 0.0);
3764 _edje_part_pos_set(obj->ed, obj->rp, EDJE_TWEEN_MODE_LINEAR, ZERO, ZERO, ZERO);
3765 _edje_recalc(obj->ed);
3766 return 0;
3767}
3768
3769static int
3770_edje_lua_part_set_tween_state(lua_State *L)
3771{
3772 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3773 luaL_checktype(L, 2, LUA_TTABLE);
3774 lua_rawgeti(L, 2, 1);
3775 lua_rawgeti(L, 2, 2);
3776 lua_rawgeti(L, 2, 3);
3777 lua_rawgeti(L, 2, 4);
3778 lua_rawgeti(L, 2, 5);
3779 _edje_part_description_apply(obj->ed, obj->rp,
3780 luaL_checkstring(L, -4), luaL_checknumber(L, -3),
3781 luaL_checkstring(L, -2), luaL_checknumber(L, -1));
3782 _edje_part_pos_set(obj->ed, obj->rp, EDJE_TWEEN_MODE_LINEAR,
3783 FROM_DOUBLE(luaL_checknumber(L, -5)), ZERO, ZERO);
3784 _edje_recalc(obj->ed);
3785 return 0;
3786}
3787
3788static int
3789_edje_lua_part_set_text(lua_State *L)
3790{
3791 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3792 edje_object_part_text_set(obj->ed->obj, obj->key, luaL_checkstring(L, 2));
3793 return 0;
3794}
3795
3796static int
3797_edje_lua_part_set_drag_value(lua_State *L)
3798{
3799 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3800 lua_rawgeti(L, 2, 1);
3801 lua_rawgeti(L, 2, 2);
3802 edje_object_part_drag_value_set(obj->ed->obj, obj->key,
3803 luaL_checknumber(L, -2),
3804 luaL_checknumber(L, -1));
3805 return 0;
3806}
3807
3808static int
3809_edje_lua_part_set_drag_size(lua_State *L)
3810{
3811 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3812 lua_rawgeti(L, 2, 1);
3813 lua_rawgeti(L, 2, 2);
3814 edje_object_part_drag_size_set(obj->ed->obj, obj->key,
3815 luaL_checknumber(L, -2),
3816 luaL_checknumber(L, -1));
3817 return 0;
3818}
3819
3820static int
3821_edje_lua_part_set_drag_step(lua_State *L)
3822{
3823 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3824 lua_rawgeti(L, 2, 1);
3825 lua_rawgeti(L, 2, 2);
3826 edje_object_part_drag_step_set(obj->ed->obj, obj->key,
3827 luaL_checknumber(L, -2),
3828 luaL_checknumber(L, -1));
3829 return 0;
3830}
3831
3832static int
3833_edje_lua_part_set_drag_page(lua_State *L)
3834{
3835 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3836 lua_rawgeti(L, 2, 1);
3837 lua_rawgeti(L, 2, 2);
3838 edje_object_part_drag_page_set(obj->ed->obj, obj->key,
3839 luaL_checknumber(L, -2),
3840 luaL_checknumber(L, -1));
3841 return 0;
3842}
3843
3844const luaL_Reg lPart_set[] = {
3845 {"drag_value", _edje_lua_part_set_drag_value},
3846 {"drag_size", _edje_lua_part_set_drag_size},
3847 {"drag_step", _edje_lua_part_set_drag_step},
3848 {"drag_page", _edje_lua_part_set_drag_page},
3849
3850 {"effect", _edje_lua_part_set_effect},
3851 {"mouse_events", _edje_lua_part_set_mouse_events},
3852 {"repeat_events", _edje_lua_part_set_repeat_events},
3853 {"state", _edje_lua_part_set_state},
3854 {"tween_state", _edje_lua_part_set_tween_state},
3855 {"text", _edje_lua_part_set_text},
3856 {NULL, NULL} // sentinel
3857};
3858
3859static int
3860_edje_lua_part_fn_swallow(lua_State *L)
3861{
3862 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3863 Edje_Lua_Evas_Object *swa = _edje_lua_checkudata(L, 2, &mObject);
3864 edje_object_part_swallow(obj->ed->obj, obj->key, swa->eo);
3865 return 0;
3866}
3867
3868static int
3869_edje_lua_part_fn_unswallow(lua_State *L)
3870{
3871 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3872 edje_object_part_unswallow(obj->ed->obj, obj->eo);
3873 return 0;
3874}
3875
3876static int
3877_edje_lua_part_fn_text_select_none(lua_State *L)
3878{
3879 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3880 edje_object_part_text_select_none(obj->ed->obj, obj->key);
3881 return 0;
3882}
3883
3884static int
3885_edje_lua_part_fn_text_select_all(lua_State *L)
3886{
3887 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3888 edje_object_part_text_select_all(obj->ed->obj, obj->key);
3889 return 0;
3890}
3891
3892static int
3893_edje_lua_part_fn_text_insert(lua_State *L)
3894{
3895 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3896 edje_object_part_text_insert(obj->ed->obj, obj->key, luaL_checkstring(L, 2));
3897 return 0;
3898}
3899
3900static int
3901_edje_lua_part_fn_custom_state(lua_State *L)
3902{
3903 char *name;
3904 float val;
3905 Edje_Part_Description *parent;
3906 Edje_Part_Image_Id *iid;
3907 Eina_List *l;
3908 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3909 /* check whether this part already has a "custom" state */
3910 if (obj->rp->custom)
3911 {
3912 _edje_lua_get_reg(L, obj->rp->custom->description);
3913 return 1;
3914 }
3915
3916 name = (char *)luaL_checkstring(L, 2); // state name
3917 val = luaL_checknumber(L, 3); // state val
3918 if (!(parent = _edje_part_description_find(obj->ed, obj->rp, name, val)))
3919 {
3920 lua_pushnil(L);
3921 return 1;
3922 }
3923 /* now create the custom state */
3924 Edje_Lua_Edje_Part_Description *tar =
3925 lua_newuserdata(L, sizeof(Edje_Lua_Edje_Part_Description));
3926 tar->rp = obj->rp;
3927 _edje_lua_set_class(L, -1, cDescription);
3928 _edje_lua_new_reg(L, -1, tar); // freed in edje_load.c::_edje_file_del
3929 if (!(tar->pd = calloc(1, sizeof(Edje_Part_Description))))
3930 {
3931 lua_pushnil(L);
3932 return 1;
3933 }
3934
3935 obj->rp->custom = eina_mempool_malloc(_edje_real_part_state_mp, sizeof (Edje_Real_Part_State));
3936 if (!obj->rp->custom)
3937 {
3938 free(tar->pd);
3939 tar->pd = NULL;
3940 lua_pushnil(L);
3941 return 1;
3942 }
3943
3944 *(tar->pd) = *parent;
3945 tar->pd->state.name = (char *)eina_stringshare_add("custom");
3946 tar->pd->state.value = 0.0;
3947 /*
3948 * make sure all the allocated memory is getting copied,
3949 * not just referenced
3950 */
3951 tar->pd->image.tween_list = NULL;
3952 EINA_LIST_FOREACH(parent->image.tween_list, l, iid)
3953 {
3954 Edje_Part_Image_Id *iid_new;
3955 iid_new = calloc(1, sizeof(Edje_Part_Image_Id));
3956 iid_new->id = iid->id;
3957
3958 tar->pd->image.tween_list =
3959 eina_list_append(tar->pd->image.tween_list, iid_new);
3960 }
3961#define DUP(x) x ? (char *)eina_stringshare_add(x) : NULL
3962 tar->pd->color_class = DUP(tar->pd->color_class);
3963 tar->pd->text.text = DUP(tar->pd->text.text);
3964 tar->pd->text.text_class = DUP(tar->pd->text.text_class);
3965 tar->pd->text.font = DUP(tar->pd->text.font);
3966 tar->pd->text.style = DUP(tar->pd->text.style);
3967#undef DUP
3968 obj->rp->custom->description = tar->pd;
3969 _edje_lua_new_reg(L, -1, obj->rp->custom->description); // freed in edje_load.c::_edje_file_del
3970 return 1;
3971}
3972
3973static int
3974_edje_lua_part_fn_table_pack(lua_State *L)
3975{
3976 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3977 Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject);
3978 lua_pushboolean(L,
3979 edje_object_part_table_pack(obj->ed->obj, obj->key, tar->eo,
3980 luaL_checkint(L, 3),
3981 luaL_checkint(L, 4),
3982 luaL_checkint(L, 5),
3983 luaL_checkint(L, 6)));
3984 return 1;
3985}
3986
3987static int
3988_edje_lua_part_fn_table_unpack(lua_State *L)
3989{
3990 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
3991 Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject);
3992 lua_pushboolean(L,
3993 edje_object_part_table_unpack(obj->ed->obj, obj->key, tar->eo));
3994 return 1;
3995}
3996
3997static int
3998_edje_lua_part_fn_table_clear(lua_State *L)
3999{
4000 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
4001 lua_pushboolean(L,
4002 edje_object_part_table_clear(obj->ed->obj, obj->key, lua_toboolean(L, 2)));
4003 return 1;
4004}
4005
4006static int
4007_edje_lua_part_fn_box_append(lua_State *L)
4008{
4009 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
4010 Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject);
4011 lua_pushboolean(L,
4012 edje_object_part_box_append(obj->ed->obj, obj->key, tar->eo));
4013 return 1;
4014}
4015
4016static int
4017_edje_lua_part_fn_box_prepend(lua_State *L)
4018{
4019 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
4020 Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject);
4021 lua_pushboolean(L,
4022 edje_object_part_box_prepend(obj->ed->obj, obj->key, tar->eo));
4023 return 1;
4024}
4025
4026static int
4027_edje_lua_part_fn_box_insert_before(lua_State *L)
4028{
4029 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
4030 Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject);
4031 Edje_Lua_Evas_Object *ref = _edje_lua_checkudata(L, 3, &mObject);
4032 lua_pushboolean(L,
4033 edje_object_part_box_insert_before(obj->ed->obj, obj->key, tar->eo, ref->eo));
4034 return 1;
4035}
4036
4037static int
4038_edje_lua_part_fn_box_insert_at(lua_State *L)
4039{
4040 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
4041 Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject);
4042 lua_pushboolean(L,
4043 edje_object_part_box_insert_at(obj->ed->obj, obj->key, tar->eo, luaL_checkint(L, 3)));
4044 return 1;
4045}
4046
4047static int
4048_edje_lua_part_fn_box_remove(lua_State *L)
4049{
4050 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
4051 Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject);
4052 edje_object_part_box_remove(obj->ed->obj, obj->key, tar->eo);
4053 lua_pushvalue(L, 2);
4054 return 1;
4055}
4056
4057static int
4058_edje_lua_part_fn_box_remove_at(lua_State *L)
4059{
4060 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
4061 _edje_lua_get_reg(L, edje_object_part_box_remove_at(obj->ed->obj, obj->key, luaL_checkint(L, 2)));
4062 return 1;
4063}
4064
4065static int
4066_edje_lua_part_fn_box_remove_all(lua_State *L)
4067{
4068 Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart);
4069 lua_pushboolean(L,
4070 edje_object_part_box_remove_all(obj->ed->obj, obj->key, lua_toboolean(L, 2)));
4071 return 1;
4072}
4073
4074const luaL_Reg lPart_fn[] = {
4075 {"swallow", _edje_lua_part_fn_swallow},
4076 {"unswallow", _edje_lua_part_fn_unswallow},
4077
4078 {"custom_state", _edje_lua_part_fn_custom_state},
4079
4080 {"text_select_none", _edje_lua_part_fn_text_select_none},
4081 {"text_select_all", _edje_lua_part_fn_text_select_all},
4082 {"text_insert", _edje_lua_part_fn_text_insert},
4083
4084 {"table_pack", _edje_lua_part_fn_table_pack},
4085 {"table_unpack", _edje_lua_part_fn_table_unpack},
4086 {"table_clear", _edje_lua_part_fn_table_clear},
4087
4088 {"box_append", _edje_lua_part_fn_box_append},
4089 {"box_prepend", _edje_lua_part_fn_box_prepend},
4090 {"box_insert_before", _edje_lua_part_fn_box_insert_before},
4091 {"box_insert_at", _edje_lua_part_fn_box_insert_at},
4092 {"box_remove", _edje_lua_part_fn_box_remove},
4093 {"box_remove_at", _edje_lua_part_fn_box_remove_at},
4094 {"box_remove_all", _edje_lua_part_fn_box_remove_all},
4095 {NULL, NULL} // sentinel
4096};
4097
4098const luaL_Reg lGroup_mt[];
4099
4100const luaL_Reg lGroup_get[];
4101
4102const luaL_Reg lGroup_set[];
4103
4104const luaL_Reg lGroup_fn[];
4105
4106const Edje_Lua_Reg mGroup = {
4107 lGroup_mt,
4108 lGroup_get,
4109 lGroup_set,
4110 lGroup_fn
4111};
4112
4113const Edje_Lua_Reg *cGroup[] = {
4114 &mClass,
4115 &mObject,
4116 &mGroup,
4117 NULL // sentinel
4118};
4119
4120static int
4121_edje_lua_group_mt_index(lua_State *L)
4122{
4123 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4124 lua_getmetatable(L, 1);
4125 if (!_edje_lua_look_fn(L))
4126 {
4127 // look in lGroup_fn
4128 if (!_edje_lua_look_get(L))
4129 {
4130 // look in lGroup_get
4131 const char *key = luaL_checkstring(L, 2);
4132 Edje *ed = _edje_fetch(obj->eo);
4133 Edje_Real_Part *rp = _edje_real_part_recursive_get(ed, key);
4134 if (rp)
4135 {
4136 // check if lua userdata exists
4137 Evas_Object *part = (Evas_Object *) edje_object_part_object_get(obj->eo, key);
4138 _edje_lua_get_reg(L, part);
4139 if (lua_isnil(L, -1))
4140 {
4141 // create it
4142 lua_pop(L, 1);
4143 Edje_Lua_Edje_Part_Object *tar =
4144 lua_newuserdata(L, sizeof(Edje_Lua_Edje_Part_Object));
4145 tar->eo = part;
4146 tar->ed = ed;
4147 tar->key = key;
4148 tar->L = L;
4149 tar->rp = rp;
4150 _edje_lua_set_class(L, -1, cPart);
4151 _edje_lua_new_reg(L, -1, tar); // freed in _edje_lua_edje_part_del_cb
4152 _edje_lua_new_reg(L, -1, part); // freed in _edje_lua_edje_part_del_cb
4153 evas_object_event_callback_add(tar->eo,
4154 EVAS_CALLBACK_DEL,
4155 _edje_lua_edje_part_del_cb,
4156 L);
4157 }
4158 }
4159 else
4160 {
4161 // look in obj environment table
4162 lua_getfenv(L, 1);
4163 lua_pushvalue(L, 2); // key
4164 lua_rawget(L, -2);
4165 }
4166 }
4167 }
4168 return 1;
4169}
4170
4171const luaL_Reg lGroup_mt[] = {
4172 {"__index", _edje_lua_group_mt_index},
4173 {NULL, NULL} // sentinel
4174};
4175
4176static int
4177_edje_lua_group_get_group(lua_State *L)
4178{
4179 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4180 const char *file, *group;
4181 edje_object_file_get(obj->eo, &file, &group);
4182 lua_pushstring(L, group);
4183 return 1;
4184}
4185
4186static int
4187_edje_lua_group_get_mouse(lua_State *L)
4188{
4189 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4190 int x, y;
4191 evas_pointer_canvas_xy_get(evas_object_evas_get(obj->eo), &x, &y);
4192 x -= obj->ed->x;
4193 y -= obj->ed->y;
4194 lua_createtable(L, 2, 0);
4195 lua_pushnumber(L, x);
4196 lua_rawseti(L, -2, 1);
4197 lua_pushnumber(L, y);
4198 lua_rawseti(L, -2, 2);
4199 return 1;
4200}
4201
4202static int
4203_edje_lua_group_get_mouse_buttons(lua_State *L)
4204{
4205 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4206 lua_pushnumber(L, evas_pointer_button_down_mask_get(obj->ed->evas));
4207 return 1;
4208}
4209
4210static int
4211_edje_lua_group_get_size_min(lua_State *L)
4212{
4213 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4214 int w, h;
4215 edje_object_size_min_get(obj->eo, &w, &h);
4216 lua_createtable(L, 2, 0);
4217 lua_pushnumber(L, w);
4218 lua_rawseti(L, -2, 1);
4219 lua_pushnumber(L, h);
4220 lua_rawseti(L, -2, 2);
4221 return 1;
4222}
4223
4224static int
4225_edje_lua_group_get_size_max(lua_State *L)
4226{
4227 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4228 int w, h;
4229 edje_object_size_max_get(obj->eo, &w, &h);
4230 lua_createtable(L, 2, 0);
4231 lua_pushnumber(L, w);
4232 lua_rawseti(L, -2, 1);
4233 lua_pushnumber(L, h);
4234 lua_rawseti(L, -2, 2);
4235 return 1;
4236}
4237
4238static int
4239_edje_lua_group_get_scale(lua_State *L)
4240{
4241 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4242 lua_pushnumber(L, edje_object_scale_get(obj->eo));
4243 return 1;
4244}
4245
4246static int
4247_edje_lua_group_get_load_error(lua_State *L)
4248{
4249 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4250 lua_pushnumber(L, edje_object_load_error_get(obj->eo));
4251 return 1;
4252}
4253
4254static int
4255_edje_lua_group_get_load_error_str(lua_State *L)
4256{
4257 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4258 lua_pushstring(L, edje_load_error_str(edje_object_load_error_get(obj->eo)));
4259 return 1;
4260}
4261
4262static int
4263_edje_lua_group_get_play(lua_State *L)
4264{
4265 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4266 lua_pushboolean(L, edje_object_play_get(obj->eo));
4267 return 1;
4268}
4269
4270static int
4271_edje_lua_group_get_animation(lua_State *L)
4272{
4273 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4274 lua_pushboolean(L, edje_object_animation_get(obj->eo));
4275 return 1;
4276}
4277
4278static int
4279_edje_lua_group_get_frametime(lua_State *L)
4280{
4281 lua_pushnumber(L, edje_frametime_get());
4282 return 1;
4283}
4284
4285const luaL_Reg lGroup_get[] = {
4286 {"group", _edje_lua_group_get_group},
4287 {"mouse", _edje_lua_group_get_mouse},
4288 {"mouse_buttons", _edje_lua_group_get_mouse_buttons},
4289 {"size_min", _edje_lua_group_get_size_min},
4290 {"size_max", _edje_lua_group_get_size_max},
4291 {"scale", _edje_lua_group_get_scale},
4292 {"load_error", _edje_lua_group_get_load_error},
4293 {"load_error_str", _edje_lua_group_get_load_error_str},
4294 {"play", _edje_lua_group_get_play},
4295 {"animation", _edje_lua_group_get_animation},
4296 {"frametime", _edje_lua_group_get_frametime},
4297 {NULL, NULL} // sentinel
4298};
4299
4300static int
4301_edje_lua_group_set_group(lua_State *L)
4302{
4303 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4304 edje_object_file_set(obj->eo, obj->ed->file->path, luaL_checkstring(L, 2));
4305 return 0;
4306}
4307
4308static int
4309_edje_lua_group_set_size_min(lua_State *L)
4310{
4311 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4312
4313 luaL_checktype(L, 2, LUA_TTABLE);
4314 lua_rawgeti(L, 2, 1);
4315 lua_rawgeti(L, 2, 2);
4316 obj->ed->collection->prop.min.w = luaL_checkint(L, -2);
4317 obj->ed->collection->prop.min.h = luaL_checkint(L, -1);
4318 obj->ed->dirty = 1;
4319 _edje_recalc(obj->ed);
4320 return 0;
4321}
4322
4323static int
4324_edje_lua_group_set_size_max(lua_State *L)
4325{
4326 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4327 luaL_checktype(L, 2, LUA_TTABLE);
4328 lua_rawgeti(L, 2, 1);
4329 lua_rawgeti(L, 2, 2);
4330 obj->ed->collection->prop.max.w = luaL_checkint(L, -2);
4331 obj->ed->collection->prop.max.h = luaL_checkint(L, -1);
4332 obj->ed->dirty = 1;
4333 _edje_recalc(obj->ed);
4334 return 0;
4335}
4336
4337static int
4338_edje_lua_group_set_scale(lua_State *L)
4339{
4340 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4341 edje_object_scale_set(obj->eo, luaL_checknumber(L, 2));
4342 return 0;
4343}
4344
4345static int
4346_edje_lua_group_set_play(lua_State *L)
4347{
4348 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4349 edje_object_play_set(obj->eo, lua_toboolean(L, 2));
4350 return 0;
4351}
4352
4353static int
4354_edje_lua_group_set_animation(lua_State *L)
4355{
4356 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4357 edje_object_animation_set(obj->eo, lua_toboolean(L, 2));
4358 return 0;
4359}
4360
4361static void
4362_edje_lua_group_text_change_cb(void* data, Evas_Object *obj, const char* part)
4363{
4364 Edje_Lua_Ref *ref = data;
4365 lua_State *L = ref->L;
4366 int err_code;
4367
4368 _edje_lua_get_ref(L, ref);
4369 _edje_lua_get_reg(L, obj);
4370 lua_pushstring(L, part);
4371
4372 if ((err_code = lua_pcall(L, 2, 0, 0)))
4373 _edje_lua_error(L, err_code);
4374}
4375
4376static int
4377_edje_lua_group_set_text_change_cb(lua_State *L)
4378{
4379 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4380 edje_object_text_change_cb_set(obj->eo, _edje_lua_group_text_change_cb, _edje_lua_new_ref(L, 2));
4381 return 0;
4382}
4383
4384static int
4385_edje_lua_group_set_frametime(lua_State *L)
4386{
4387 edje_frametime_set(luaL_checknumber(L, 2));
4388 return 0;
4389}
4390const luaL_Reg lGroup_set[] = {
4391 {"group", _edje_lua_group_set_group},
4392 {"size_min", _edje_lua_group_set_size_min},
4393 {"size_max", _edje_lua_group_set_size_max},
4394 {"scale", _edje_lua_group_set_scale},
4395 {"play", _edje_lua_group_set_play},
4396 {"animation", _edje_lua_group_set_animation},
4397 {"text_change_cb", _edje_lua_group_set_text_change_cb},
4398 {"frametime", _edje_lua_group_set_frametime},
4399 {NULL, NULL} // sentinel
4400};
4401
4402static int
4403_edje_lua_group_fn_timer(lua_State *L)
4404{
4405 Edje_Lua_Timer *tar = lua_newuserdata(L, sizeof(Edje_Lua_Timer));
4406
4407 _edje_lua_set_class(L, -1, cTimer);
4408 /* ^^^^^^^^^^^^^^^^(L, index, class)
4409 lua_newtable(L);
4410 if (index < 0)
4411 lua_setfenv(L, index - 1);
4412 else
4413 lua_setfenv(L, index);
4414
4415 _edje_lua_get_metatable(L, class);
4416 if (index < 0)
4417 lua_setmetatable(L, index - 1);
4418 else
4419 lua_setmetatable(L, index);
4420 */
4421
4422 tar->et = ecore_timer_add(luaL_checknumber(L, 2), _edje_lua_timer_cb, tar);
4423 tar->L = L;
4424
4425 _edje_lua_new_reg(L, -1, tar); // freed in _edje_lua_timer_cb/del
4426 /* ^^^^^^^^^^^^^^(L, index, ptr)
4427 lua_pushvalue(L, index);
4428 lua_pushlightuserdata(L, ptr);
4429 lua_insert(L, -2);
4430 lua_rawset(L, LUA_REGISTRYINDEX); // freed in _edje_lua_free_reg
4431 */
4432
4433 tar->cb = _edje_lua_new_ref(L, 3); // freed in _edje_lua_timer_cb/del
4434 /* ^^^^^^^^^^^^^^^^^^^^^^^^(L, index)
4435 lua_pushvalue(L, index);
4436 Edje_Lua_Ref *ref = malloc(sizeof(Edje_Lua_Ref));
4437 ref->id = luaL_ref(L, LUA_REGISTRYINDEX);
4438 ref->L = L;
4439 return ref;
4440 */
4441 return 1;
4442}
4443
4444static int
4445_edje_lua_group_fn_animator(lua_State *L)
4446{
4447 Edje_Lua_Animator *tar = lua_newuserdata(L, sizeof(Edje_Lua_Animator));
4448 _edje_lua_set_class(L, -1, cAnimator);
4449 tar->ea = ecore_animator_add(_edje_lua_animator_cb, tar);
4450 tar->L = L;
4451 _edje_lua_new_reg(L, -1, tar); // freed in _edje_lua_animator_cb/del
4452 tar->cb = _edje_lua_new_ref(L, 2); // freed in _edje_lua_animator_cb/del
4453 return 1;
4454}
4455
4456static int
4457_edje_lua_group_fn_poller(lua_State *L)
4458{
4459 int interval;
4460 Edje_Lua_Poller *tar;
4461 tar = lua_newuserdata(L, sizeof(Edje_Lua_Poller));
4462 _edje_lua_set_class(L, -1, cPoller);
4463
4464 interval = luaL_checknumber(L, 2);
4465 if ((interval <= 0) || ((interval & 1) != 0))
4466 {
4467 return 0;
4468 }
4469
4470 // Only 1 type of poller currently implemented in ecore
4471 tar->ep = ecore_poller_add(ECORE_POLLER_CORE, interval,
4472 _edje_lua_poller_cb, tar);
4473 tar->L = L;
4474 _edje_lua_new_reg(L, -1, tar); // freed in _edje_lua_poller_cb/del
4475 tar->cb = _edje_lua_new_ref(L, 3); // freed in _edje_lua_poller_cb/del
4476
4477 return 1;
4478}
4479
4480static int
4481_edje_lua_group_fn_transform(lua_State *L)
4482{
4483 Edje_Lua_Transform *tar = lua_newuserdata(L, sizeof(Edje_Lua_Transform));
4484 evas_transform_identity_set (&(tar->et));
4485 _edje_lua_set_class(L, -1, cTransform);
4486 tar->L = L;
4487 return 1;
4488}
4489
4490static int
4491_edje_lua_group_fn_signal_emit(lua_State *L)
4492{
4493 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4494 edje_object_signal_emit(obj->eo,
4495 luaL_checkstring(L, 2), luaL_checkstring(L, 3));
4496 return 0;
4497}
4498
4499static Edje_Program *
4500_edje_lua_program_get_byname(Evas_Object * obj, const char *prog_name)
4501{
4502 Edje_Program *epr;
4503 int i;
4504 Edje *ed;
4505 ed = _edje_fetch(obj);
4506 if (!ed)
4507 return NULL;
4508 if (!prog_name)
4509 return NULL;
4510 for (i = 0; i < ed->table_programs_size; i++)
4511 {
4512 epr = ed->table_programs[i];
4513 if ((epr->name) && (strcmp(epr->name, prog_name) == 0))
4514 return epr;
4515 }
4516 return NULL;
4517}
4518
4519static int
4520_edje_lua_group_fn_program_run(lua_State *L)
4521{
4522 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4523 Edje_Program *pr =
4524 _edje_lua_program_get_byname(obj->eo, luaL_checkstring(L, 2));
4525 if (pr)
4526 _edje_program_run(obj->ed, pr, 0, "", "");
4527 return 0;
4528}
4529
4530static int
4531_edje_lua_group_fn_program_stop(lua_State *L)
4532{
4533 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4534 Edje_Program *pr =
4535 _edje_lua_program_get_byname(obj->eo, luaL_checkstring(L, 2));
4536 int program_id = pr->id;
4537 Edje_Running_Program *runp;
4538 Eina_List *l;
4539 obj->ed->walking_actions = 1;
4540 EINA_LIST_FOREACH(obj->ed->actions, l, runp)
4541 if (program_id == runp->program->id)
4542 _edje_program_end(obj->ed, runp);
4543 obj->ed->walking_actions = 0;
4544 return 0;
4545}
4546
4547static int
4548_edje_lua_group_fn_message_send(lua_State *L)
4549{
4550 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4551 int type = luaL_checkint(L, 2);
4552 void *msg = NULL;
4553 int i;
4554 int size;
4555 switch (type)
4556 {
4557 case EDJE_MESSAGE_NONE:
4558 break;
4559 case EDJE_MESSAGE_SIGNAL:
4560 break;
4561 case EDJE_MESSAGE_STRING:
4562 {
4563 Edje_Message_String *msg_string =
4564 malloc(sizeof(Edje_Message_String));
4565 msg_string->str = (char *)luaL_checkstring(L, 4);
4566 msg = msg_string;
4567 }
4568 break;
4569 case EDJE_MESSAGE_INT:
4570 {
4571 Edje_Message_Int *msg_int = malloc(sizeof(Edje_Message_Int));
4572
4573 msg_int->val = luaL_checkint(L, 4);
4574 msg = msg_int;
4575 }
4576 break;
4577 case EDJE_MESSAGE_FLOAT:
4578 {
4579 Edje_Message_Float *msg_float = malloc(sizeof(Edje_Message_Float));
4580
4581 msg_float->val = luaL_checknumber(L, 4);
4582 msg = msg_float;
4583 }
4584 break;
4585 case EDJE_MESSAGE_STRING_SET:
4586 {
4587 if (lua_type(L, 4) != LUA_TTABLE)
4588 break;
4589 size = lua_objlen(L, 4);
4590 Edje_Message_String_Set *msg_string_set =
4591 malloc(sizeof(Edje_Message_String_Set) +
4592 (size - 1) * sizeof(char *));
4593 msg_string_set->count = size;
4594 for (i = 0; i < size; i++)
4595 {
4596 lua_rawgeti(L, 4, i + 1);
4597 msg_string_set->str[i] = (char *)luaL_checkstring(L, -1);
4598 lua_pop(L, 1);
4599 }
4600 msg = msg_string_set;
4601 }
4602 break;
4603 case EDJE_MESSAGE_INT_SET:
4604 {
4605 if (lua_type(L, 4) != LUA_TTABLE)
4606 break;
4607 size = lua_objlen(L, 4);
4608 Edje_Message_Int_Set *msg_int_set =
4609 malloc(sizeof(Edje_Message_Int_Set) + (size - 1) * sizeof(int));
4610 msg_int_set->count = size;
4611 for (i = 0; i < size; i++)
4612 {
4613 lua_rawgeti(L, 4, i + 1);
4614 msg_int_set->val[i] = luaL_checkint(L, -1);
4615 lua_pop(L, 1);
4616 }
4617 msg = msg_int_set;
4618 }
4619 break;
4620 case EDJE_MESSAGE_FLOAT_SET:
4621 {
4622 if (lua_type(L, 4) != LUA_TTABLE)
4623 break;
4624 size = lua_objlen(L, 4);
4625 Edje_Message_Float_Set *msg_float_set =
4626 malloc(sizeof(Edje_Message_Float_Set) +
4627 (size - 1) * sizeof(double));
4628 msg_float_set->count = size;
4629 for (i = 0; i < size; i++)
4630 {
4631 lua_rawgeti(L, 4, i + 1);
4632 msg_float_set->val[i] = luaL_checknumber(L, -1);
4633 lua_pop(L, 1);
4634 }
4635 msg = msg_float_set;
4636 }
4637 break;
4638 case EDJE_MESSAGE_STRING_INT:
4639 {
4640 Edje_Message_String_Int *msg_string_int =
4641 malloc(sizeof(Edje_Message_String_Int));
4642 msg_string_int->str = (char *)luaL_checkstring(L, 4);
4643 msg_string_int->val = luaL_checkint(L, 5);
4644 msg = msg_string_int;
4645 }
4646 break;
4647 case EDJE_MESSAGE_STRING_FLOAT:
4648 {
4649 Edje_Message_String_Float *msg_string_float =
4650 malloc(sizeof(Edje_Message_String_Float));
4651 msg_string_float->str = (char *)luaL_checkstring(L, 4);
4652 msg_string_float->val = luaL_checknumber(L, 5);
4653 msg = msg_string_float;
4654 }
4655 break;
4656 case EDJE_MESSAGE_STRING_INT_SET:
4657 {
4658 if (lua_type(L, 5) != LUA_TTABLE)
4659 break;
4660 size = lua_objlen(L, 5);
4661 Edje_Message_String_Int_Set *msg_string_int_set =
4662 malloc(sizeof(Edje_Message_String_Int_Set) +
4663 (size - 1) * sizeof(int));
4664 msg_string_int_set->str = (char *)luaL_checkstring(L, 4);
4665 msg_string_int_set->count = size;
4666 for (i = 0; i < size; i++)
4667 {
4668 lua_rawgeti(L, 5, i + 1);
4669 msg_string_int_set->val[i] = luaL_checkint(L, -1);
4670 lua_pop(L, 1);
4671 }
4672 msg = msg_string_int_set;
4673 }
4674 break;
4675 case EDJE_MESSAGE_STRING_FLOAT_SET:
4676 {
4677 if (lua_type(L, 5) != LUA_TTABLE)
4678 break;
4679 size = lua_objlen(L, 5);
4680 Edje_Message_String_Float_Set *msg_string_float_set =
4681 malloc(sizeof(Edje_Message_String_Float_Set) +
4682 (size - 1) * sizeof(double));
4683 msg_string_float_set->str = (char *)luaL_checkstring(L, 4);
4684 msg_string_float_set->count = size;
4685 for (i = 0; i < size; i++)
4686 {
4687 lua_rawgeti(L, 5, i + 1);
4688 msg_string_float_set->val[i] = luaL_checknumber(L, -1);
4689 lua_pop(L, 1);
4690 }
4691 msg = msg_string_float_set;
4692 }
4693 break;
4694 default:
4695 break;
4696 }
4697
4698 if (msg)
4699 {
4700 edje_object_message_send(obj->eo, type, luaL_checkint(L, 3), msg);
4701 free(msg);
4702 }
4703
4704 return 0;
4705}
4706
4707static void
4708_edje_lua_group_signal_callback(void *data, Evas_Object * edj,
4709 const char *signal, const char *source)
4710{
4711 Edje_Lua_Ref *cb = data;
4712 lua_State *L = cb->L;
4713 _edje_lua_get_ref(L, cb); // signal callback function
4714 if (lua_isfunction(L, -1))
4715 {
4716 int err_code;
4717
4718 _edje_lua_get_reg(L, edj);
4719 lua_pushstring(L, signal); // signal
4720 lua_pushstring(L, source); // source
4721
4722 if ((err_code = lua_pcall(L, 3, 0, 0)))
4723 _edje_lua_error(L, err_code);
4724 }
4725}
4726
4727static int
4728_edje_lua_group_fn_signal_callback_add(lua_State *L)
4729{
4730 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4731 if (lua_type(L, 4) == LUA_TFUNCTION)
4732 {
4733 Edje_Lua_Ref *ref = _edje_lua_new_ref(L, 4);
4734 obj->cb = eina_list_append(obj->cb, ref);
4735 edje_object_signal_callback_add(obj->eo,
4736 luaL_checkstring(L, 2),
4737 luaL_checkstring(L, 3),
4738 _edje_lua_group_signal_callback,
4739 ref); // freed in _edje_lua_group_fn_signal_callback_del
4740 }
4741 return 0;
4742}
4743
4744static int
4745_edje_lua_group_fn_signal_callback_del(lua_State *L)
4746{
4747 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4748 Edje_Lua_Ref *ref = edje_object_signal_callback_del(obj->eo,
4749 luaL_checkstring(L, 2),
4750 luaL_checkstring(L, 3),
4751 _edje_lua_group_signal_callback);
4752 obj->cb = eina_list_remove(obj->cb, ref);
4753 _edje_lua_free_ref(L, ref); // created in _edje_lua_group_fn_signal_callback_add
4754 return 0;
4755}
4756
4757static int
4758_edje_lua_group_fn_freeze(lua_State *L)
4759{
4760 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4761 edje_object_freeze(obj->eo);
4762 return 0;
4763}
4764
4765static int
4766_edje_lua_group_fn_thaw(lua_State *L)
4767{
4768 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup);
4769 edje_object_thaw(obj->eo);
4770 return 0;
4771}
4772
4773const luaL_Reg lGroup_fn[] = {
4774 {"timer", _edje_lua_group_fn_timer},
4775 {"animator", _edje_lua_group_fn_animator},
4776 {"poller", _edje_lua_group_fn_poller},
4777 {"transform", _edje_lua_group_fn_transform},
4778 {"signal_emit", _edje_lua_group_fn_signal_emit},
4779 {"message_send", _edje_lua_group_fn_message_send},
4780 {"program_run", _edje_lua_group_fn_program_run},
4781 {"program_stop", _edje_lua_group_fn_program_stop},
4782 {"signal_callback_add", _edje_lua_group_fn_signal_callback_add},
4783 {"signal_callback_del", _edje_lua_group_fn_signal_callback_del},
4784 {"freeze", _edje_lua_group_fn_freeze},
4785 {"thaw", _edje_lua_group_fn_thaw},
4786 {NULL, NULL} // sentinel
4787};
4788
4789/*
4790 * Lua bindings
4791 */
4792
4793const luaL_Reg lScript_get[];
4794
4795const luaL_Reg lScript_set[];
4796
4797const luaL_Reg lScript_fn[];
4798
4799const Edje_Lua_Reg mScript = {
4800 lNil,
4801 lScript_get,
4802 lScript_set,
4803 lScript_fn
4804};
4805
4806const Edje_Lua_Reg *cScript[] = {
4807 &mClass,
4808 &mObject,
4809 &mGroup,
4810 &mScript,
4811 NULL // sentinel
4812};
4813
4814/*
4815 * macro for adding an evas_object in the lua_script_only object
4816 */
4817#define _EDJE_LUA_SCRIPT_FN_ADD(DEF, CLASS, FUNC) \
4818 static int \
4819 DEF (lua_State *L) \
4820 { \
4821 int set = lua_gettop (L) == 2; \
4822 Edje_Lua_Evas_Object *obj = _edje_lua_checkudata (L, 1, &mScript); \
4823 Edje_Lua_Evas_Object *tar = lua_newuserdata (L, sizeof (Edje_Lua_Evas_Object)); \
4824 _edje_lua_set_class (L, -1, CLASS); \
4825 tar->eo = FUNC (obj->ed->evas); \
4826 tar->ed = obj->ed; \
4827 tar->L = L; \
4828 tar->cb = NULL; \
4829 evas_object_move (tar->eo, obj->ed->x, obj->ed->y); \
4830 _edje_lua_new_reg (L, -1, tar); /* freed in _edje_lua_object_del_cb */ \
4831 _edje_lua_new_reg (L, -1, tar->eo); /* freed in _edje_lua_object_del_cb */ \
4832 evas_object_smart_member_add (tar->eo, obj->eo); \
4833 evas_object_clip_set (tar->eo, obj->ed->clipper); \
4834 evas_object_event_callback_add (tar->eo, EVAS_CALLBACK_DEL, _edje_lua_object_del_cb, L); \
4835 if (set) \
4836 { \
4837 int err_code; \
4838 lua_getfield (L, -1, "set"); \
4839 lua_pushvalue (L, -2); \
4840 lua_pushvalue (L, 2); \
4841 if ((err_code = lua_pcall (L, 2, 0, 0))) \
4842 _edje_lua_error (L, err_code); \
4843 } \
4844 return 1; \
4845 }
4846
4847_EDJE_LUA_SCRIPT_FN_ADD(_edje_lua_script_fn_rectangle,
4848 cRectangle,
4849 evas_object_rectangle_add)
4850_EDJE_LUA_SCRIPT_FN_ADD(_edje_lua_script_fn_image,
4851 cImage,
4852 evas_object_image_add)
4853_EDJE_LUA_SCRIPT_FN_ADD(_edje_lua_script_fn_table,
4854 cTable,
4855 evas_object_table_add)
4856_EDJE_LUA_SCRIPT_FN_ADD(_edje_lua_script_fn_line,
4857 cLine,
4858 evas_object_line_add)
4859_EDJE_LUA_SCRIPT_FN_ADD(_edje_lua_script_fn_polygon,
4860 cPolygon,
4861 evas_object_polygon_add)
4862_EDJE_LUA_SCRIPT_FN_ADD(_edje_lua_script_fn_group, cGroup, edje_object_add)
4863
4864const luaL_Reg lScript_fn[] = {
4865 {"rectangle", _edje_lua_script_fn_rectangle},
4866 {"image", _edje_lua_script_fn_image},
4867 {"table", _edje_lua_script_fn_table},
4868 {"line", _edje_lua_script_fn_line},
4869 {"polygon", _edje_lua_script_fn_polygon},
4870 {"group", _edje_lua_script_fn_group},
4871 {NULL, NULL} // sentinel
4872};
4873
4874const luaL_Reg lScript_get[] = {
4875 {NULL, NULL} // sentinel
4876};
4877
4878const luaL_Reg lScript_set[] = {
4879 {NULL, NULL} // sentinel
4880};
4881
4882/*
4883 * creates and exports a lua_script_only object
4884 */
4885void
4886_edje_lua_script_fn_new(Edje * ed)
4887{
4888 lua_State *L = ed->L;
4889 Edje_Lua_Evas_Object *tar = lua_newuserdata(L, sizeof(Edje_Lua_Evas_Object));
4890 _edje_lua_set_class(L, -1, cScript);
4891 tar->eo = ed->obj;
4892 tar->ed = ed;
4893 tar->L = L;
4894 tar->cb = NULL;
4895 _edje_lua_new_reg(L, -1, tar); // freed in _edje_lua_object_del_cb
4896 _edje_lua_new_reg(L, -1, ed); // freed in edje_load.c::_edje_file_del
4897 _edje_lua_new_reg(L, -1, ed->obj); // freed in _edje_lua_object_del_cb
4898 evas_object_event_callback_add(tar->eo, EVAS_CALLBACK_DEL,
4899 _edje_lua_object_del_cb, L);
4900}
4901
4902/*
4903 * creates and exports an Edje group with associated Lua scripts in the parts and programs sections
4904 */
4905void
4906_edje_lua_group_fn_new(Edje * ed)
4907{
4908 lua_State *L = ed->L;
4909 Edje_Lua_Evas_Object *tar = lua_newuserdata(L, sizeof(Edje_Lua_Evas_Object));
4910 _edje_lua_set_class(L, -1, cGroup);
4911 tar->eo = ed->obj;
4912 tar->ed = ed;
4913 tar->L = L;
4914 tar->cb = NULL;
4915 _edje_lua_new_reg(L, -1, tar); // freed in _edje_lua_object_del_cb
4916 _edje_lua_new_reg(L, -1, ed); // freed in edje_load.c::_edje_file_del
4917 _edje_lua_new_reg(L, -1, ed->obj); // freed in _edje_lua_object_del_cb
4918 evas_object_event_callback_add(tar->eo, EVAS_CALLBACK_DEL,
4919 _edje_lua_object_del_cb, L);
4920}
4921
4922/*
4923 * this function loads all the Lua bindings into the global Lua state
4924 */
4925static void
4926_edje_lua_open(lua_State *L)
4927{
4928 /*
4929 * export classes
4930 */
4931 _edje_lua_new_class(L, cTimer);
4932 _edje_lua_new_class(L, cAnimator);
4933 _edje_lua_new_class(L, cPoller);
4934 _edje_lua_new_class(L, cTransform);
4935 _edje_lua_new_class(L, cRectangle);
4936 _edje_lua_new_class(L, cImage);
4937 _edje_lua_new_class(L, cTable);
4938 _edje_lua_new_class(L, cLine);
4939 _edje_lua_new_class(L, cPolygon);
4940 _edje_lua_new_class(L, cGroup);
4941 _edje_lua_new_class(L, cDescription);
4942 _edje_lua_new_class(L, cPart);
4943 _edje_lua_new_class(L, cScript);
4944
4945 /*
4946 * export constants
4947 */
4948 _edje_lua_new_const(L, "MESSAGE_NONE", EDJE_MESSAGE_NONE);
4949 _edje_lua_new_const(L, "MESSAGE_SIGNAL", EDJE_MESSAGE_SIGNAL);
4950 _edje_lua_new_const(L, "MESSAGE_STRING", EDJE_MESSAGE_STRING);
4951 _edje_lua_new_const(L, "MESSAGE_INT", EDJE_MESSAGE_INT);
4952 _edje_lua_new_const(L, "MESSAGE_FLOAT", EDJE_MESSAGE_FLOAT);
4953 _edje_lua_new_const(L, "MESSAGE_STRING_SET", EDJE_MESSAGE_STRING_SET);
4954 _edje_lua_new_const(L, "MESSAGE_INT_SET", EDJE_MESSAGE_INT_SET);
4955 _edje_lua_new_const(L, "MESSAGE_FLOAT_SET", EDJE_MESSAGE_FLOAT_SET);
4956 _edje_lua_new_const(L, "MESSAGE_STRING_INT", EDJE_MESSAGE_STRING_INT);
4957 _edje_lua_new_const(L, "MESSAGE_STRING_FLOAT", EDJE_MESSAGE_STRING_FLOAT);
4958 _edje_lua_new_const(L, "MESSAGE_STRING_INT_SET", EDJE_MESSAGE_STRING_INT_SET);
4959 _edje_lua_new_const(L, "MESSAGE_STRING_FLOAT_SET", EDJE_MESSAGE_STRING_FLOAT_SET);
4960
4961 _edje_lua_new_const(L, "PART_TYPE_NONE", EDJE_PART_TYPE_NONE);
4962 _edje_lua_new_const(L, "PART_TYPE_RECTANGLE", EDJE_PART_TYPE_RECTANGLE);
4963 _edje_lua_new_const(L, "PART_TYPE_TEXT", EDJE_PART_TYPE_TEXT);
4964 _edje_lua_new_const(L, "PART_TYPE_IMAGE", EDJE_PART_TYPE_IMAGE);
4965 _edje_lua_new_const(L, "PART_TYPE_SWALLOW", EDJE_PART_TYPE_SWALLOW);
4966 _edje_lua_new_const(L, "PART_TYPE_TEXTBLOCK", EDJE_PART_TYPE_TEXTBLOCK);
4967 _edje_lua_new_const(L, "PART_TYPE_GRADIENT", EDJE_PART_TYPE_GRADIENT);
4968 _edje_lua_new_const(L, "PART_TYPE_GROUP", EDJE_PART_TYPE_GROUP);
4969 _edje_lua_new_const(L, "PART_TYPE_BOX", EDJE_PART_TYPE_BOX);
4970
4971 _edje_lua_new_const(L, "TEXT_EFFECT_NONE", EDJE_TEXT_EFFECT_NONE);
4972 _edje_lua_new_const(L, "TEXT_EFFECT_PLAIN", EDJE_TEXT_EFFECT_PLAIN);
4973 _edje_lua_new_const(L, "TEXT_EFFECT_OUTLINE", EDJE_TEXT_EFFECT_OUTLINE);
4974 _edje_lua_new_const(L, "TEXT_EFFECT_OTLINE", EDJE_TEXT_EFFECT_SOFT_OUTLINE);
4975 _edje_lua_new_const(L, "TEXT_EFFECT_SHADOW", EDJE_TEXT_EFFECT_SHADOW);
4976 _edje_lua_new_const(L, "TEXT_EFFECT_SOFT_SHADOW", EDJE_TEXT_EFFECT_SOFT_SHADOW);
4977 _edje_lua_new_const(L, "TEXT_EFFECT_OUTLINE_SHADOW", EDJE_TEXT_EFFECT_OUTLINE_SHADOW);
4978 _edje_lua_new_const(L, "TEXT_EFFECT_OUTLINE_SOFT_SHADOW", EDJE_TEXT_EFFECT_OUTLINE_SOFT_SHADOW);
4979 _edje_lua_new_const(L, "TEXT_EFFECT_FAR_SHADOW", EDJE_TEXT_EFFECT_FAR_SHADOW);
4980 _edje_lua_new_const(L, "TEXT_EFFECT_FAR_SOFT_SHADOW", EDJE_TEXT_EFFECT_FAR_SOFT_SHADOW);
4981 _edje_lua_new_const(L, "TEXT_EFFECT_GLOW", EDJE_TEXT_EFFECT_GLOW);
4982
4983 _edje_lua_new_const(L, "RENDER_BLEND", EVAS_RENDER_BLEND);
4984 _edje_lua_new_const(L, "RENDER_BLEND_REL", EVAS_RENDER_BLEND_REL);
4985 _edje_lua_new_const(L, "RENDER_COPY", EVAS_RENDER_COPY);
4986 _edje_lua_new_const(L, "RENDER_COPY_REL", EVAS_RENDER_COPY_REL);
4987 _edje_lua_new_const(L, "RENDER_ADD", EVAS_RENDER_ADD);
4988 _edje_lua_new_const(L, "RENDER_ADD_REL", EVAS_RENDER_ADD_REL);
4989 _edje_lua_new_const(L, "RENDER_SUB", EVAS_RENDER_SUB);
4990 _edje_lua_new_const(L, "RENDER_SUB_REL", EVAS_RENDER_SUB_REL);
4991 _edje_lua_new_const(L, "RENDER_TINT", EVAS_RENDER_TINT);
4992 _edje_lua_new_const(L, "RENDER_TINT_REL", EVAS_RENDER_TINT_REL);
4993 _edje_lua_new_const(L, "RENDER_MASK", EVAS_RENDER_MASK);
4994 _edje_lua_new_const(L, "RENDER_MUL", EVAS_RENDER_MUL);
4995
4996 _edje_lua_new_const(L, "BORDER_FILL_NONE", EVAS_BORDER_FILL_NONE);
4997 _edje_lua_new_const(L, "BORDER_FILL_DEFAULT", EVAS_BORDER_FILL_DEFAULT);
4998 _edje_lua_new_const(L, "BORDER_FILL_SOLID", EVAS_BORDER_FILL_SOLID);
4999
5000 _edje_lua_new_const(L, "POINTER_MODE_AUTOGRAB", EVAS_OBJECT_POINTER_MODE_AUTOGRAB);
5001 _edje_lua_new_const(L, "POINTER_MODE_NOGRAB", EVAS_OBJECT_POINTER_MODE_NOGRAB);
5002
5003 _edje_lua_new_const(L, "ASPECT_CONTROL_NEITHER", EVAS_ASPECT_CONTROL_NEITHER);
5004 _edje_lua_new_const(L, "ASPECT_CONTROL_HORIZONTAL", EVAS_ASPECT_CONTROL_HORIZONTAL);
5005 _edje_lua_new_const(L, "ASPECT_CONTROL_VERTICAL", EVAS_ASPECT_CONTROL_VERTICAL);
5006 _edje_lua_new_const(L, "ASPECT_CONTROL_BOTH", EVAS_ASPECT_CONTROL_BOTH);
5007
5008 _edje_lua_new_const(L, "CALLBACK_RENEW", ECORE_CALLBACK_RENEW);
5009 _edje_lua_new_const(L, "CALLBACK_CANCEL", ECORE_CALLBACK_CANCEL);
5010}
5011
5012/*
5013 * main Lua state
5014 * created by edje_init ()
5015 * closed by edje_shutdown ()
5016 * any other private Lua state inherits from this global state
5017 */
5018static lua_State *Ledje = NULL;
5019
5020lua_State *
5021_edje_lua_state_get ()
5022{
5023 return Ledje;
5024}
5025
5026/*
5027 * custom memory allocation function
5028 * raises an error, if memory usage is above the given maximum
5029 */
5030static void *
5031_edje_lua_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
5032{
5033 Edje_Lua_Alloc *ela = ud;
5034 void *ptr2;
5035
5036 ela->cur += nsize - osize;
5037 if (ela->cur > ela->max)
5038 {
5039 ERR("Edje Lua memory limit of %zu bytes reached (%zu allocated)",
5040 ela->max, ela->cur);
5041 return NULL;
5042 }
5043 if (nsize == 0)
5044 {
5045 free(ptr); /* ANSI requires that free(NULL) has no effect */
5046 return NULL;
5047 }
5048
5049 /* ANSI requires that realloc(NULL, size) == malloc(size) */
5050 ptr2 = realloc(ptr, nsize);
5051 if (ptr2) return ptr2;
5052 ERR("Edje Lua cannot re-allocate %zu bytes", nsize);
5053 return ptr2;
5054}
5055
5056void
5057_edje_lua_init()
5058{
5059 if (Ledje != NULL) return;
5060 /*
5061 * create main Lua state with the custom memory allocation function
5062 */
5063 static Edje_Lua_Alloc ela = { 1e7, 0 }; // TODO make the memory limit configurable?
5064 Ledje = lua_newstate(_edje_lua_alloc, &ela);
5065 if (!Ledje)
5066 {
5067 ERR("Lua error: Lua state could not be initialized");
5068 exit(-1);
5069 }
5070
5071 lua_atpanic(Ledje, _edje_lua_custom_panic);
5072
5073 /*
5074 * configure Lua garbage collector
5075 * TODO optimize garbage collector for typical edje use or make it configurable
5076 */
5077 lua_gc(Ledje, LUA_GCSETPAUSE, 200);
5078 lua_gc(Ledje, LUA_GCSETSTEPMUL, 200);
5079
5080 /*
5081 * sandbox Lua
5082 * no access to io, os and package routines
5083 * no loading and execution of files
5084 * no loading and execution of strings
5085 * no access to the OS environment
5086 */
5087 luaopen_base(Ledje);
5088 luaopen_table(Ledje);
5089 luaopen_string(Ledje);
5090 luaopen_math(Ledje);
5091 luaopen_os(Ledje);
5092
5093 /*
5094 * FIXME
5095 * this is just for debug purposes
5096 * remove it in the final version
5097 */
5098 lua_pushnil(Ledje);
5099 lua_setglobal(Ledje, "load");
5100 lua_pushnil(Ledje);
5101 lua_setglobal(Ledje, "loadfile");
5102 lua_pushnil(Ledje);
5103 lua_setglobal(Ledje, "loadstring");
5104 lua_pushnil(Ledje);
5105 lua_setglobal(Ledje, "dofile");
5106 lua_pushnil(Ledje);
5107 lua_setglobal(Ledje, "dostring");
5108
5109 lua_getglobal(Ledje, "os");
5110 lua_pushnil(Ledje);
5111 lua_setfield(Ledje, -2, "exit");
5112 lua_pushnil(Ledje);
5113 lua_setfield(Ledje, -2, "setlocale");
5114 lua_pushnil(Ledje);
5115 lua_setfield(Ledje, -2, "getenv");
5116 lua_pushnil(Ledje);
5117 lua_setfield(Ledje, -2, "remove");
5118 lua_pushnil(Ledje);
5119 lua_setfield(Ledje, -2, "tmpname");
5120 lua_pushnil(Ledje);
5121 lua_setfield(Ledje, -2, "rename");
5122 lua_pushnil(Ledje);
5123 lua_setfield(Ledje, -2, "execute");
5124 lua_pushnil(Ledje);
5125
5126 /*
5127 * we need a weak value registry
5128 * so that deleted and unused objects can be garbage collected
5129 */
5130 lua_createtable(Ledje, 1, 0);
5131 //lua_pushstring(Ledje, "v");
5132 lua_pushstring(Ledje, "");
5133 lua_setfield(Ledje, -2, "__mode");
5134 lua_setmetatable(Ledje, LUA_REGISTRYINDEX);
5135
5136 /*
5137 * load Lua Evas/Edje bindings
5138 */
5139 _edje_lua_open(Ledje);
5140}
5141
5142void
5143_edje_lua_shutdown()
5144{
5145 if (Ledje == NULL) return;
5146 lua_close(Ledje);
5147 Ledje = NULL;
5148}
5149
5150#endif