diff --git a/legacy/edje/configure.ac b/legacy/edje/configure.ac index 82a7167657..dd82a5185c 100644 --- a/legacy/edje/configure.ac +++ b/legacy/edje/configure.ac @@ -183,6 +183,18 @@ AC_SUBST(EFL_EDJE_BUILD) # Dependencies for the library +# Lua pkg-config hack for different naming conventions +requirement_lua="" +PKG_CHECK_MODULES([LUA], [lua >= 5.1.0], requirement_lua="lua", + [PKG_CHECK_MODULES([LUA], [lua5.1 >= 5.1.0], requirement_lua="lua5.1", + [PKG_CHECK_MODULES([LUA], [lua-5.1 >= 5.1.0], requirement_lua="lua-5.1", + [PKG_CHECK_MODULES([LUA], [lua51 >= 5.1.0], requirement_lua="lua51", + AC_MSG_ERROR([unable to find Lua]) + ) + ]) + ]) +]) + PKG_CHECK_MODULES([EDJE], [ eina-0 @@ -193,7 +205,11 @@ PKG_CHECK_MODULES([EDJE], embryo >= 0.9.1 ]) +EDJE_LIBS="$EDJE_LIBS $LUA_LIBS" +EDJE_CFLAGS="$EDJE_CFLAGS $LUA_CFLAGS" + requirement_edje="embryo ecore-job ecore evas eet eina-0 ${requirement_edje}" +requirement_edje="${requirement_lua} ${requirement_edje}" have_ecore_imf="no" PKG_CHECK_MODULES([ECORE_IMF], diff --git a/legacy/edje/data/edc.vim b/legacy/edje/data/edc.vim index 7e470b4efa..f4407c6843 100644 --- a/legacy/edje/data/edc.vim +++ b/legacy/edje/data/edc.vim @@ -15,7 +15,7 @@ endif syn keyword cStructure images data fonts collections group syn keyword cStructure part parts dragable description rel1 rel2 syn keyword cStatement text image font fill origin size tag -syn keyword cStructure programs program script styles style base +syn keyword cStructure programs program script script_only lua_script lua_script_only styles style base syn keyword cStructure spectra spectrum syn match cType "+ + +;" contained @@ -35,6 +35,7 @@ syn keyword cConstant TEXT IMAGE RECT SWALLOW syn keyword cConstant NONE PLAIN OUTLINE SOFT_OUTLINE SHADOW syn keyword cConstant SOFT_SHADOW OUTLINE_SHADOW OUTLINE_SOFT_SHADOW syn keyword cConstant STATE_SET ACTION_STOP SIGNAL_EMIT +syn keyword cConstant SCRIPT LUA_SCRIPT syn keyword cConstant DRAG_VAL_SET DRAG_VAL_STEP DRAG_VAL_PAGE syn keyword cConstant LINEAR SINUSOIDAL ACCELERATE DECELERATE syn keyword cConstant "default" diff --git a/legacy/edje/src/bin/edje_cc.h b/legacy/edje/src/bin/edje_cc.h index 117a1bc5a6..a27d586416 100644 --- a/legacy/edje/src/bin/edje_cc.h +++ b/legacy/edje/src/bin/edje_cc.h @@ -50,6 +50,7 @@ struct _Code int l1, l2; char *shared; Eina_List *programs; + int is_lua; }; struct _Code_Program diff --git a/legacy/edje/src/bin/edje_cc_handlers.c b/legacy/edje/src/bin/edje_cc_handlers.c index c68a4e3ad8..cf8c638a1b 100644 --- a/legacy/edje/src/bin/edje_cc_handlers.c +++ b/legacy/edje/src/bin/edje_cc_handlers.c @@ -78,12 +78,14 @@ static void ob_collections(void); static void ob_collections_group(void); static void st_collections_group_name(void); static void st_collections_group_script_only(void); +static void st_collections_group_lua_script_only(void); static void st_collections_group_alias(void); static void st_collections_group_min(void); static void st_collections_group_max(void); static void st_collections_group_data_item(void); static void ob_collections_group_script(void); +static void ob_collections_group_lua_script(void); static void ob_collections_group_parts_part(void); static void st_collections_group_parts_part_name(void); @@ -205,6 +207,7 @@ static void st_collections_group_programs_program_target(void); static void st_collections_group_programs_program_after(void); static void ob_collections_group_programs_program_script(void); +static void ob_collections_group_programs_program_lua_script(void); /*****/ @@ -237,6 +240,7 @@ New_Statement_Handler statement_handlers[] = {"collections.color_classes.color_class.color3", st_color_class_color3}, /* dup */ {"collections.group.name", st_collections_group_name}, {"collections.group.script_only", st_collections_group_script_only}, + {"collections.group.lua_script_only", st_collections_group_lua_script_only}, {"collections.group.alias", st_collections_group_alias}, {"collections.group.min", st_collections_group_min}, {"collections.group.max", st_collections_group_max}, @@ -504,6 +508,7 @@ New_Object_Handler object_handlers[] = {"collections.group", ob_collections_group}, {"collections.group.data", NULL}, {"collections.group.script", ob_collections_group_script}, + {"collections.group.lua_script", ob_collections_group_lua_script}, {"collections.group.images", NULL}, /* dup */ {"collections.group.fonts", NULL}, /* dup */ {"collections.group.styles", NULL}, /* dup */ @@ -554,36 +559,48 @@ New_Object_Handler object_handlers[] = {"collections.group.parts.part.description.color_classes.color_class", ob_color_class}, /* dup */ {"collections.group.parts.part.description.program", ob_collections_group_programs_program}, /* dup */ {"collections.group.parts.part.description.program.script", ob_collections_group_programs_program_script}, /* dup */ + {"collections.group.parts.part.description.program.lua_script", ob_collections_group_programs_program_lua_script}, /* dup */ {"collections.group.parts.part.description.programs", NULL}, /* dup */ {"collections.group.parts.part.description.programs.images", NULL}, /* dup */ {"collections.group.parts.part.description.programs.fonts", NULL}, /* dup */ {"collections.group.parts.part.description.programs.program", ob_collections_group_programs_program}, /* dup */ {"collections.group.parts.part.description.programs.program.script", ob_collections_group_programs_program_script}, /* dup */ + {"collections.group.parts.part.description.programs.program.lua_script", ob_collections_group_programs_program_lua_script}, /* dup */ {"collections.group.parts.part.description.script", ob_collections_group_script}, /* dup */ + {"collections.group.parts.part.description.lua_script", ob_collections_group_lua_script}, /* dup */ {"collections.group.parts.part.program", ob_collections_group_programs_program}, /* dup */ {"collections.group.parts.part.program.script", ob_collections_group_programs_program_script}, /* dup */ + {"collections.group.parts.part.program.lua_script", ob_collections_group_programs_program_lua_script}, /* dup */ {"collections.group.parts.part.programs", NULL}, /* dup */ {"collections.group.parts.part.programs.images", NULL}, /* dup */ {"collections.group.parts.part.programs.fonts", NULL}, /* dup */ {"collections.group.parts.part.programs.program", ob_collections_group_programs_program}, /* dup */ {"collections.group.parts.part.programs.program.script", ob_collections_group_programs_program_script}, /* dup */ + {"collections.group.parts.part.programs.program.lua_script", ob_collections_group_programs_program_lua_script}, /* dup */ {"collections.group.parts.part.script", ob_collections_group_script}, /* dup */ + {"collections.group.parts.part.lua_script", ob_collections_group_lua_script}, /* dup */ {"collections.group.parts.program", ob_collections_group_programs_program}, /* dup */ {"collections.group.parts.program.script", ob_collections_group_programs_program_script}, /* dup */ + {"collections.group.parts.program.lua_script", ob_collections_group_programs_program_lua_script}, /* dup */ {"collections.group.parts.programs", NULL}, /* dup */ {"collections.group.parts.programs.images", NULL}, /* dup */ {"collections.group.parts.programs.fonts", NULL}, /* dup */ {"collections.group.parts.programs.program", ob_collections_group_programs_program}, /* dup */ {"collections.group.parts.programs.program.script", ob_collections_group_programs_program_script}, /* dup */ + {"collections.group.parts.programs.program.lua_script", ob_collections_group_programs_program_lua_script}, /* dup */ {"collections.group.parts.script", ob_collections_group_script}, /* dup */ + {"collections.group.parts.lua_script", ob_collections_group_lua_script}, /* dup */ {"collections.group.program", ob_collections_group_programs_program}, /* dup */ {"collections.group.program.script", ob_collections_group_programs_program_script}, /* dup */ + {"collections.group.program.lua_script", ob_collections_group_programs_program_lua_script}, /* dup */ {"collections.group.programs", NULL}, {"collections.group.programs.images", NULL}, /* dup */ {"collections.group.programs.fonts", NULL}, /* dup */ {"collections.group.programs.program", ob_collections_group_programs_program}, {"collections.group.programs.program.script", ob_collections_group_programs_program_script}, - {"collections.group.programs.script", ob_collections_group_script} /* dup */ + {"collections.group.programs.program.lua_script", ob_collections_group_programs_program_lua_script}, + {"collections.group.programs.script", ob_collections_group_script}, /* dup */ + {"collections.group.programs.lua_script", ob_collections_group_lua_script} /* dup */ }; /*****/ @@ -1368,6 +1385,17 @@ st_collections_group_script_only(void) pc->script_only = parse_bool(0); } +static void +st_collections_group_lua_script_only(void) +{ + Edje_Part_Collection *pc; + + check_arg_count(1); + + pc = eina_list_data_get(eina_list_last(edje_collections)); + pc->lua_script_only = parse_bool(0); +} + /** @page edcref @property @@ -1494,6 +1522,39 @@ ob_collections_group_script(void) exit(-1); } cd->shared = s; + cd->is_lua = 0; + set_verbatim(NULL, 0, 0); + } + } +} + +static void +ob_collections_group_lua_script(void) +{ + Edje_Part_Collection *pc; + Code *cd; + + pc = eina_list_data_get(eina_list_last(edje_collections)); + cd = eina_list_data_get(eina_list_last(codes)); + + if (!is_verbatim()) track_verbatim(1); + else + { + char *s; + + s = get_verbatim(); + if (s) + { + cd->l1 = get_verbatim_line1(); + cd->l2 = get_verbatim_line2(); + if (cd->shared) + { + fprintf(stderr, "%s: Error. parse error %s:%i. There is already an existing script section for the group\n", + progname, file_in, line - 1); + exit(-1); + } + cd->shared = s; + cd->is_lua = 1; set_verbatim(NULL, 0, 0); } } @@ -5604,6 +5665,7 @@ st_collections_group_programs_program_action(void) "DRAG_VAL_STEP", EDJE_ACTION_TYPE_DRAG_VAL_STEP, "DRAG_VAL_PAGE", EDJE_ACTION_TYPE_DRAG_VAL_PAGE, "SCRIPT", EDJE_ACTION_TYPE_SCRIPT, + "LUA_SCRIPT", EDJE_ACTION_TYPE_LUA_SCRIPT, "FOCUS_SET", EDJE_ACTION_TYPE_FOCUS_SET, NULL); if (ep->action == EDJE_ACTION_TYPE_STATE_SET) @@ -5641,6 +5703,10 @@ st_collections_group_programs_program_action(void) /* this is implicitly set by script {} so this is here just for * completeness */ break; + case EDJE_ACTION_TYPE_LUA_SCRIPT: + /* this is implicitly set by lua_script {} so this is here just for + * completeness */ + break; case EDJE_ACTION_TYPE_FOCUS_SET: check_arg_count(1); break; @@ -5797,12 +5863,59 @@ ob_collections_group_programs_program_script(void) cp->l2 = get_verbatim_line2(); cp->id = ep->id; cp->script = s; + if (cd->shared && cd->is_lua) + { + fprintf(stderr, "%s: Error. parse error %s:%i. You're trying to mix Embryo and Lua scripting in the same group\n", + progname, file_in, line - 1); + exit(-1); + } + cd->is_lua = 0; cd->programs = eina_list_append(cd->programs, cp); set_verbatim(NULL, 0, 0); ep->action = EDJE_ACTION_TYPE_SCRIPT; } } } + +static void +ob_collections_group_programs_program_lua_script(void) +{ + Edje_Part_Collection *pc; + Edje_Program *ep; + Code *cd; + + pc = eina_list_data_get(eina_list_last(edje_collections)); + ep = eina_list_data_get(eina_list_last(pc->programs)); + cd = eina_list_data_get(eina_list_last(codes)); + + if (!is_verbatim()) track_verbatim(1); + else + { + char *s; + + s = get_verbatim(); + if (s) + { + Code_Program *cp; + + cp = mem_alloc(SZ(Code_Program)); + cp->l1 = get_verbatim_line1(); + cp->l2 = get_verbatim_line2(); + cp->id = ep->id; + cp->script = s; + if (cd->shared && !cd->is_lua) + { + fprintf(stderr, "%s: Error. parse error %s:%i. You're trying to mix Embryo and Lua scripting in the same group\n", + progname, file_in, line - 1); + exit(-1); + } + cd->is_lua = 1; + cd->programs = eina_list_append(cd->programs, cp); + set_verbatim(NULL, 0, 0); + ep->action = EDJE_ACTION_TYPE_LUA_SCRIPT; + } + } +} /** @page edcref diff --git a/legacy/edje/src/bin/edje_cc_out.c b/legacy/edje/src/bin/edje_cc_out.c index 2db802f588..69636cd3de 100644 --- a/legacy/edje/src/bin/edje_cc_out.c +++ b/legacy/edje/src/bin/edje_cc_out.c @@ -33,6 +33,9 @@ void *alloca (size_t); #include "edje_cc.h" #include "edje_prefix.h" +#include +#include + typedef struct _Part_Lookup Part_Lookup; typedef struct _Program_Lookup Program_Lookup; typedef struct _Group_Lookup Group_Lookup; @@ -769,7 +772,9 @@ data_write_scripts(Eet_File *ef) { int fd; Code *cd = eina_list_data_get(l); - + + if (cd->is_lua) + continue; if ((!cd->shared) && (!cd->programs)) continue; @@ -801,6 +806,142 @@ data_write_scripts(Eet_File *ef) } } +typedef struct _Edje_Lua_Script_Writer_Struct Edje_Lua_Script_Writer_Struct; + +struct _Edje_Lua_Script_Writer_Struct { + void *buf; + int size; +}; + +static int +_edje_lua_script_writer (lua_State *L, const void* chunk_buf, size_t chunk_size, void* _data) +{ + Edje_Lua_Script_Writer_Struct *data = _data; + void *old = data->buf; + data->buf = malloc (data->size + chunk_size); + memcpy (data->buf, old, data->size); + memcpy (&((data->buf)[data->size]), chunk_buf, chunk_size); + if (old) + free (old); + data->size += chunk_size; + return 0; +} + +void +_edje_lua_error_and_abort(lua_State * L, int err_code, Edje_File *ef) +{ + char *err_type; + switch (err_code) + { + case LUA_ERRRUN: + err_type = "runtime"; + break; + case LUA_ERRSYNTAX: + err_type = "syntax"; + break; + case LUA_ERRMEM: + err_type = "memory allocation"; + break; + case LUA_ERRERR: + err_type = "error handler"; + break; + default: + err_type = "unknown"; + break; + } + error_and_abort(ef, "Lua %s error: %s\n", err_type, lua_tostring(L, -1)); +} + + +static void +data_write_lua_scripts(Eet_File *ef) +{ + Eina_List *l; + Eina_List *ll; + Code_Program *cp; + int i; + + for (i = 0, l = codes; l; l = eina_list_next(l), i++) + { + Code *cd = eina_list_data_get(l); + if (!cd->is_lua) + continue; + if ((!cd->shared) && (!cd->programs)) + continue; + + lua_State *L = luaL_newstate(); + if (!L) + error_and_abort(ef, "Lua error: Lua state could not be initialized\n"); + + int ln = 1; + luaL_Buffer b; + luaL_buffinit(L, &b); + + Edje_Lua_Script_Writer_Struct data; + data.buf = NULL; + data.size = 0; + if (cd->shared) + { + while (ln < (cd->l1 - 1)) + { + luaL_addchar(&b, '\n'); + ln++; + } + luaL_addstring(&b, cd->shared); + ln += cd->l2 - cd->l1; + } + + EINA_LIST_FOREACH(cd->programs, ll, cp) + { + if (cp->script) + { + while (ln < (cp->l1 - 1)) + { + luaL_addchar(&b, '\n'); + ln++; + } + luaL_addstring(&b, "_G["); + lua_pushnumber(L, cp->id); + luaL_addvalue(&b); + luaL_addstring(&b, "] = function (ed, signal, source)"); + luaL_addstring(&b, cp->script); + luaL_addstring(&b, "end\n"); + ln += cp->l2 - cp->l1 + 1; + } + } + luaL_pushresult(&b); +#ifdef LUA_BINARY + int err_code; + if (err_code = luaL_loadstring(L, lua_tostring (L, -1))) + _edje_lua_error_and_abort(L, err_code, ef); + lua_dump(L, _edje_lua_script_writer, &data); +#else // LUA_PLAIN_TEXT + data.buf = lua_tostring(L, -1); + data.size = strlen(data.buf); +#endif + //printf("lua chunk size: %d\n", data.size); + + /* + * TODO load and test Lua chunk + */ + + /* + if (luaL_loadbuffer(L, globbuf, globbufsize, "edje_lua_script")) + printf("lua load error: %s\n", lua_tostring (L, -1)); + if (lua_pcall(L, 0, 0, 0)) + printf("lua call error: %s\n", lua_tostring (L, -1)); + */ + + char buf[4096]; + snprintf(buf, sizeof(buf), "lua_scripts/%i", i); + eet_write(ef, buf, data.buf, data.size, 1); +#ifdef LUA_BINARY + free(data.buf); +#endif + lua_close(L); + } +} + void data_write(void) { @@ -834,6 +975,7 @@ data_write(void) total_bytes += data_write_groups(ef, &collection_num); data_write_scripts(ef); + data_write_lua_scripts(ef); src_bytes = source_append(ef); total_bytes += src_bytes; @@ -1325,7 +1467,7 @@ data_process_scripts(void) Eina_List *ll; Code_Program *cp; - if (cd->shared) + if ((cd->shared) && (!cd->is_lua)) { data_process_string(pc, "PART", cd->shared, _data_queue_part_lookup); data_process_string(pc, "PROGRAM", cd->shared, _data_queue_program_lookup); diff --git a/legacy/edje/src/lib/Makefile.am b/legacy/edje/src/lib/Makefile.am index 0e6b159b1d..6a4c7d5fcd 100644 --- a/legacy/edje/src/lib/Makefile.am +++ b/legacy/edje/src/lib/Makefile.am @@ -23,6 +23,7 @@ edje_calc.c \ edje_callbacks.c \ edje_data.c \ edje_embryo.c \ +edje_lua.c \ edje_load.c \ edje_main.c \ edje_misc.c \ @@ -40,6 +41,7 @@ edje_match.c \ edje_textblock_styles.c \ edje_edit.c \ edje_script_only.c \ +edje_lua_script_only.c \ edje_entry.c libedje_la_LIBADD = @EDJE_LIBS@ @ECORE_IMF_LIBS@ -lm diff --git a/legacy/edje/src/lib/edje_cache.c b/legacy/edje/src/lib/edje_cache.c index c505502667..f36af0e89f 100644 --- a/legacy/edje/src/lib/edje_cache.c +++ b/legacy/edje/src/lib/edje_cache.c @@ -67,6 +67,28 @@ _edje_file_coll_open(Edje_File *edf, const char *coll) free(data); } + snprintf(buf, sizeof(buf), "lua_scripts/%i", id); + data = eet_read(edf->ef, buf, &size); + + if (data) + { + //printf("lua chunk size: %d\n", size); + edc->L = _edje_lua_new_thread(_edje_lua_state_get()); // gets freed in 'edje_load::_edje_collection_free' + _edje_lua_new_reg(edc->L, -1, edc); // gets freed in 'edje_load::_edje_collectoin_free' + + int err_code; + if (err_code = luaL_loadbuffer(edc->L, data, size, "edje_lua_script")); + { + if (err_code == LUA_ERRSYNTAX) + printf("lua load syntax error: %s\n", lua_tostring(edc->L, -1)); + else if (err_code == LUA_ERRMEM) + printf("lua load memory allocation error: %s\n", lua_tostring(edc->L, -1)); + } + if (lua_pcall(edc->L, 0, 0, 0)) + printf("lua call error: %s\n", lua_tostring(edc->L, -1)); + free(data); + } + edc->part = eina_stringshare_add(coll); edc->references = 1; if (!edf->collection_hash) diff --git a/legacy/edje/src/lib/edje_data.c b/legacy/edje/src/lib/edje_data.c index da2340a7f2..141153fe7a 100644 --- a/legacy/edje/src/lib/edje_data.c +++ b/legacy/edje/src/lib/edje_data.c @@ -396,4 +396,5 @@ _edje_edd_setup(void) EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection, Edje_Part_Collection, "prop.max.h", prop.max.h, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection, Edje_Part_Collection, "id", id, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection, Edje_Part_Collection, "script_only", script_only, EET_T_UCHAR); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection, Edje_Part_Collection, "lua_script_only", lua_script_only, EET_T_UCHAR); } diff --git a/legacy/edje/src/lib/edje_load.c b/legacy/edje/src/lib/edje_load.c index 08c469d85a..955d7e3f41 100644 --- a/legacy/edje/src/lib/edje_load.c +++ b/legacy/edje/src/lib/edje_load.c @@ -296,6 +296,7 @@ _edje_object_file_set_internal(Evas_Object *obj, const char *file, const char *g old_swallows = _edje_swallows_collect(ed); if (_edje_script_only(ed)) _edje_script_only_shutdown(ed); + if (_edje_lua_script_only(ed)) _edje_lua_script_only_shutdown(ed); _edje_file_del(ed); if (ed->path) eina_stringshare_del(ed->path); @@ -316,6 +317,11 @@ _edje_object_file_set_internal(Evas_Object *obj, const char *file, const char *g ed->load_error = EDJE_LOAD_ERROR_NONE; _edje_script_only_init(ed); } + else if (ed->collection->lua_script_only) + { + ed->load_error = EDJE_LOAD_ERROR_NONE; + _edje_lua_script_only_init(ed); + } else { Eina_List *l; @@ -849,7 +855,16 @@ _edje_file_del(Edje *ed) if (rp->text.cache.out_str) eina_stringshare_del(rp->text.cache.out_str); if (rp->custom) - _edje_collection_free_part_description_free(rp->custom->description, ed->file->free_strings); + { + if (ed->L) + { + _edje_lua_get_reg(ed->L, rp->custom->description); + _edje_lua_free_reg(ed->L, lua_touserdata(ed->L, -1)); // created in edje_lua.c::_edje_lua_part_fn_custom_state + lua_pop(ed->L, 1); + _edje_lua_free_reg(ed->L, rp->custom->description); // created in edje_lua.c::_edje_lua_part_fn_custom_state + } + _edje_collection_free_part_description_free(rp->custom->description, ed->file->free_strings); + } /* Cleanup optional part. */ free(rp->drag); @@ -898,6 +913,13 @@ _edje_file_del(Edje *ed) free(pp); } } + if (ed->L) + { + _edje_lua_free_reg(ed->L, ed); // created in edje_lua.c::_edje_lua_script_fn_new/_edje_lua_group_fn_new + _edje_lua_free_reg(ed->L, ed->L); // created in edje_program.c::_edje_program_run/edje_lua_script_only.c::_edje_lua_script_only_init + _edje_lua_free_thread(ed->L); // created in edje_program.c::_edje_program_run/edje_lua_script_only.c::_edje_lua_script_only_init + ed->L = NULL; + } if (ed->table_parts) free(ed->table_parts); ed->table_parts = NULL; ed->table_parts_size = 0; @@ -1096,6 +1118,12 @@ _edje_collection_free(Edje_File *edf, Edje_Part_Collection *ec) } #endif if (ec->script) embryo_program_free(ec->script); + if (ec->L) + { + _edje_lua_free_reg(ec->L, ec); // created in edje_cache.c::_edje_file_coll_open + _edje_lua_free_thread(ec->L); // created in edje_cache.c::_edje_file_coll_open + ec->L = NULL; + } free(ec); } diff --git a/legacy/edje/src/lib/edje_lua.c b/legacy/edje/src/lib/edje_lua.c new file mode 100644 index 0000000000..d4ca8ce90e --- /dev/null +++ b/legacy/edje/src/lib/edje_lua.c @@ -0,0 +1,5105 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#ifdef HAVE_ALLOCA_H +# include +#elif defined __GNUC__ +# define alloca __builtin_alloca +#elif defined _AIX +# define alloca __alloca +#elif defined _MSC_VER +# include +# define alloca _alloca +#else +# include +# ifdef __cplusplus +extern "C" +# endif +void *alloca(size_t); +#endif + +#include "edje_private.h" + +#include +#include + +/* + * Edje_Lua framework definitions + */ + +#define EDJE_LUA_GET 1 +#define EDJE_LUA_SET 2 +#define EDJE_LUA_FN 3 + +typedef struct _Edje_Lua_Alloc Edje_Lua_Alloc; + +typedef struct _Edje_Lua_Ref Edje_Lua_Ref; + +typedef struct _Edje_Lua_Reg Edje_Lua_Reg; + +typedef struct _Edje_Lua_Timer Edje_Lua_Timer; + +typedef struct _Edje_Lua_Animator Edje_Lua_Animator; + +typedef struct _Edje_Lua_Poller Edje_Lua_Poller; + +typedef struct _Edje_Lua_Transform Edje_Lua_Transform; + +typedef struct _Edje_Lua_Transition Edje_Lua_Transition; + +typedef struct _Edje_Lua_Evas_Object Edje_Lua_Evas_Object; + +typedef struct _Edje_Lua_Edje_Part_Object Edje_Lua_Edje_Part_Object; + +typedef struct _Edje_Lua_Edje_Part_Description Edje_Lua_Edje_Part_Description; + +struct _Edje_Lua_Alloc +{ + size_t max, cur; /* maximal and current memory used by Lua */ +}; + +struct _Edje_Lua_Ref +{ + int id; + lua_State *L; +}; + +struct _Edje_Lua_Reg +{ + const luaL_Reg *mt, *get, *set, *fn; +}; + +struct _Edje_Lua_Timer +{ + lua_State *L; + Ecore_Timer *et; + Edje_Lua_Ref *cb; +}; + +struct _Edje_Lua_Animator +{ + lua_State *L; + Ecore_Animator *ea; + Edje_Lua_Ref *cb; +}; + +struct _Edje_Lua_Poller +{ + lua_State *L; + Ecore_Poller *ep; + Edje_Lua_Ref *cb; +}; + +struct _Edje_Lua_Transform +{ + lua_State *L; + Evas_Transform et; +}; + +struct _Edje_Lua_Transition +{ + lua_State *L; + Ecore_Timer *et; + Edje_Lua_Ref *trans; + Edje_Lua_Ref *cb; + Edje_Lua_Ref *ref; + double dur; +}; + +struct _Edje_Lua_Evas_Object +{ + lua_State *L; + Edje *ed; + Evas_Object *eo; + Eina_Bool mouse_events; + Eina_List *cb; +}; + +struct _Edje_Lua_Edje_Part_Object +{ + lua_State *L; + Edje *ed; + Evas_Object *eo; + Edje_Real_Part *rp; + const char *key; +}; + +struct _Edje_Lua_Edje_Part_Description +{ + lua_State *L; + Edje *ed; + Evas_Object *eo; + Edje_Real_Part *rp; + Edje_Part_Description *pd; +}; + +void +_edje_lua_error(lua_State *L, int err_code) +{ + char *err_type; + + switch (err_code) + { + case LUA_ERRRUN: + err_type = "runtime"; + break; + case LUA_ERRSYNTAX: + err_type = "syntax"; + break; + case LUA_ERRMEM: + err_type = "memory allocation"; + break; + case LUA_ERRERR: + err_type = "error handler"; + break; + default: + err_type = "unknown"; + break; + } + fprintf(stderr, "Lua %s error: %s\n", err_type, lua_tostring(L, -1)); + exit(-1); +} + +lua_State * +_edje_lua_new_thread(lua_State *L) +{ + /* create new thread */ + lua_State *thread = lua_newthread(L); + //printf ("new thread %d->%d\n", L, thread); + /* create new environment for new thread */ + lua_newtable(L); + /* inherit new environment from global environment */ + lua_createtable(L, 1, 0); + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfield(L, -2, "__index"); + lua_setmetatable(L, -2); + lua_setfenv(L, -2); + return thread; +} + +void +_edje_lua_free_thread(lua_State *L) +{ + lua_pushthread(L); + lua_getfenv(L, -1); + lua_pushnil(L); + while (lua_next(L, -2)) + { + // key at -2, value at -1 + lua_pop(L, 1); + lua_pushvalue(L, -1); + lua_pushnil(L); + lua_rawset(L, -4); + } + lua_settop(L, 0); + lua_gc(L, LUA_GCCOLLECT, 0); +} + +/* + * only for debug, returns number of objects in registry + */ +static int +_edje_lua_reg_count (lua_State *L) +{ + int count = 0; + lua_pushvalue(L, LUA_REGISTRYINDEX); + lua_pushnil(L); + while (lua_next(L, -2)) + { + // key at -2, value at -1 + lua_pop(L, 1); + count++; + } + lua_pop(L, 1); + return count; +} + +static Edje_Lua_Ref * +_edje_lua_new_ref(lua_State *L, int index) +{ + //printf ("_edje_lua_new_ref %d %d %d\n", L, lua_objlen(L, LUA_REGISTRYINDEX), _edje_lua_reg_count(L)); + lua_pushvalue(L, index); + Edje_Lua_Ref *ref = malloc(sizeof(Edje_Lua_Ref)); + ref->id = luaL_ref(L, LUA_REGISTRYINDEX); + ref->L = L; + return ref; +} + +static void +_edje_lua_get_ref(lua_State *L, Edje_Lua_Ref *ref) +{ + lua_rawgeti(L, LUA_REGISTRYINDEX, ref->id); +} + +static void +_edje_lua_free_ref(lua_State *L, Edje_Lua_Ref *ref) +{ + //printf ("_edje_lua_free_ref %d %d %d\n", L, lua_objlen(L, LUA_REGISTRYINDEX), _edje_lua_reg_count(L)); + luaL_unref(L, LUA_REGISTRYINDEX, ref->id); + free(ref); + lua_gc(L, LUA_GCCOLLECT, 0); +} + +void +_edje_lua_new_reg(lua_State *L, int index, void *ptr) +{ + //printf ("_edje_lua_new_reg %d %d %d\n", L, ptr, _edje_lua_reg_count(L)); + lua_pushvalue(L, index); + lua_pushlightuserdata(L, ptr); + lua_insert(L, -2); + lua_rawset(L, LUA_REGISTRYINDEX); /* freed in _edje_lua_free_reg */ +} + +void +_edje_lua_get_reg(lua_State *L, void *ptr) +{ + //printf ("_edje_lua_get_reg %d %d\n", L, ptr); + lua_pushlightuserdata(L, ptr); + lua_rawget(L, LUA_REGISTRYINDEX); +} + +void +_edje_lua_free_reg(lua_State *L, void *ptr) +{ + //printf ("_edje_lua_free_reg %d %d %d\n", L, ptr, _edje_lua_reg_count(L)); + lua_pushlightuserdata(L, ptr); + lua_pushnil(L); + lua_rawset(L, LUA_REGISTRYINDEX); /* created in _edje_lua_new_reg */ + lua_gc(L, LUA_GCCOLLECT, 0); +} + +static void +_edje_lua_rawsetfield(lua_State *L, int index, const char *key) +{ + lua_pushstring(L, key); + lua_insert(L, -2); + if (index < 0) + lua_rawset(L, index - 1); + else + lua_rawset(L, index); +} + +static void +_edje_lua_rawgetfield(lua_State *L, int index, const char *key) +{ + lua_pushstring(L, key); + if (index < 0) + lua_rawget(L, index - 1); + else + lua_rawget(L, index); +} + +static void +_edje_lua_new_const(lua_State *L, const char *id, int val) +{ + lua_pushnumber(L, val); + lua_setglobal(L, id); +} + +static void +_edje_lua_new_metatable(lua_State *L, const Edje_Lua_Reg ** class) +{ + lua_newtable(L); + lua_pushlightuserdata(L, class); + lua_pushvalue(L, -2); + lua_rawset(L, LUA_REGISTRYINDEX); /* freed in _edje_lua_free_metatable */ + lua_pushvalue(L, -1); + lua_pushlightuserdata(L, class); + lua_rawset(L, LUA_REGISTRYINDEX); /* freed in _edje_lua_free_metatable */ +} + +static void +_edje_lua_get_metatable(lua_State *L, const Edje_Lua_Reg ** class) +{ + lua_pushlightuserdata(L, class); + lua_rawget(L, LUA_REGISTRYINDEX); +} + +static void +_edje_lua_free_metatable(lua_State *L, const Edje_Lua_Reg ** class) +{ + lua_pushlightuserdata(L, class); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_pushnil(L); + lua_rawset(L, LUA_REGISTRYINDEX); /* created in _edje_lua_new_metatable */ + lua_pushlightuserdata(L, class); + lua_pushnil(L); + lua_rawset(L, LUA_REGISTRYINDEX); /* created in _edje_lua_new_metatable */ + lua_gc(L, LUA_GCCOLLECT, 0); +} + +void * +_edje_lua_checkudata(lua_State *L, int pos, const Edje_Lua_Reg * module) +{ + luaL_checktype(L, pos, LUA_TUSERDATA); + lua_getmetatable(L, pos); + lua_rawget(L, LUA_REGISTRYINDEX); + Edje_Lua_Reg **class = lua_touserdata(L, -1); + lua_pop(L, 1); // class + int flag = 0; + int ptr = 0; + while (class[ptr] && !flag) + if (class[ptr++] == module) + flag = 1; + if (!flag) + { + lua_pushstring(L, "class type mismatch"); + lua_error(L); + } + return lua_touserdata(L, pos); +} + +static void +_edje_lua_new_class(lua_State *L, const Edje_Lua_Reg ** class) +{ + int n = 0; + _edje_lua_new_metatable(L, class); + while (class && (class[n] != NULL)) + { + luaL_register(L, NULL, class[n]->mt); + lua_pushstring(L, "hands off, it's none of your business!"); + _edje_lua_rawsetfield(L, -2, "__metatable"); + + if (n == 0) + { + lua_newtable(L); + luaL_register(L, NULL, class[n]->set); + lua_rawseti (L, -2, EDJE_LUA_SET); + + lua_newtable(L); + luaL_register(L, NULL, class[n]->get); + lua_rawseti (L, -2, EDJE_LUA_GET); + + lua_newtable(L); + luaL_register(L, NULL, class[n]->fn); + lua_rawseti (L, -2, EDJE_LUA_FN); + } + else + { + lua_rawgeti(L, -1, EDJE_LUA_SET); + luaL_register(L, NULL, class[n]->set); + lua_pop(L, 1); + + lua_rawgeti(L, -1, EDJE_LUA_GET); + luaL_register(L, NULL, class[n]->get); + lua_pop(L, 1); + + lua_rawgeti(L, -1, EDJE_LUA_FN); + luaL_register(L, NULL, class[n]->fn); + lua_pop(L, 1); + } + n += 1; + } +} + +static void +_edje_lua_set_class(lua_State *L, int index, const Edje_Lua_Reg ** class) +{ + lua_newtable(L); + if (index < 0) + lua_setfenv(L, index - 1); + else + lua_setfenv(L, index); + + _edje_lua_get_metatable(L, class); + if (index < 0) + lua_setmetatable(L, index - 1); + else + lua_setmetatable(L, index); +} + +int +_edje_lua_look_fn(lua_State *L) +{ + lua_rawgeti(L, -1, EDJE_LUA_FN); + lua_pushvalue(L, 2); // key + lua_rawget(L, -2); // .fn[key] + if (lua_iscfunction(L, -1)) + return 1; + else + { + lua_pop(L, 2); // .fn[key], .fn + return 0; + } +} + +int +_edje_lua_look_get(lua_State *L) +{ + lua_rawgeti(L, -1, EDJE_LUA_GET); + lua_pushvalue(L, 2); // key + lua_rawget(L, -2); // .get[key] + if (lua_iscfunction(L, -1)) + { + lua_pushvalue(L, 1); + int err_code; + + if (err_code = lua_pcall(L, 1, 1, 0)) + _edje_lua_error(L, err_code); + return 1; + } + else + { + lua_pop(L, 2); // .get[key], .get + return 0; + } +} + +int +_edje_lua_look_set(lua_State *L) +{ + lua_rawgeti(L, -1, EDJE_LUA_SET); + lua_pushvalue(L, 2); // key + lua_rawget(L, -2); // .set[key] + if (lua_iscfunction(L, -1)) + { + lua_pushvalue(L, 1); // obj + lua_pushvalue(L, 3); // value + int err_code; + + if (err_code = lua_pcall(L, 2, 0, 0)) // .set[key](obj,key,value) + _edje_lua_error(L, err_code); + return 1; + } + else + { + lua_pop(L, 2); // .set[key], .set + return 0; + } +} + +/* + * Lua Class bindings + */ + +const luaL_Reg lNil[] = { + {NULL, NULL} // sentinel +}; + +const luaL_Reg lClass_mt[]; + +const luaL_Reg lClass_fn[]; + +const Edje_Lua_Reg mClass = { + lClass_mt, + lNil, + lNil, + lClass_fn +}; + +static int +_edje_lua_class_mt_index(lua_State *L) +{ + _edje_lua_checkudata(L, 1, &mClass); + lua_getmetatable(L, 1); + if (!_edje_lua_look_fn(L)) // look in lClass_fn + if (!_edje_lua_look_get(L)) // look in lClass_get + { // look in obj ref hash + lua_getfenv(L, 1); + lua_pushvalue(L, 2); // key + lua_rawget(L, -2); + } + return 1; +} + +static int +_edje_lua_class_mt_newindex(lua_State *L) +{ + _edje_lua_checkudata(L, 1, &mClass); + lua_getmetatable(L, 1); + if (!_edje_lua_look_set(L)) // look in lClass_set + { // look in obj ref hash + lua_getfenv(L, 1); + lua_pushvalue(L, 2); + lua_pushvalue(L, 3); + lua_rawset(L, -3); + } + return 0; +} + +static int +_edje_lua_class_mt_gc(lua_State *L) +{ + _edje_lua_checkudata(L, 1, &mClass); + //printf("_edje_lua_class_mt_gc\n"); + /* FIXME has to be commented to not raise an error, solve differently + lua_getfield(L, 1, "del"); + if (!lua_isnil(L, -1)) + { + lua_pushvalue(L, 1); + int err_code; + + if (err_code = lua_pcall(L, 1, 0, 0)) + _edje_lua_error(L, err_code); + } + lua_pop(L, 1); + */ + return 0; +} + +static int +_edje_lua_class_fn_set(lua_State *L) +{ + _edje_lua_checkudata(L, 1, &mClass); + /* + * for k,v in pairs(table) do + * obj[k] = v + * end + */ + lua_pushnil(L); + while (lua_next(L, 2)) + { + // key at -2, value at -1 + lua_pushvalue(L, -2); + lua_insert(L, -2); + lua_settable(L, 1); + } + return 0; +} + +static int +_edje_lua_class_fn_get(lua_State *L) +{ + _edje_lua_checkudata(L, 1, &mClass); + /* + * res = {} + * mtG = getmetatable(obj)['.get'] + * for k,v in pairs(mtG) do + * res[k] = obj[k] + * end + */ + lua_newtable(L); // res + lua_getmetatable(L, 1); // mt + lua_getfield(L, -1, ".get"); + lua_remove(L, -2); // mt + + lua_pushnil(L); + while (lua_next(L, -2)) + { + // key at -2, value at -1 + lua_pop(L, 1); // value = cfunction + lua_pushvalue(L, -1); // key + lua_pushvalue(L, -1); // key + lua_gettable(L, 1); // obj[key] + lua_settable(L, 2); // res[key] + } + lua_pop(L, 1); // .get + return 1; +} + +static int +_edje_lua_class_itr_call(lua_State *L, int id) +{ + _edje_lua_checkudata(L, 1, &mClass); + lua_getmetatable(L, 1); // mt + lua_rawgeti(L, -1, id); + lua_remove(L, -2); // mt + lua_getglobal(L, "pairs"); + lua_insert(L, -2); + int err_code; + if (err_code = lua_pcall(L, 1, 3, 0)) + _edje_lua_error(L, err_code); + return 3; +} + +static int +_edje_lua_class_fn_gpairs(lua_State *L) +{ + _edje_lua_checkudata(L, 1, &mClass); + return _edje_lua_class_itr_call(L, EDJE_LUA_GET); +} + +static int +_edje_lua_class_fn_spairs(lua_State *L) +{ + _edje_lua_checkudata(L, 1, &mClass); + return _edje_lua_class_itr_call(L, EDJE_LUA_SET); +} + +static int +_edje_lua_class_fn_fpairs(lua_State *L) +{ + _edje_lua_checkudata(L, 1, &mClass); + return _edje_lua_class_itr_call(L, EDJE_LUA_FN); +} + +static int +_edje_lua_class_fn_pairs(lua_State *L) +{ + _edje_lua_checkudata(L, 1, &mClass); + lua_getfenv(L, 1); + lua_getglobal(L, "pairs"); + lua_insert(L, -2); + int err_code; + if (err_code = lua_pcall(L, 1, 3, 0)) + _edje_lua_error(L, err_code); + return 3; +} + +static int +_edje_lua_class_fn_ipairs(lua_State *L) +{ + _edje_lua_checkudata(L, 1, &mClass); + lua_getfenv(L, 1); + lua_getglobal(L, "ipairs"); + lua_insert(L, -2); + int err_code; + if (err_code = lua_pcall(L, 1, 3, 0)) + _edje_lua_error(L, err_code); + return 3; +} + +const luaL_Reg lClass_mt[] = { + {"__index", _edje_lua_class_mt_index}, + {"__newindex", _edje_lua_class_mt_newindex}, + {"__gc", _edje_lua_class_mt_gc}, + {NULL, NULL} // sentinel +}; + +const luaL_Reg lClass_fn[] = { + {"get", _edje_lua_class_fn_get}, + {"set", _edje_lua_class_fn_set}, + {"gpairs", _edje_lua_class_fn_gpairs}, + {"spairs", _edje_lua_class_fn_spairs}, + {"fpairs", _edje_lua_class_fn_fpairs}, + {"pairs", _edje_lua_class_fn_pairs}, + {"ipairs", _edje_lua_class_fn_ipairs}, + {NULL, NULL} // sentinel +}; + +/* + * Lua Edje Timer bindings + */ + +const luaL_Reg lTimer_get[]; + +const luaL_Reg lTimer_set[]; + +const luaL_Reg lTimer_fn[]; + +const Edje_Lua_Reg mTimer = { + lNil, + lTimer_get, + lTimer_set, + lTimer_fn +}; + +const Edje_Lua_Reg *cTimer[] = { + &mClass, + &mTimer, + NULL // sentinel +}; + +static int +_edje_lua_timer_cb(void *data) +{ + Edje_Lua_Timer *obj = data; + lua_State *L = obj->L; + _edje_lua_get_ref(L, obj->cb); // callback function + _edje_lua_get_reg(L, obj); + int err_code; + if (err_code = lua_pcall(L, 1, 1, 0)) + _edje_lua_error(L, err_code); + int res = luaL_checkint(L, -1); + lua_pop(L, 1); // -- res + if (res == ECORE_CALLBACK_CANCEL) + { + // delete object + _edje_lua_get_reg(L, obj); + lua_pushvalue(L, -1); + lua_pushstring(L, "del"); + lua_gettable(L, -2); + lua_insert(L, -2); + if (err_code = lua_pcall(L, 1, 0, 0)) + _edje_lua_error(L, err_code); + } + return res; +} + +static int +_edje_lua_timer_get_pending(lua_State *L) +{ + Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer); + if (obj->et) + lua_pushnumber(L, ecore_timer_pending_get(obj->et)); + else + lua_pushnil(L); + return 1; +} + +static int +_edje_lua_timer_get_precision(lua_State *L) +{ + Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer); + + if (obj->et) + lua_pushnumber(L, ecore_timer_precision_get()); + else + lua_pushnil(L); + + return 1; +} + +static int +_edje_lua_timer_get_interval(lua_State *L) +{ + Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer); + + if (obj->et) + lua_pushnumber(L, ecore_timer_interval_get(obj->et)); + else + lua_pushnil(L); + + return 1; +} + +const luaL_Reg lTimer_get[] = { + {"pending", _edje_lua_timer_get_pending}, + {"precision", _edje_lua_timer_get_precision}, + {"interval", _edje_lua_timer_get_interval}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_timer_set_interval(lua_State *L) +{ + Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer); + if (obj->et) + ecore_timer_interval_set(obj->et, luaL_checknumber(L, 2)); + return 0; +} + +const luaL_Reg lTimer_set[] = { + {"interval", _edje_lua_timer_set_interval}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_timer_fn_del(lua_State *L) +{ + Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer); + if (obj->et) + { + ecore_timer_del(obj->et); + obj->et = NULL; + } + if (obj->cb) + { + _edje_lua_free_ref(L, obj->cb); // created in _edje_lua_group_fn_timer + obj->cb = NULL; + } + _edje_lua_free_reg(L, obj); // created in _edje_lua_group_fn_timer + return 0; +} + +static int +_edje_lua_timer_fn_freeze(lua_State *L) +{ + Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer); + if (obj->et) + ecore_timer_freeze(obj->et); + return 0; +} + +static int +_edje_lua_timer_fn_thaw(lua_State *L) +{ + Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer); + if (obj->et) + ecore_timer_thaw(obj->et); + return 0; +} + +static int +_edje_lua_timer_fn_delay(lua_State *L) +{ + Edje_Lua_Timer *obj = _edje_lua_checkudata(L, 1, &mTimer); + if (obj->et) + ecore_timer_delay(obj->et, luaL_checknumber(L, 2)); + return 0; +} + +const luaL_Reg lTimer_fn[] = { + {"del", _edje_lua_timer_fn_del}, + {"freeze", _edje_lua_timer_fn_freeze}, + {"thaw", _edje_lua_timer_fn_thaw}, + {"delay", _edje_lua_timer_fn_delay}, + {NULL, NULL} // sentinel +}; + +/* + * Lua Edje Animator bindings + */ + +const luaL_Reg lAnimator_get[]; + +const luaL_Reg lAnimator_fn[]; + +const Edje_Lua_Reg mAnimator = { + lNil, + lAnimator_get, + lNil, + lAnimator_fn +}; + +const Edje_Lua_Reg *cAnimator[] = { + &mClass, + &mAnimator, + NULL // sentinel +}; + +static int +_edje_lua_animator_cb(void *data) +{ + int err, res; + Edje_Lua_Animator *obj = data; + lua_State *L = obj->L; + + _edje_lua_get_ref(L, obj->cb); + _edje_lua_get_reg(L, obj); + + if (err = lua_pcall(L, 1, 1, 0)) + _edje_lua_error(L, err); + + res = luaL_checkint(L, -1); + lua_pop(L, 1); // Pop res off the stack + if (res == ECORE_CALLBACK_CANCEL) + { + /* delete animator */ + _edje_lua_get_reg(L, obj); + lua_pushvalue(L, -1); + lua_pushstring(L, "del"); + lua_gettable(L, -2); + lua_insert(L, -2); + if (err = lua_pcall(L, 1, 0, 0)) + _edje_lua_error(L, err); + } + + return res; +} + +static int +_edje_lua_animator_get_frametime(lua_State *L) +{ + Edje_Lua_Animator *obj = _edje_lua_checkudata(L, 1, &mAnimator); + + if (obj->ea) + lua_pushnumber(L, ecore_animator_frametime_get()); + else + lua_pushnil(L); + + return 1; +} + +const luaL_Reg lAnimator_get[] = { + {"frametime", _edje_lua_animator_get_frametime}, + {NULL, NULL} +}; + +static int +_edje_lua_animator_fn_del(lua_State *L) +{ + Edje_Lua_Animator *obj = _edje_lua_checkudata(L, 1, &mAnimator); + if (obj->ea) + { + ecore_animator_del(obj->ea); + obj->ea = NULL; + } + if (obj->cb) + { + _edje_lua_free_ref(L, obj->cb); // created in _edje_lua_group_fn_animator + obj->cb = NULL; + } + _edje_lua_free_reg(L, obj); // created in _edje_lua_group_fn_animator + return 0; +} + +const luaL_Reg lAnimator_fn[] = { + {"del", _edje_lua_animator_fn_del}, + {NULL, NULL} // sentinel +}; + +/* + * Lua Edje Poller Bindings + */ + +const luaL_Reg lPoller_get[]; + +const luaL_Reg lPoller_fn[]; + +const Edje_Lua_Reg mPoller = { + lNil, + lPoller_get, + lNil, + lPoller_fn +}; + +const Edje_Lua_Reg *cPoller[] = { + &mClass, + &mPoller, + NULL // sentinel +}; + +static int +_edje_lua_poller_cb(void *data) +{ + int err, res; + Edje_Lua_Poller *obj = data; + lua_State *L = obj->L; + + _edje_lua_get_ref(L, obj->cb); + _edje_lua_get_reg(L, obj); + + if (err = lua_pcall(L, 1, 1, 0)) + _edje_lua_error(L, err); + + res = luaL_checkint(L, -1); + lua_pop(L, 1); // Pop res off the stack + if (res == ECORE_CALLBACK_CANCEL) + { + /* delete poller */ + _edje_lua_get_reg(L, obj); + lua_pushvalue(L, -1); + lua_pushstring(L, "del"); + lua_gettable(L, -2); + lua_insert(L, -2); + if (err = lua_pcall(L, 1, 0, 0)) + _edje_lua_error(L, err); + } + + return res; +} + +static int +_edje_lua_poller_get_interval(lua_State *L) +{ + Edje_Lua_Poller *obj = _edje_lua_checkudata(L, 1, &mPoller); + + if (obj->ep) + lua_pushnumber(L, ecore_poller_poll_interval_get(ECORE_POLLER_CORE)); + else + lua_pushnil(L); + + return 1; +} + +const luaL_Reg lPoller_get[] = { + {"interval", _edje_lua_poller_get_interval}, + {NULL, NULL} +}; + +static int +_edje_lua_poller_fn_del(lua_State *L) +{ + Edje_Lua_Poller *obj = _edje_lua_checkudata(L, 1, &mPoller); + if (obj->ep) + { + ecore_poller_del(obj->ep); + obj->ep = NULL; + } + + if (obj->cb) + { + _edje_lua_free_ref(L, obj->cb); // created in _edje_lua_group_fn_poller + obj->cb = NULL; + } + _edje_lua_free_reg(L, obj); // created in _edje_lua_group_fn_poller + + return 0; +} + +const luaL_Reg lPoller_fn[] = { + {"del", _edje_lua_poller_fn_del}, + {NULL, NULL} +}; + +/* + * Lua Edje Transform bindings + */ + +const luaL_Reg lTransform_get[]; + +const luaL_Reg lTransform_set[]; + +const luaL_Reg lTransform_fn[]; + +const Edje_Lua_Reg mTransform = { + lNil, + lTransform_get, + lTransform_set, + lTransform_fn +}; + +const Edje_Lua_Reg *cTransform[] = { + &mClass, + &mTransform, + NULL // sentinel +}; + +static int +_edje_lua_transform_get_matrix(lua_State *L) +{ + Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform); + lua_createtable(L, 3, 0); + lua_createtable(L, 3, 0); + lua_pushnumber(L, obj->et.mxx); lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->et.mxy); lua_rawseti(L, -2, 2); + lua_pushnumber(L, obj->et.mxz); lua_rawseti(L, -2, 3); + lua_rawseti(L, -2, 1); + lua_createtable(L, 3, 0); + lua_pushnumber(L, obj->et.myx); lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->et.myy); lua_rawseti(L, -2, 2); + lua_pushnumber(L, obj->et.myz); lua_rawseti(L, -2, 3); + lua_rawseti(L, -2, 2); + lua_createtable(L, 3, 0); + lua_pushnumber(L, obj->et.mzx); lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->et.mzy); lua_rawseti(L, -2, 2); + lua_pushnumber(L, obj->et.mzz); lua_rawseti(L, -2, 3); + lua_rawseti(L, -2, 3); + return 1; +} + +const luaL_Reg lTransform_get[] = { + {"matrix", _edje_lua_transform_get_matrix}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_transform_set_matrix(lua_State *L) +{ + Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + luaL_checktype(L, -1, LUA_TTABLE); + lua_rawgeti(L, -1, 1); obj->et.mxx = luaL_checknumber(L, -1); lua_pop(L, 1); + lua_rawgeti(L, -1, 2); obj->et.mxy = luaL_checknumber(L, -1); lua_pop(L, 1); + lua_rawgeti(L, -1, 3); obj->et.mxz = luaL_checknumber(L, -1); lua_pop(L, 1); + lua_pop(L, 1); + lua_rawgeti(L, 2, 2); + luaL_checktype(L, -1, LUA_TTABLE); + lua_rawgeti(L, -1, 1); obj->et.myx = luaL_checknumber(L, -1); lua_pop(L, 1); + lua_rawgeti(L, -1, 2); obj->et.myy = luaL_checknumber(L, -1); lua_pop(L, 1); + lua_rawgeti(L, -1, 3); obj->et.myz = luaL_checknumber(L, -1); lua_pop(L, 1); + lua_pop(L, 1); + lua_rawgeti(L, 2, 3); + luaL_checktype(L, -1, LUA_TTABLE); + lua_rawgeti(L, -1, 1); obj->et.mzx = luaL_checknumber(L, -1); lua_pop(L, 1); + lua_rawgeti(L, -1, 2); obj->et.mzy = luaL_checknumber(L, -1); lua_pop(L, 1); + lua_rawgeti(L, -1, 3); obj->et.mzz = luaL_checknumber(L, -1); lua_pop(L, 1); + lua_pop(L, 1); + return 0; +} + +const luaL_Reg lTransform_set[] = { + {"matrix", _edje_lua_transform_set_matrix}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_transform_fn_identity(lua_State *L) +{ + Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform); + evas_transform_identity_set(&(obj->et)); + return 0; +} + +static int +_edje_lua_transform_fn_rotate(lua_State *L) +{ + Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform); + evas_transform_rotate(luaL_checknumber(L, 2), &(obj->et)); + return 0; +} + +static int +_edje_lua_transform_fn_translate(lua_State *L) +{ + Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform); + evas_transform_translate(luaL_checknumber(L, 2), luaL_checknumber(L, 3), &(obj->et)); + return 0; +} + +static int +_edje_lua_transform_fn_scale(lua_State *L) +{ + Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform); + evas_transform_scale(luaL_checknumber(L, 2), luaL_checknumber(L, 3), &(obj->et)); + return 0; +} + +static int +_edje_lua_transform_fn_shear(lua_State *L) +{ + Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform); + evas_transform_shear(luaL_checknumber(L, 2), luaL_checknumber(L, 3), &(obj->et)); + return 0; +} + +static int +_edje_lua_transform_fn_compose(lua_State *L) +{ + Edje_Lua_Transform *obj = _edje_lua_checkudata(L, 1, &mTransform); + Edje_Lua_Transform *tar = _edje_lua_checkudata(L, 2, &mTransform); + evas_transform_compose(&(tar->et), &(obj->et)); + return 0; +} + +const luaL_Reg lTransform_fn[] = { + {"identity", _edje_lua_transform_fn_identity}, + {"rotate", _edje_lua_transform_fn_rotate}, + {"translate", _edje_lua_transform_fn_translate}, + {"scale", _edje_lua_transform_fn_scale}, + {"shear", _edje_lua_transform_fn_shear}, + {"compose", _edje_lua_transform_fn_compose}, + {NULL, NULL} // sentinel +}; + +/* + * Lua Edje Transition bindings + */ + +const luaL_Reg lTransition_get[]; + +const luaL_Reg lTransition_set[]; + +const luaL_Reg lTransition_fn[]; + +const Edje_Lua_Reg mTransition = { + lNil, + lTransition_get, + lTransition_set, + lTransition_fn +}; + +const Edje_Lua_Reg *cTransition[] = { + &mClass, + &mTransition, + NULL // sentinel +}; + +const luaL_Reg lTransition_get[] = { + {NULL, NULL} // sentinel +}; + +const luaL_Reg lTransition_set[] = { + {NULL, NULL} // sentinel +}; + +const luaL_Reg lTransition_fn[] = { + {NULL, NULL} // sentinel +}; + +/* + * Lua Evas Object bindings + */ + +const luaL_Reg lObject_get[]; + +const luaL_Reg lObject_set[]; + +const luaL_Reg lObject_fn[]; + +const Edje_Lua_Reg mObject = { + lNil, + lObject_get, + lObject_set, + lObject_fn +}; + +static void +_edje_lua_object_del_cb(void *data, Evas * e, Evas_Object * obj, + void *event_info) +{ + //printf("_edje_lua_object_delete_cb\n"); + lua_State *L = data; + _edje_lua_get_reg(L, obj); + Edje_Lua_Evas_Object *udata = _edje_lua_checkudata(L, -1, &mObject); + lua_pop(L, 1); + _edje_lua_free_reg(L, udata); // created in EDJE_LUA_SCRIPT_FN_ADD + _edje_lua_free_reg(L, obj); // created in EDJE_LUA_SCRIPT_FN_ADD + + Edje_Lua_Ref *ref; + EINA_LIST_FREE(udata->cb, ref) + _edje_lua_free_ref(L, ref); +} + +static int +_edje_lua_object_fn_del(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + if (obj->eo) + { + evas_object_del(obj->eo); + obj->eo = NULL; + obj->ed = NULL; + } + return 0; +} + +static int +_edje_lua_object_fn_show(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_show(obj->eo); + return 0; +} + +static int +_edje_lua_object_fn_hide(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_hide(obj->eo); + return 0; +} + +static int +_edje_lua_object_fn_move(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + //printf ("%i %i %i %i\n", obj->ed->x, obj->ed->y, luaL_checkint (L, 2), luaL_checkint (L, 3)); + evas_object_move(obj->eo, + obj->ed->x + luaL_checkint(L, 2), + obj->ed->y + luaL_checkint(L, 3)); + return 0; +} + +static int +_edje_lua_object_fn_resize(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_resize(obj->eo, luaL_checkint(L, 2), luaL_checkint(L, 3)); + return 0; +} + +static int +_edje_lua_object_fn_raise(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_raise(obj->eo); + return 0; +} + +static int +_edje_lua_object_fn_lower(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_lower(obj->eo); + return 0; +} + +static int +_edje_lua_object_fn_stack_above(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject); + evas_object_stack_above(obj->eo, tar->eo); + return 0; +} + +static int +_edje_lua_object_fn_stack_below(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject); + evas_object_stack_below(obj->eo, tar->eo); + return 0; +} + +static int +_edje_lua_object_fn_clip_unset(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_clip_unset(obj->eo); + return 0; +} + +const luaL_Reg lObject_fn[] = { + {"del", _edje_lua_object_fn_del}, + {"show", _edje_lua_object_fn_show}, + {"hide", _edje_lua_object_fn_hide}, + {"move", _edje_lua_object_fn_move}, + {"resize", _edje_lua_object_fn_resize}, + {"raise", _edje_lua_object_fn_raise}, + {"lower", _edje_lua_object_fn_lower}, + {"stack_above", _edje_lua_object_fn_stack_above}, + {"stack_below", _edje_lua_object_fn_stack_below}, + {"clip_unset", _edje_lua_object_fn_clip_unset}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_object_get_name(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushstring(L, evas_object_name_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_geometry(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + int x, y, w, h; + evas_object_geometry_get(obj->eo, &x, &y, &w, &h); + lua_createtable(L, 4, 0); + lua_pushnumber(L, x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, y); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, w); + lua_rawseti(L, -2, 3); + lua_pushnumber(L, h); + lua_rawseti(L, -2, 4); + return 1; +} + +static int +_edje_lua_object_get_type(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushstring(L, evas_object_type_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_layer(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushnumber(L, evas_object_layer_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_above(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + Evas_Object *above = evas_object_above_get(obj->eo); + _edje_lua_get_reg(L, above); + // TODO create object if it does not already exist? + return 1; +} + +static int +_edje_lua_object_get_below(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + Evas_Object *below = evas_object_below_get(obj->eo); + _edje_lua_get_reg(L, below); + // TODO create object if it does not already exist? + return 1; +} + +static int +_edje_lua_object_get_size_hint_min(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + int w, h; + evas_object_size_hint_min_get(obj->eo, &w, &h); + lua_createtable(L, 2, 0); + lua_pushnumber(L, w); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, h); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_object_get_size_hint_max(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + int w, h; + evas_object_size_hint_max_get(obj->eo, &w, &h); + lua_createtable(L, 2, 0); + lua_pushnumber(L, w); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, h); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_object_get_size_hint_request(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + int w, h; + evas_object_size_hint_request_get(obj->eo, &w, &h); + lua_createtable(L, 2, 0); + lua_pushnumber(L, w); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, h); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_object_get_size_hint_aspect(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + Evas_Aspect_Control a; + int w, h; + evas_object_size_hint_aspect_get(obj->eo, &a, &w, &h); + lua_createtable(L, 3, 0); + lua_pushnumber(L, a); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, w); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, h); + lua_rawseti(L, -2, 3); + return 1; +} + +static int +_edje_lua_object_get_size_hint_align(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + double w, h; + evas_object_size_hint_align_get(obj->eo, &w, &h); + lua_createtable(L, 2, 0); + lua_pushnumber(L, w); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, h); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_object_get_size_hint_weight(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + double w, h; + evas_object_size_hint_weight_get(obj->eo, &w, &h); + lua_createtable(L, 2, 0); + lua_pushnumber(L, w); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, h); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_object_get_size_hint_padding(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + int l, r, t, b; + evas_object_size_hint_padding_get(obj->eo, &l, &r, &t, &b); + lua_createtable(L, 4, 0); + lua_pushnumber(L, l); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, r); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, t); + lua_rawseti(L, -2, 3); + lua_pushnumber(L, b); + lua_rawseti(L, -2, 4); + return 1; +} + +static int +_edje_lua_object_get_visible(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushboolean(L, evas_object_visible_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_render_op(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushnumber(L, evas_object_render_op_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_anti_alias(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushboolean(L, evas_object_anti_alias_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_scale(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushnumber(L, evas_object_scale_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_color(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + int r, g, b, a; + evas_object_color_get(obj->eo, &r, &g, &b, &a); + lua_createtable(L, 4, 0); + lua_pushnumber(L, r); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, g); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, b); + lua_rawseti(L, -2, 3); + lua_pushnumber(L, a); + lua_rawseti(L, -2, 4); + return 1; +} + +static int +_edje_lua_object_get_color_interpolation(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushnumber(L, evas_object_color_interpolation_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_clip(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + Evas_Object *clip = evas_object_clip_get(obj->eo); + _edje_lua_get_reg(L, clip); + // TODO create object if it does not already exist? + return 1; +} + +static int +_edje_lua_object_get_clipees(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + Eina_List *clipees = (Eina_List *) evas_object_clipees_get(obj->eo); + Eina_List *l; + Evas_Object *clip; + int i = 1; + lua_createtable(L, eina_list_count(clipees), 0); + EINA_LIST_FOREACH(clipees, l, clip) + { + _edje_lua_get_reg(L, clip); + // TODO create object if it does not already exist? + lua_rawseti(L, -2, i++); + } + return 1; +} + +static int +_edje_lua_object_get_evas(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + Evas *evas = evas_object_evas_get(obj->eo); + lua_pushnil(L); + // FIXME implement Evas class in the first place? + return 1; +} + +static int +_edje_lua_object_get_pass_events(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushboolean(L, evas_object_pass_events_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_repeat_events(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushboolean(L, evas_object_repeat_events_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_propagate_events(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushboolean(L, evas_object_propagate_events_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_focus(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushboolean(L, evas_object_focus_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_pointer_mode(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushnumber(L, evas_object_pointer_mode_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_precise_is_inside(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushboolean(L, evas_object_precise_is_inside_get(obj->eo)); + return 1; +} + +static int +_edje_lua_object_get_mouse_events(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + lua_pushboolean(L, obj->mouse_events); + return 1; +} + +const luaL_Reg lObject_get[] = { + {"name", _edje_lua_object_get_name}, + {"geometry", _edje_lua_object_get_geometry}, + {"type", _edje_lua_object_get_type}, + {"layer", _edje_lua_object_get_layer}, + {"above", _edje_lua_object_get_above}, + {"below", _edje_lua_object_get_below}, + {"size_hint_min", _edje_lua_object_get_size_hint_min}, + {"size_hint_max", _edje_lua_object_get_size_hint_max}, + {"size_hint_request", _edje_lua_object_get_size_hint_request}, + {"size_hint_aspect", _edje_lua_object_get_size_hint_aspect}, + {"size_hint_align", _edje_lua_object_get_size_hint_align}, + {"size_hint_weight", _edje_lua_object_get_size_hint_weight}, + {"size_hint_padding", _edje_lua_object_get_size_hint_padding}, + {"visible", _edje_lua_object_get_visible}, + {"render_op", _edje_lua_object_get_render_op}, + {"anti_alias", _edje_lua_object_get_anti_alias}, + {"scale", _edje_lua_object_get_scale}, + {"color", _edje_lua_object_get_color}, + {"color_interpolation", _edje_lua_object_get_color_interpolation}, + {"clip", _edje_lua_object_get_clip}, + {"clipees", _edje_lua_object_get_clipees}, + {"evas", _edje_lua_object_get_evas}, + {"pass_events", _edje_lua_object_get_pass_events}, + {"repeat_events", _edje_lua_object_get_repeat_events}, + {"propagate_events", _edje_lua_object_get_propagate_events}, + {"focus", _edje_lua_object_get_focus}, + {"pointer_mode", _edje_lua_object_get_pointer_mode}, + {"precise_is_inside", _edje_lua_object_get_precise_is_inside}, + {"mouse_events", _edje_lua_object_get_mouse_events}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_object_set_name(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_name_set(obj->eo, luaL_checkstring(L, 2)); + return 0; +} + +static int +_edje_lua_object_set_layer(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_layer_set(obj->eo, luaL_checkint(L, 2)); + return 0; +} + +static int +_edje_lua_object_set_size_hint_min(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + evas_object_size_hint_min_set(obj->eo, + luaL_checkint(L, -2), + luaL_checkint(L, -1)); + return 0; +} + +static int +_edje_lua_object_set_size_hint_max(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + evas_object_size_hint_max_set(obj->eo, + luaL_checkint(L, -2), + luaL_checkint(L, -1)); + return 0; +} + +static int +_edje_lua_object_set_size_hint_request(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + evas_object_size_hint_request_set(obj->eo, + luaL_checkint(L, -2), + luaL_checkint(L, -1)); + return 0; +} + +static int +_edje_lua_object_set_size_hint_aspect(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + lua_rawgeti(L, 2, 3); + evas_object_size_hint_aspect_set(obj->eo, + luaL_checkint(L, -3), + luaL_checkint(L, -2), + luaL_checkint(L, -1)); + return 0; +} + +static int +_edje_lua_object_set_size_hint_align(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + evas_object_size_hint_align_set(obj->eo, + luaL_checknumber(L, -2), + luaL_checknumber(L, -1)); + return 0; +} + +static int +_edje_lua_object_set_size_hint_weight(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + evas_object_size_hint_weight_set(obj->eo, + luaL_checknumber(L, -2), + luaL_checknumber(L, -1)); + return 0; +} + +static int +_edje_lua_object_set_size_hint_padding(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + lua_rawgeti(L, 2, 3); + lua_rawgeti(L, 2, 4); + evas_object_size_hint_padding_set(obj->eo, + luaL_checknumber(L, -4), + luaL_checknumber(L, -3), + luaL_checknumber(L, -2), + luaL_checknumber(L, -1)); + return 0; +} + +static int +_edje_lua_object_set_render_op(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_render_op_set(obj->eo, luaL_checkint(L, 2)); + return 0; +} + +static int +_edje_lua_object_set_anti_alias(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_anti_alias_set(obj->eo, lua_toboolean(L, 2)); + return 0; +} + +static int +_edje_lua_object_set_scale(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_scale_set(obj->eo, luaL_checknumber(L, 2)); + return 0; +} + +static int +_edje_lua_object_set_color(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + lua_rawgeti(L, 2, 3); + lua_rawgeti(L, 2, 4); + evas_object_color_set(obj->eo, + luaL_checkint(L, -4), + luaL_checkint(L, -3), + luaL_checkint(L, -2), + luaL_checkint(L, -1)); + return 0; +} + +static int +_edje_lua_object_set_color_interpolation(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_color_interpolation_set(obj->eo, luaL_checkint(L, 2)); + return 0; +} + +static int +_edje_lua_object_set_clip(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + Edje_Lua_Evas_Object *clip = _edje_lua_checkudata(L, 2, &mObject); + evas_object_clip_set(obj->eo, clip->eo); + return 0; +} + +static int +_edje_lua_object_set_pass_events(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_pass_events_set(obj->eo, lua_toboolean(L, 2)); + return 0; +} + +static int +_edje_lua_object_set_repeat_events(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_repeat_events_set(obj->eo, lua_toboolean(L, 2)); + return 0; +} + +static int +_edje_lua_object_set_propagate_events(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_propagate_events_set(obj->eo, lua_toboolean(L, 2)); + return 0; +} + +static int +_edje_lua_object_set_focus(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_focus_set(obj->eo, lua_toboolean(L, 2)); + return 0; +} + +static int +_edje_lua_object_set_pointer_mode(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_pointer_mode_set(obj->eo, luaL_checkint(L, 2)); + return 0; +} + +static int +_edje_lua_object_set_precise_is_inside(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_precise_is_inside_set(obj->eo, lua_toboolean(L, 2)); + return 0; +} + +#define OBJECT_CB_MACRO(KEY) \ + lua_State *L = data; \ + _edje_lua_get_reg(L, obj); \ + lua_getfield(L, -1, KEY); \ + if (lua_type(L, -1) != LUA_TFUNCTION) \ + { \ + lua_pop(L, 2); \ + return; \ + } \ + lua_insert(L, -2); + +static void +_edje_lua_object_cb_mouse_in(void *data, Evas * e, Evas_Object * obj, + void *event_info) +{ + OBJECT_CB_MACRO("mouse_in"); + Evas_Event_Mouse_In * ev = event_info; + lua_pushnumber(L, ev->output.x); + lua_pushnumber(L, ev->output.y); + lua_pushnumber(L, ev->canvas.x); + lua_pushnumber(L, ev->canvas.y); + int err_code; + if (err_code = lua_pcall(L, 5, 0, 0)) + _edje_lua_error(L, err_code); +} + +static void +_edje_lua_object_cb_mouse_out(void *data, Evas * e, Evas_Object * obj, + void *event_info) +{ + OBJECT_CB_MACRO("mouse_out"); + Evas_Event_Mouse_In * ev = event_info; + lua_pushnumber(L, ev->output.x); + lua_pushnumber(L, ev->output.y); + lua_pushnumber(L, ev->canvas.x); + lua_pushnumber(L, ev->canvas.y); + int err_code; + if (err_code = lua_pcall(L, 5, 0, 0)) + _edje_lua_error(L, err_code); +} + +static void +_edje_lua_object_cb_mouse_down(void *data, Evas * e, Evas_Object * obj, + void *event_info) +{ + OBJECT_CB_MACRO("mouse_down"); + Evas_Event_Mouse_Down * ev = event_info; + lua_pushnumber(L, ev->button); + lua_pushnumber(L, ev->output.x); + lua_pushnumber(L, ev->output.y); + lua_pushnumber(L, ev->canvas.x); + lua_pushnumber(L, ev->canvas.y); + int err_code; + if (err_code = lua_pcall(L, 6, 0, 0)) + _edje_lua_error(L, err_code); +} + +static void +_edje_lua_object_cb_mouse_up(void *data, Evas * e, Evas_Object * obj, + void *event_info) +{ + OBJECT_CB_MACRO("mouse_up"); + Evas_Event_Mouse_Up * ev = event_info; + lua_pushnumber(L, ev->button); + lua_pushnumber(L, ev->output.x); + lua_pushnumber(L, ev->output.y); + lua_pushnumber(L, ev->canvas.x); + lua_pushnumber(L, ev->canvas.y); + int err_code; + if (err_code = lua_pcall(L, 6, 0, 0)) + _edje_lua_error(L, err_code); +} + +static void +_edje_lua_object_cb_mouse_move(void *data, Evas * e, Evas_Object * obj, + void *event_info) +{ + OBJECT_CB_MACRO("mouse_move"); + Evas_Event_Mouse_Move * ev = event_info; + lua_pushnumber(L, ev->buttons); + lua_pushnumber(L, ev->cur.output.x); + lua_pushnumber(L, ev->cur.output.y); + lua_pushnumber(L, ev->cur.canvas.x); + lua_pushnumber(L, ev->cur.canvas.y); + int err_code; + if (err_code = lua_pcall(L, 6, 0, 0)) + _edje_lua_error(L, err_code); +} + +static void +_edje_lua_object_cb_mouse_wheel(void *data, Evas * e, Evas_Object * obj, + void *event_info) +{ + OBJECT_CB_MACRO("mouse_wheel"); + Evas_Event_Mouse_Wheel * ev = event_info; + lua_pushnumber(L, ev->z); + lua_pushnumber(L, ev->output.x); + lua_pushnumber(L, ev->output.y); + lua_pushnumber(L, ev->canvas.x); + lua_pushnumber(L, ev->canvas.y); + int err_code; + if (err_code = lua_pcall(L, 6, 0, 0)) + _edje_lua_error(L, err_code); +} + +static int +_edje_lua_object_set_mouse_events(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + obj->mouse_events = lua_toboolean(L, 2); + if (obj->mouse_events) + { + // add all mouse events + evas_object_event_callback_add(obj->eo, EVAS_CALLBACK_MOUSE_IN, _edje_lua_object_cb_mouse_in, L); + evas_object_event_callback_add(obj->eo, EVAS_CALLBACK_MOUSE_OUT, _edje_lua_object_cb_mouse_out, L); + evas_object_event_callback_add(obj->eo, EVAS_CALLBACK_MOUSE_DOWN, _edje_lua_object_cb_mouse_down, L); + evas_object_event_callback_add(obj->eo, EVAS_CALLBACK_MOUSE_UP, _edje_lua_object_cb_mouse_up, L); + evas_object_event_callback_add(obj->eo, EVAS_CALLBACK_MOUSE_MOVE, _edje_lua_object_cb_mouse_move, L); + evas_object_event_callback_add(obj->eo, EVAS_CALLBACK_MOUSE_WHEEL, _edje_lua_object_cb_mouse_wheel, L); + } + else + { + // delete all mouse events + evas_object_event_callback_del(obj->eo, EVAS_CALLBACK_MOUSE_IN, _edje_lua_object_cb_mouse_in); + evas_object_event_callback_del(obj->eo, EVAS_CALLBACK_MOUSE_OUT, _edje_lua_object_cb_mouse_out); + evas_object_event_callback_del(obj->eo, EVAS_CALLBACK_MOUSE_DOWN, _edje_lua_object_cb_mouse_down); + evas_object_event_callback_del(obj->eo, EVAS_CALLBACK_MOUSE_UP, _edje_lua_object_cb_mouse_up); + evas_object_event_callback_del(obj->eo, EVAS_CALLBACK_MOUSE_MOVE, _edje_lua_object_cb_mouse_move); + evas_object_event_callback_del(obj->eo, EVAS_CALLBACK_MOUSE_WHEEL, _edje_lua_object_cb_mouse_wheel); + } + return 0; +} + +const luaL_Reg lObject_set[] = { + {"name", _edje_lua_object_set_name}, + {"layer", _edje_lua_object_set_layer}, + {"size_hint_min", _edje_lua_object_set_size_hint_min}, + {"size_hint_max", _edje_lua_object_set_size_hint_max}, + {"size_hint_request", _edje_lua_object_set_size_hint_request}, + {"size_hint_aspect", _edje_lua_object_set_size_hint_aspect}, + {"size_hint_align", _edje_lua_object_set_size_hint_align}, + {"size_hint_weight", _edje_lua_object_set_size_hint_weight}, + {"size_hint_padding", _edje_lua_object_set_size_hint_padding}, + {"render_op", _edje_lua_object_set_render_op}, + {"anti_alias", _edje_lua_object_set_anti_alias}, + {"scale", _edje_lua_object_set_scale}, + {"color", _edje_lua_object_set_color}, + {"color_interpolation", _edje_lua_object_set_color_interpolation}, + {"clip", _edje_lua_object_set_clip}, + {"pass_events", _edje_lua_object_set_pass_events}, + {"repeat_events", _edje_lua_object_set_repeat_events}, + {"propagate_events", _edje_lua_object_set_propagate_events}, + {"focus", _edje_lua_object_set_focus}, + {"pointer_mode", _edje_lua_object_get_pointer_mode}, + {"precise_is_inside", _edje_lua_object_get_precise_is_inside}, + {"mouse_events", _edje_lua_object_set_mouse_events}, + {NULL, NULL} // sentinel +}; + +const Edje_Lua_Reg *cRectangle[] = { + &mClass, + &mObject, + NULL // sentinel +}; + +/* + * Image + */ + +const luaL_Reg lImage_get[]; + +const luaL_Reg lImage_set[]; + +const Edje_Lua_Reg mImage = { + lNil, + lImage_get, + lImage_set, + lNil +}; + +const Edje_Lua_Reg *cImage[] = { + &mClass, + &mObject, + &mImage, + NULL // sentinel +}; + +static int +_edje_lua_image_get_size(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mImage); + int w, h; + evas_object_image_size_get(obj->eo, &w, &h); + lua_createtable(L, 2, 0); + lua_pushnumber(L, w); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, h); + lua_rawseti(L, -2, 2); + return 1; +}; + +const luaL_Reg lImage_get[] = { + {"size", _edje_lua_image_get_size}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_image_set_file(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mImage); + int id = edje_edit_image_id_get(obj->ed->obj, luaL_checkstring(L, 2)); + char buf[256]; + sprintf(buf, "images/%i", id); + evas_object_image_file_set(obj->eo, obj->ed->path, buf); + return 0; +} + +static int +_edje_lua_image_set_fill(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mImage); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + lua_rawgeti(L, 2, 3); + lua_rawgeti(L, 2, 4); + evas_object_image_fill_set(obj->eo, + luaL_checkint(L, -4), + luaL_checkint(L, -3), + luaL_checkint(L, -2), luaL_checkint(L, -1)); + return 0; +} + +static int +_edje_lua_image_set_fill_transform(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mImage); + Edje_Lua_Transform *tar = _edje_lua_checkudata(L, 2, &mTransform); + evas_object_image_fill_transform_set(obj->eo, &(tar->et)); + return 0; +} + +static int +_edje_lua_image_set_alpha(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mObject); + evas_object_image_alpha_set(obj->eo, lua_toboolean(L, 2)); + return 0; +} + +const luaL_Reg lImage_set[] = { + {"file", _edje_lua_image_set_file}, + {"fill", _edje_lua_image_set_fill}, + {"fill_transform", _edje_lua_image_set_fill_transform}, + {"alpha", _edje_lua_image_set_alpha}, + {NULL, NULL} // sentinel +}; + +/* + * Line + */ + +const luaL_Reg lLine_get[]; +const luaL_Reg lLine_set[]; + +const Edje_Lua_Reg mLine = { + lNil, + lLine_get, + lLine_set, + lNil +}; + +const Edje_Lua_Reg *cLine[] = { + &mClass, + &mObject, + &mLine, + NULL // sentinel +}; + +static int +_edje_lua_line_get_xy(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mLine); + int x1, y1, x2, y2; + evas_object_line_xy_get(obj->eo, &x1, &y1, &x2, &y2); + lua_createtable(L, 4, 0); + lua_pushnumber(L, x1); lua_rawseti(L, -2, 1); + lua_pushnumber(L, y1); lua_rawseti(L, -2, 2); + lua_pushnumber(L, x2); lua_rawseti(L, -2, 3); + lua_pushnumber(L, y2); lua_rawseti(L, -2, 4); + return 1; +} + +const luaL_Reg lLine_get[] = { + {"xy", _edje_lua_line_get_xy}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_line_set_xy(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mLine); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + lua_rawgeti(L, 2, 3); + lua_rawgeti(L, 2, 4); + evas_object_line_xy_set(obj->eo, + luaL_checkint(L, -4), + luaL_checkint(L, -3), + luaL_checkint(L, -2), + luaL_checkint(L, -1)); + return 0; +} + +const luaL_Reg lLine_set[] = { + {"xy", _edje_lua_line_set_xy}, + {NULL, NULL} // sentinel +}; + +/* + * Polygon + */ + +const luaL_Reg lPolygon_fn[]; + +const Edje_Lua_Reg mPolygon = { + lNil, + lNil, + lNil, + lPolygon_fn +}; + +const Edje_Lua_Reg *cPolygon[] = { + &mClass, + &mObject, + &mPolygon, + NULL // sentinel +}; + +static int +_edje_lua_polygon_fn_point_add(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mPolygon); + evas_object_polygon_point_add(obj->eo, + luaL_checknumber(L, 2), + luaL_checknumber(L, 3)); + return 0; +} + +static int +_edje_lua_polygon_fn_points_clear(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mPolygon); + evas_object_polygon_points_clear(obj->eo); + return 0; +} + +const luaL_Reg lPolygon_fn[] = { + {"point_add", _edje_lua_polygon_fn_point_add}, + {"points_clear", _edje_lua_polygon_fn_points_clear}, + {NULL, NULL} // sentinel +}; + +/* + * Table + */ + +const luaL_Reg lTable_get[]; + +const luaL_Reg lTable_set[]; + +const luaL_Reg lTable_fn[]; + +const Edje_Lua_Reg mTable = { + lNil, + lTable_get, + lTable_set, + lTable_fn +}; + +const Edje_Lua_Reg *cTable[] = { + &mClass, + &mObject, + &mTable, + NULL // sentinel +}; + +static int +_edje_lua_table_get_homogeneous(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable); + lua_pushnumber(L, evas_object_table_homogeneous_get(obj->eo)); + return 1; +} + +static int +_edje_lua_table_get_padding(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable); + int x, y; + evas_object_table_padding_get(obj->eo, &x, &y); + lua_createtable(L, 2, 0); + lua_pushnumber(L, x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_table_get_align(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable); + double x, y; + evas_object_table_align_get(obj->eo, &x, &y); + lua_createtable(L, 2, 0); + lua_pushnumber(L, x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_table_get_col_row_size(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable); + int x, y; + evas_object_table_col_row_size_get(obj->eo, &x, &y); + lua_createtable(L, 2, 0); + lua_pushnumber(L, x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_table_get_children(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable); + Eina_List *children = (Eina_List *) evas_object_table_children_get(obj->eo); + Eina_List *l; + Evas_Object *child; + int i = 1; + lua_createtable(L, eina_list_count(children), 0); + EINA_LIST_FOREACH(children, l, child) + { + _edje_lua_get_reg(L, child); + // TODO create object if it does not already exist? + lua_rawseti(L, -2, i++); + } + return 1; +} + +const luaL_Reg lTable_get[] = { + {"homogeneous", _edje_lua_table_get_homogeneous}, + {"padding", _edje_lua_table_get_padding}, + {"align", _edje_lua_table_get_align}, + {"col_row_size", _edje_lua_table_get_col_row_size}, + {"children", _edje_lua_table_get_children}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_table_set_homogeneous(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable); + evas_object_table_homogeneous_set(obj->eo, + luaL_checkint(L, 2)); + return 0; +} + +static int +_edje_lua_table_set_padding(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + evas_object_table_padding_set(obj->eo, + luaL_checkint(L, -2), + luaL_checkint(L, -1)); + return 0; +} + +static int +_edje_lua_table_set_align(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + evas_object_table_align_set(obj->eo, + luaL_checknumber(L, -2), + luaL_checknumber(L, -1)); + return 0; +} + +const luaL_Reg lTable_set[] = { + {"homogeneous", _edje_lua_table_set_homogeneous}, + {"padding", _edje_lua_table_set_padding}, + {"align", _edje_lua_table_set_align}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_table_fn_pack(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable); + Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject); + lua_pushboolean(L, + evas_object_table_pack(obj->eo, tar->eo, + luaL_checkint(L, 3), + luaL_checkint(L, 4), + luaL_checkint(L, 5), + luaL_checkint(L, 6))); + return 1; +} + +static int +_edje_lua_table_fn_unpack(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable); + Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject); + lua_pushboolean(L, + evas_object_table_unpack(obj->eo, tar->eo)); + return 1; +} + +static int +_edje_lua_table_fn_clear(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mTable); + evas_object_table_clear(obj->eo, lua_toboolean(L, 2)); + return 0; +} + +const luaL_Reg lTable_fn[] = { + {"pack", _edje_lua_table_fn_pack}, + {"unpack", _edje_lua_table_fn_unpack}, + {"clear", _edje_lua_table_fn_clear}, + {NULL, NULL} // sentinel +}; + +/* + * Description + */ + +const luaL_Reg lDescription_get[]; + +const luaL_Reg lDescription_set[]; + +const Edje_Lua_Reg mDescription = { + lNil, + lDescription_get, + lDescription_set, + lNil +}; + +const Edje_Lua_Reg *cDescription[] = { + &mClass, + &mObject, + &mDescription, + NULL // sentinel +}; + +static int +_edje_lua_description_get_alignment(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->align.x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->align.y); + lua_rawseti(L, -2, 1); + return 1; +} + +static int +_edje_lua_description_get_min(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->min.w); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->min.h); + lua_rawseti(L, -2, 1); + return 1; +} + +static int +_edje_lua_description_get_max(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->max.w); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->max.h); + lua_rawseti(L, -2, 1); + return 1; +} + +static int +_edje_lua_description_get_step(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->step.x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->step.y); + lua_rawseti(L, -2, 1); + return 1; +} + +static int +_edje_lua_description_get_aspect(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->aspect.min); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->aspect.max); + lua_rawseti(L, -2, 1); + return 1; +} + +static int +_edje_lua_description_get_aspect_pref(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_pushnumber(L, obj->rp->custom->description->aspect.prefer); + return 1; +} + +static int +_edje_lua_description_get_color(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + /* check whether this part has a "custom" state */ + if (!obj->rp->custom) return 0; + lua_createtable(L, 4, 0); + lua_pushnumber(L, obj->rp->custom->description->color.r); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->color.g); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, obj->rp->custom->description->color.b); + lua_rawseti(L, -2, 3); + lua_pushnumber(L, obj->rp->custom->description->color.a); + lua_rawseti(L, -2, 4); + return 1; +} + +static int +_edje_lua_description_get_color2(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_createtable(L, 4, 0); + lua_pushnumber(L, obj->rp->custom->description->color2.r); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->color2.g); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, obj->rp->custom->description->color2.b); + lua_rawseti(L, -2, 3); + lua_pushnumber(L, obj->rp->custom->description->color2.a); + lua_rawseti(L, -2, 4); + return 1; +} + +static int +_edje_lua_description_get_color3(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_createtable(L, 4, 0); + lua_pushnumber(L, obj->rp->custom->description->color3.r); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->color3.g); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, obj->rp->custom->description->color3.b); + lua_rawseti(L, -2, 3); + lua_pushnumber(L, obj->rp->custom->description->color3.a); + lua_rawseti(L, -2, 4); + return 1; +} + +static int +_edje_lua_description_get_color_class(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_pushstring(L, obj->rp->custom->description->color_class); + return 1; +} + +static int +_edje_lua_description_get_rel1(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->rel1.relative_x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->rel1.relative_y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_description_get_rel1_to(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->rel1.id_x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->rel1.id_y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_description_get_rel1_offset(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->rel1.offset_x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->rel1.offset_y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_description_get_rel2(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->rel2.relative_x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->rel2.relative_y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_description_get_rel2_to(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->rel2.id_x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->rel2.id_y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_description_get_rel2_offset(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->rel2.offset_x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->rel2.offset_y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_description_get_image(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE)) + return 0; + // TODO +} + +static int +_edje_lua_description_get_border(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE)) + return 0; + if (!obj->rp->custom) return 0; + lua_createtable(L, 4, 0); + lua_pushnumber(L, obj->rp->custom->description->border.l); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->border.r); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, obj->rp->custom->description->border.t); + lua_rawseti(L, -2, 3); + lua_pushnumber(L, obj->rp->custom->description->border.b); + lua_rawseti(L, -2, 4); + return 1; +} + +static int +_edje_lua_description_get_fill_smooth(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE)) + return 0; + if (!obj->rp->custom) return 0; + lua_pushboolean(L, obj->rp->custom->description->fill.smooth); + return 1; +} + +static int +_edje_lua_description_get_fill_pos(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE)) + return 0; + if (!obj->rp->custom) return 0; + lua_createtable(L, 4, 0); + lua_pushnumber(L, obj->rp->custom->description->fill.pos_rel_x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->fill.pos_rel_y); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, obj->rp->custom->description->fill.pos_abs_x); + lua_rawseti(L, -2, 3); + lua_pushnumber(L, obj->rp->custom->description->fill.pos_abs_y); + lua_rawseti(L, -2, 4); + return 1; +} + +static int +_edje_lua_description_get_fill_size(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE)) + return 0; + if (!obj->rp->custom) return 0; + lua_createtable(L, 4, 0); + lua_pushnumber(L, obj->rp->custom->description->fill.rel_x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->fill.rel_y); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, obj->rp->custom->description->fill.abs_x); + lua_rawseti(L, -2, 3); + lua_pushnumber(L, obj->rp->custom->description->fill.abs_y); + lua_rawseti(L, -2, 4); + return 1; +} + +static int +_edje_lua_description_get_text(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT) + && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) + return 0; + if (!obj->rp->custom) return 0; + lua_pushstring(L, obj->rp->custom->description->text.text); + return 1; +} + +static int +_edje_lua_description_get_text_class(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT) + && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) + return 0; + if (!obj->rp->custom) return 0; + lua_pushstring(L, obj->rp->custom->description->text.text_class); + return 1; +} + +static int +_edje_lua_description_get_text_font(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)) + return 0; + if (!obj->rp->custom) return 0; + lua_pushstring(L, obj->rp->custom->description->text.text_class); + return 1; +} + +static int +_edje_lua_description_get_text_style(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) + return 0; + if (!obj->rp->custom) return 0; + lua_pushstring(L, obj->rp->custom->description->text.style); + return 1; +} + +static int +_edje_lua_description_get_text_size(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)) + return 0; + if (!obj->rp->custom) return 0; + lua_pushnumber(L, obj->rp->custom->description->text.size); + return 1; +} + +static int +_edje_lua_description_get_text_fit(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)) + return 0; + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushboolean(L, obj->rp->custom->description->text.fit_x); + lua_rawseti(L, -2, 1); + lua_pushboolean(L, obj->rp->custom->description->text.fit_y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_description_get_text_min(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT) + && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) + return 0; + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->text.min_x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->text.min_y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_description_get_text_max(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT) + && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) + return 0; + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->text.max_x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->text.max_y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_description_get_text_align(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)) + return 0; + if (!obj->rp->custom) return 0; + lua_createtable(L, 2, 0); + lua_pushnumber(L, obj->rp->custom->description->text.align.x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, obj->rp->custom->description->text.align.y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_description_get_visible(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_pushboolean(L, obj->rp->custom->description->visible); + return 1; +} + +const luaL_Reg lDescription_get[] = { + {"alignment", _edje_lua_description_get_alignment}, + {"min", _edje_lua_description_get_min}, + {"max", _edje_lua_description_get_max}, + {"step", _edje_lua_description_get_step}, + {"aspect", _edje_lua_description_get_aspect}, + {"aspect_pref", _edje_lua_description_get_aspect_pref}, + {"color", _edje_lua_description_get_color}, + {"color2", _edje_lua_description_get_color2}, + {"color3", _edje_lua_description_get_color3}, + {"color_class", _edje_lua_description_get_color_class}, + {"rel1", _edje_lua_description_get_rel1}, + {"rel1_to", _edje_lua_description_get_rel1_to}, + {"rel1_offset", _edje_lua_description_get_rel1_offset}, + {"rel2", _edje_lua_description_get_rel2}, + {"rel2_to", _edje_lua_description_get_rel2_to}, + {"rel2_offset", _edje_lua_description_get_rel2_offset}, + {"image", _edje_lua_description_get_image}, + {"border", _edje_lua_description_get_border}, + {"fill_smooth", _edje_lua_description_get_fill_smooth}, + {"fill_pos", _edje_lua_description_get_fill_pos}, + {"fill_size", _edje_lua_description_get_fill_size}, + {"text", _edje_lua_description_get_text}, + {"text_class", _edje_lua_description_get_text_class}, + {"text_font", _edje_lua_description_get_text_font}, + {"text_style", _edje_lua_description_get_text_style}, + {"text_size", _edje_lua_description_get_text_size}, + {"text_fit", _edje_lua_description_get_text_fit}, + {"text_min", _edje_lua_description_get_text_min}, + {"text_max", _edje_lua_description_get_text_max}, + {"text_align", _edje_lua_description_get_text_align}, + {"visible", _edje_lua_description_get_visible}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_description_set_alignment(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->align.x = luaL_checknumber(L, -2); + obj->rp->custom->description->align.y = luaL_checknumber(L, -1); + return 0; +} + +static int +_edje_lua_description_set_min(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->min.w = luaL_checkint(L, -2); + obj->rp->custom->description->min.h = luaL_checkint(L, -1); + return 0; +} + +static int +_edje_lua_description_set_max(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->max.w = luaL_checkint(L, -2); + obj->rp->custom->description->max.h = luaL_checkint(L, -1); + return 0; +} + +static int +_edje_lua_description_set_step(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->step.x = luaL_checkint(L, -2); + obj->rp->custom->description->step.y = luaL_checkint(L, -1); + return 0; +} + +static int +_edje_lua_description_set_aspect(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->aspect.min = luaL_checknumber(L, -2); + obj->rp->custom->description->aspect.max = luaL_checknumber(L, -1); + return 0; + +} + +static int +_edje_lua_description_set_aspect_pref(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + obj->rp->custom->description->aspect.prefer = luaL_checknumber(L, 2); + return 0; + +} + +static int +_edje_lua_description_set_color(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + lua_rawgeti(L, 2, 3); + lua_rawgeti(L, 2, 4); + obj->rp->custom->description->color.r = luaL_checkint(L, -4); + obj->rp->custom->description->color.g = luaL_checkint(L, -3); + obj->rp->custom->description->color.b = luaL_checkint(L, -2); + obj->rp->custom->description->color.a = luaL_checkint(L, -1); + return 0; +} + +static int +_edje_lua_description_set_color2(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + lua_rawgeti(L, 2, 3); + lua_rawgeti(L, 2, 4); + obj->rp->custom->description->color2.r = luaL_checkint(L, -4); + obj->rp->custom->description->color2.g = luaL_checkint(L, -3); + obj->rp->custom->description->color2.b = luaL_checkint(L, -2); + obj->rp->custom->description->color2.a = luaL_checkint(L, -1); + return 0; +} + +static int +_edje_lua_description_set_color3(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + lua_rawgeti(L, 2, 3); + lua_rawgeti(L, 2, 4); + obj->rp->custom->description->color3.r = luaL_checkint(L, -4); + obj->rp->custom->description->color3.g = luaL_checkint(L, -3); + obj->rp->custom->description->color3.b = luaL_checkint(L, -2); + obj->rp->custom->description->color3.a = luaL_checkint(L, -1); + return 0; +} + +static int +_edje_lua_description_set_color_class(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + obj->rp->custom->description->color_class = (char *)luaL_checkstring(L, 2); + return 0; +} + +static int +_edje_lua_description_set_rel1(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->rel1.relative_x = luaL_checknumber(L, -2); + obj->rp->custom->description->rel1.relative_y = luaL_checknumber(L, -1); + return 0; +} + +static int +_edje_lua_description_set_rel1_to(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->rel1.id_x = luaL_checknumber(L, -2); + obj->rp->custom->description->rel1.id_y = luaL_checknumber(L, -1); + if (obj->rp->param1.description->rel1.id_x >= 0) + obj->rp->param1.rel1_to_x = obj->ed->table_parts[obj->rp->param1.description->rel1.id_x % obj->ed->table_parts_size]; + if (obj->rp->param1.description->rel1.id_y >= 0) + obj->rp->param1.rel1_to_y = obj->ed->table_parts[obj->rp->param1.description->rel1.id_y % obj->ed->table_parts_size]; + return 0; +} + +static int +_edje_lua_description_set_rel1_offset(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->rel1.offset_x = luaL_checkint(L, -2); + obj->rp->custom->description->rel1.offset_y = luaL_checkint(L, -1); + return 0; +} + +static int +_edje_lua_description_set_rel2(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->rel2.relative_x = luaL_checknumber(L, -2); + obj->rp->custom->description->rel2.relative_y = luaL_checknumber(L, -1); + return 0; +} + +static int +_edje_lua_description_set_rel2_to(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->rel2.id_x = luaL_checknumber(L, -2); + obj->rp->custom->description->rel2.id_y = luaL_checknumber(L, -1); + if (obj->rp->param1.description->rel2.id_x >= 0) + obj->rp->param1.rel2_to_x = obj->ed->table_parts[obj->rp->param1.description->rel2.id_x % obj->ed->table_parts_size]; + if (obj->rp->param1.description->rel2.id_y >= 0) + obj->rp->param1.rel2_to_y = obj->ed->table_parts[obj->rp->param1.description->rel2.id_y % obj->ed->table_parts_size]; + return 0; +} + +static int +_edje_lua_description_set_rel2_offset(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->rel2.offset_x = luaL_checkint(L, -2); + obj->rp->custom->description->rel2.offset_y = luaL_checkint(L, -1); + return 0; +} + +static int +_edje_lua_description_set_image(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE)) + return 0; + obj->rp->custom->description->image.id = + edje_edit_image_id_get(obj->ed->obj, (char *)luaL_checkstring(L, 2)); + return 0; +} + +static int +_edje_lua_description_set_border(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE)) + return 0; + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + lua_rawgeti(L, 2, 3); + lua_rawgeti(L, 2, 4); + obj->rp->custom->description->border.l = luaL_checkint(L, -2); + obj->rp->custom->description->border.r = luaL_checkint(L, -1); + obj->rp->custom->description->border.t = luaL_checkint(L, -2); + obj->rp->custom->description->border.b = luaL_checkint(L, -1); + return 0; +} + +static int +_edje_lua_description_set_fill_smooth(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE)) + return 0; + if (!obj->rp->custom) return 0; + obj->rp->custom->description->fill.smooth = lua_toboolean(L, 2); + return 0; +} + +static int +_edje_lua_description_set_fill_pos(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE)) + return 0; + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + lua_rawgeti(L, 2, 3); + lua_rawgeti(L, 2, 4); + obj->rp->custom->description->fill.pos_rel_x = luaL_checkint(L, -2); + obj->rp->custom->description->fill.pos_rel_y = luaL_checkint(L, -1); + obj->rp->custom->description->fill.pos_abs_x = luaL_checkint(L, -2); + obj->rp->custom->description->fill.pos_abs_y = luaL_checkint(L, -1); + return 0; +} + +static int +_edje_lua_description_set_fill_size(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_IMAGE)) + return 0; + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + lua_rawgeti(L, 2, 3); + lua_rawgeti(L, 2, 4); + obj->rp->custom->description->fill.rel_x = luaL_checkint(L, -2); + obj->rp->custom->description->fill.rel_y = luaL_checkint(L, -1); + obj->rp->custom->description->fill.abs_x = luaL_checkint(L, -2); + obj->rp->custom->description->fill.abs_y = luaL_checkint(L, -1); + return 0; +} + +static int +_edje_lua_description_set_text(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT) + && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) + return 0; + if (!obj->rp->custom) return 0; + obj->rp->custom->description->text.text = (char *)luaL_checkstring(L, 2); + return 0; +} + +static int +_edje_lua_description_set_text_class(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT) + && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) + return 0; + if (!obj->rp->custom) return 0; + obj->rp->custom->description->text.text_class = + (char *)luaL_checkstring(L, 2); + return 0; +} + +static int +_edje_lua_description_set_text_font(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)) + return 0; + if (!obj->rp->custom) return 0; + obj->rp->custom->description->text.font = (char *)luaL_checkstring(L, 2); + return 0; +} + +static int +_edje_lua_description_set_text_style(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) + return 0; + if (!obj->rp->custom) return 0; + obj->rp->custom->description->text.style = (char *)luaL_checkstring(L, 2); + return 0; +} + +static int +_edje_lua_description_set_text_size(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)) + return 0; + if (!obj->rp->custom) return 0; + obj->rp->custom->description->text.size = luaL_checkint(L, 2); + return 0; +} + +static int +_edje_lua_description_set_text_fit(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->text.fit_x = lua_toboolean(L, -2); + obj->rp->custom->description->text.fit_y = lua_toboolean(L, -1); + return 0; +} + +static int +_edje_lua_description_set_text_min(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT) + && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) + return 0; + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->text.min_x = luaL_checkint(L, -2); + obj->rp->custom->description->text.min_y = luaL_checkint(L, -1); + return 0; +} + +static int +_edje_lua_description_set_text_max(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT) + && (obj->rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) + return 0; + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->text.max_x = luaL_checkint(L, -2); + obj->rp->custom->description->text.max_y = luaL_checkint(L, -1); + return 0; +} + +static int +_edje_lua_description_set_text_align(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if ((obj->rp->part->type != EDJE_PART_TYPE_TEXT)) + return 0; + if (!obj->rp->custom) return 0; + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->rp->custom->description->text.align.x = luaL_checknumber(L, -2); + obj->rp->custom->description->text.align.y = luaL_checknumber(L, -1); + return 0; +} + +static int +_edje_lua_description_set_visible(lua_State *L) +{ + Edje_Lua_Edje_Part_Description *obj = + _edje_lua_checkudata(L, 1, &mDescription); + if (!obj->rp->custom) return 0; + obj->rp->custom->description->visible = lua_toboolean(L, 2); + return 0; +} + +const luaL_Reg lDescription_set[] = { + {"alignment", _edje_lua_description_set_alignment}, + {"min", _edje_lua_description_set_min}, + {"max", _edje_lua_description_set_max}, + {"step", _edje_lua_description_set_step}, + {"aspect", _edje_lua_description_set_aspect}, + {"aspect_pref", _edje_lua_description_set_aspect_pref}, + {"color", _edje_lua_description_set_color}, + {"color2", _edje_lua_description_set_color2}, + {"color3", _edje_lua_description_set_color3}, + {"color_class", _edje_lua_description_set_color_class}, + {"rel1", _edje_lua_description_set_rel1}, + {"rel1_to", _edje_lua_description_set_rel1_to}, + {"rel1_offset", _edje_lua_description_set_rel1_offset}, + {"rel2", _edje_lua_description_set_rel2}, + {"rel2_to", _edje_lua_description_set_rel2_to}, + {"rel2_offset", _edje_lua_description_set_rel2_offset}, + {"image", _edje_lua_description_set_image}, + {"border", _edje_lua_description_set_border}, + {"fill_smooth", _edje_lua_description_set_fill_smooth}, + {"fill_pos", _edje_lua_description_set_fill_pos}, + {"fill_size", _edje_lua_description_set_fill_size}, + {"text", _edje_lua_description_set_text}, + {"text_class", _edje_lua_description_set_text_class}, + {"text_font", _edje_lua_description_set_text_font}, + {"text_style", _edje_lua_description_set_text_style}, + {"text_size", _edje_lua_description_set_text_size}, + {"text_fit", _edje_lua_description_set_text_fit}, + {"text_min", _edje_lua_description_set_text_min}, + {"text_max", _edje_lua_description_set_text_max}, + {"text_align", _edje_lua_description_set_text_align}, + {"visible", _edje_lua_description_set_visible}, + {NULL, NULL} // sentinel +}; + +/* + * Part + */ + +const luaL_Reg lPart_get[]; + +const luaL_Reg lPart_set[]; + +const luaL_Reg lPart_fn[]; + +const Edje_Lua_Reg mPart = { + lNil, + lPart_get, + lPart_set, + lPart_fn +}; + +static void +_edje_lua_edje_part_del_cb(void *data, Evas * e, Evas_Object * obj, + void *event_info) +{ + //printf("_edje_lua_object_delete_cb\n"); + lua_State *L = data; + _edje_lua_get_reg(L, obj); + Edje_Lua_Edje_Part_Object *udata = _edje_lua_checkudata(L, -1, &mPart); + lua_pop(L, 1); + _edje_lua_free_reg(L, udata); // created in _edje_lua_group_mt_index + _edje_lua_free_reg(L, obj); // created in _edje_lua_group_mt_index +} + +const Edje_Lua_Reg *cPart[] = { + &mClass, + &mObject, + &mPart, + NULL // sentinel +}; + +static int +_edje_lua_part_get_swallow(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + Evas_Object *swa = edje_object_part_swallow_get(obj->ed->obj, obj->key); + _edje_lua_get_reg(L, swa); + // TODO create object if it does not already exist? + return 1; +} + +static int +_edje_lua_part_get_type(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + lua_pushnumber(L, edje_edit_part_type_get(obj->ed->obj, obj->key)); + return 1; +} + +static int +_edje_lua_part_get_effect(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + lua_pushnumber(L, edje_edit_part_effect_get(obj->ed->obj, obj->key)); + return 1; +} + +static int +_edje_lua_part_get_mouse_events(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + lua_pushboolean(L, edje_edit_part_mouse_events_get(obj->ed->obj, obj->key)); + return 1; +} + +static int +_edje_lua_part_get_repeat_events(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + lua_pushboolean(L, edje_edit_part_repeat_events_get(obj->ed->obj, obj->key)); + return 1; +} + +static int +_edje_lua_part_get_states_list(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + Eina_List *slist = edje_edit_part_states_list_get(obj->ed->obj, obj->key); + Eina_List *ilist; + lua_newtable(L); + int i = 1; + for (ilist = slist; ilist; ilist = eina_list_next(ilist)) + { + lua_pushstring(L, eina_list_data_get(ilist)); + lua_rawseti(L, -2, i++); + } + edje_edit_string_list_free(slist); + return 1; +}; + +static int +_edje_lua_part_get_state(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + const char *state; + double val; + state = edje_object_part_state_get(obj->ed->obj, obj->key, &val); + lua_createtable(L, 2, 0); + lua_pushstring(L, state); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, val); + lua_rawseti(L, -2, 2); + return 1; +}; + +static int +_edje_lua_part_get_text(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + lua_pushstring(L, edje_object_part_text_get(obj->ed->obj, obj->key)); + return 1; +}; + +static int +_edje_lua_part_get_text_selection(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + lua_pushstring(L, + edje_object_part_text_selection_get(obj->ed->obj, obj->key)); + return 1; +}; + +static int +_edje_lua_part_get_drag_dir(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + lua_pushnumber(L, edje_object_part_drag_dir_get(obj->ed->obj, obj->key)); + return 1; +} + +static int +_edje_lua_part_get_drag_value(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + double dx, dy; + edje_object_part_drag_value_get(obj->ed->obj, obj->key, &dx, &dy); + lua_createtable(L, 2, 0); + lua_pushnumber(L, dx); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, dy); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_part_get_drag_size(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + double dx, dy; + edje_object_part_drag_size_get(obj->ed->obj, obj->key, &dx, &dy); + lua_createtable(L, 2, 0); + lua_pushnumber(L, dx); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, dy); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_part_get_drag_step(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + double dx, dy; + edje_object_part_drag_step_get(obj->ed->obj, obj->key, &dx, &dy); + lua_createtable(L, 2, 0); + lua_pushnumber(L, dx); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, dy); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_part_get_drag_page(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + double dx, dy; + edje_object_part_drag_page_get(obj->ed->obj, obj->key, &dx, &dy); + lua_createtable(L, 2, 0); + lua_pushnumber(L, dx); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, dy); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_part_get_text_cursor_geometry(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + Evas_Coord x, y, w, h; + edje_object_part_text_cursor_geometry_get(obj->ed->obj, obj->key, + &x, &y, &w, &h); + lua_createtable(L, 4, 0); + lua_pushnumber(L, x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, y); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, w); + lua_rawseti(L, -2, 3); + lua_pushnumber(L, h); + lua_rawseti(L, -2, 4); + return 1; +} + +static int +_edje_lua_part_get_geometry(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + Evas_Coord x, y, w, h; + edje_object_part_geometry_get(obj->ed->obj, obj->key, &x, &y, &w, &h); + lua_createtable(L, 4, 0); + lua_pushnumber(L, x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, y); + lua_rawseti(L, -2, 2); + lua_pushnumber(L, w); + lua_rawseti(L, -2, 3); + lua_pushnumber(L, h); + lua_rawseti(L, -2, 4); + return 1; +} + +static int +_edje_lua_part_get_table_col_row_size(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + int cols, rows; + edje_object_part_table_col_row_size_get(obj->ed->obj, obj->key, &cols, &rows); + lua_createtable(L, 2, 0); + lua_pushnumber(L, cols); lua_rawseti(L, -2, 1); + lua_pushnumber(L, rows); lua_rawseti(L, -2, 2); + return 1; +} + +static int _edje_lua_part_fn_custom_state(lua_State *L); + +const luaL_Reg lPart_get[] = { + {"custom_state", _edje_lua_part_fn_custom_state}, + {"Swallow", _edje_lua_part_get_swallow}, + + {"drag_dir", _edje_lua_part_get_drag_dir}, + {"drag_value", _edje_lua_part_get_drag_value}, + {"drag_size", _edje_lua_part_get_drag_size}, + {"drag_step", _edje_lua_part_get_drag_step}, + {"drag_page", _edje_lua_part_get_drag_page}, + + {"type", _edje_lua_part_get_type}, + {"effect", _edje_lua_part_get_effect}, + {"mouse_events", _edje_lua_part_get_mouse_events}, + {"repeat_events", _edje_lua_part_get_repeat_events}, + {"states_list", _edje_lua_part_get_states_list}, + {"state", _edje_lua_part_get_state}, + + {"text", _edje_lua_part_get_text}, + {"text_selection", _edje_lua_part_get_text_selection}, + {"text_cursor_geometry", _edje_lua_part_get_text_cursor_geometry}, + + {"geometry", _edje_lua_part_get_geometry}, + {"part_col_row_size", _edje_lua_part_get_table_col_row_size}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_part_set_effect(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + edje_edit_part_effect_set(obj->ed->obj, obj->key, luaL_checkint(L, 2)); + return 0; +} + +static int +_edje_lua_part_set_mouse_events(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + edje_edit_part_mouse_events_set(obj->ed->obj, obj->key, lua_toboolean(L, 2)); + return 0; +} + +static int +_edje_lua_part_set_repeat_events(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + edje_edit_part_repeat_events_set(obj->ed->obj, obj->key, + lua_toboolean(L, 2)); + return 0; +} + +static int +_edje_lua_part_set_state(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + _edje_part_description_apply(obj->ed, obj->rp, + luaL_checkstring(L, -2), luaL_checknumber(L, -1), + NULL, 0.0); + _edje_part_pos_set(obj->ed, obj->rp, EDJE_TWEEN_MODE_LINEAR, 0.0); + _edje_recalc(obj->ed); + return 0; +} + +static int +_edje_lua_part_set_tween_state(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + lua_rawgeti(L, 2, 3); + lua_rawgeti(L, 2, 4); + lua_rawgeti(L, 2, 5); + _edje_part_description_apply(obj->ed, obj->rp, + luaL_checkstring(L, -4), luaL_checknumber(L, -3), + luaL_checkstring(L, -2), luaL_checknumber(L, -1)); + _edje_part_pos_set(obj->ed, obj->rp, EDJE_TWEEN_MODE_LINEAR, + luaL_checknumber(L, -5)); + _edje_recalc(obj->ed); + return 0; +} + +static int +_edje_lua_part_set_text(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + edje_object_part_text_set(obj->ed->obj, obj->key, luaL_checkstring(L, 2)); + return 0; +} + +static int +_edje_lua_part_set_drag_value(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + edje_object_part_drag_value_set(obj->ed->obj, obj->key, + luaL_checknumber(L, -2), + luaL_checknumber(L, -1)); + return 0; +} + +static int +_edje_lua_part_set_drag_size(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + edje_object_part_drag_size_set(obj->ed->obj, obj->key, + luaL_checknumber(L, -2), + luaL_checknumber(L, -1)); + return 0; +} + +static int +_edje_lua_part_set_drag_step(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + edje_object_part_drag_step_set(obj->ed->obj, obj->key, + luaL_checknumber(L, -2), + luaL_checknumber(L, -1)); + return 0; +} + +static int +_edje_lua_part_set_drag_page(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + edje_object_part_drag_page_set(obj->ed->obj, obj->key, + luaL_checknumber(L, -2), + luaL_checknumber(L, -1)); + return 0; +} + +const luaL_Reg lPart_set[] = { + {"drag_value", _edje_lua_part_set_drag_value}, + {"drag_size", _edje_lua_part_set_drag_size}, + {"drag_step", _edje_lua_part_set_drag_step}, + {"drag_page", _edje_lua_part_set_drag_page}, + + {"effect", _edje_lua_part_set_effect}, + {"mouse_events", _edje_lua_part_set_mouse_events}, + {"repeat_events", _edje_lua_part_set_repeat_events}, + {"state", _edje_lua_part_set_state}, + {"tween_state", _edje_lua_part_set_tween_state}, + {"text", _edje_lua_part_set_text}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_part_fn_swallow(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + Edje_Lua_Evas_Object *swa = _edje_lua_checkudata(L, 2, &mObject); + edje_object_part_swallow(obj->ed->obj, obj->key, swa->eo); + return 0; +} + +static int +_edje_lua_part_fn_unswallow(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + edje_object_part_unswallow(obj->ed->obj, obj->eo); + return 0; +} + +static int +_edje_lua_part_fn_text_select_none(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + edje_object_part_text_select_none(obj->ed->obj, obj->key); + return 0; +} + +static int +_edje_lua_part_fn_text_select_all(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + edje_object_part_text_select_all(obj->ed->obj, obj->key); + return 0; +} + +static int +_edje_lua_part_fn_text_insert(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + edje_object_part_text_insert(obj->ed->obj, obj->key, luaL_checkstring(L, 2)); + return 0; +} + +static int +_edje_lua_part_fn_custom_state(lua_State *L) +{ + char *name; + float val; + Edje_Part_Description *parent; + Edje_Part_Image_Id *iid; + Eina_List *l; + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + /* check whether this part already has a "custom" state */ + if (obj->rp->custom) + { + _edje_lua_get_reg(L, obj->rp->custom->description); + return 1; + } + + name = (char *)luaL_checkstring(L, 2); // state name + val = luaL_checknumber(L, 3); // state val + if (!(parent = _edje_part_description_find(obj->ed, obj->rp, name, val))) + { + lua_pushnil(L); + return 1; + } + /* now create the custom state */ + Edje_Lua_Edje_Part_Description *tar = + lua_newuserdata(L, sizeof(Edje_Lua_Edje_Part_Description)); + tar->rp = obj->rp; + _edje_lua_set_class(L, -1, cDescription); + _edje_lua_new_reg(L, -1, tar); // freed in edje_load.c::_edje_file_del + if (!(tar->pd = calloc(1, sizeof(Edje_Part_Description)))) + { + lua_pushnil(L); + return 1; + } + + obj->rp->custom = eina_mempool_malloc(_edje_real_part_state_mp, sizeof (Edje_Real_Part_State)); + if (!obj->rp->custom) + { + free(tar->pd); + tar->pd = NULL; + lua_pushnil(L); + return 1; + } + + *(tar->pd) = *parent; + tar->pd->state.name = (char *)eina_stringshare_add("custom"); + tar->pd->state.value = 0.0; + /* + * make sure all the allocated memory is getting copied, + * not just referenced + */ + tar->pd->image.tween_list = NULL; + EINA_LIST_FOREACH(parent->image.tween_list, l, iid) + { + Edje_Part_Image_Id *iid_new; + iid_new = calloc(1, sizeof(Edje_Part_Image_Id)); + iid_new->id = iid->id; + + tar->pd->image.tween_list = + eina_list_append(tar->pd->image.tween_list, iid_new); + } +#define DUP(x) x ? (char *)eina_stringshare_add(x) : NULL + tar->pd->color_class = DUP(tar->pd->color_class); + tar->pd->text.text = DUP(tar->pd->text.text); + tar->pd->text.text_class = DUP(tar->pd->text.text_class); + tar->pd->text.font = DUP(tar->pd->text.font); + tar->pd->text.style = DUP(tar->pd->text.style); +#undef DUP + obj->rp->custom->description = tar->pd; + _edje_lua_new_reg(L, -1, obj->rp->custom->description); // freed in edje_load.c::_edje_file_del + return 1; +} + +static int +_edje_lua_part_fn_table_pack(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject); + lua_pushboolean(L, + edje_object_part_table_pack(obj->ed->obj, obj->key, tar->eo, + luaL_checkint(L, 3), + luaL_checkint(L, 4), + luaL_checkint(L, 5), + luaL_checkint(L, 6))); + return 1; +} + +static int +_edje_lua_part_fn_table_unpack(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject); + lua_pushboolean(L, + edje_object_part_table_unpack(obj->ed->obj, obj->key, tar->eo)); + return 1; +} + +static int +_edje_lua_part_fn_table_clear(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + lua_pushboolean(L, + edje_object_part_table_clear(obj->ed->obj, obj->key, lua_toboolean(L, 2))); + return 1; +} + +static int +_edje_lua_part_fn_box_append(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject); + lua_pushboolean(L, + edje_object_part_box_append(obj->ed->obj, obj->key, tar->eo)); + return 1; +} + +static int +_edje_lua_part_fn_box_prepend(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject); + lua_pushboolean(L, + edje_object_part_box_prepend(obj->ed->obj, obj->key, tar->eo)); + return 1; +} + +static int +_edje_lua_part_fn_box_insert_before(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject); + Edje_Lua_Evas_Object *ref = _edje_lua_checkudata(L, 3, &mObject); + lua_pushboolean(L, + edje_object_part_box_insert_before(obj->ed->obj, obj->key, tar->eo, tar->eo)); + return 1; +} + +static int +_edje_lua_part_fn_box_insert_at(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject); + lua_pushboolean(L, + edje_object_part_box_insert_at(obj->ed->obj, obj->key, tar->eo, luaL_checkint(L, 3))); + return 1; +} + +static int +_edje_lua_part_fn_box_remove(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + Edje_Lua_Evas_Object *tar = _edje_lua_checkudata(L, 2, &mObject); + edje_object_part_box_remove(obj->ed->obj, obj->key, tar->eo); + lua_pushvalue(L, 2); + return 1; +} + +static int +_edje_lua_part_fn_box_remove_at(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + _edje_lua_get_reg(L, edje_object_part_box_remove_at(obj->ed->obj, obj->key, luaL_checkint(L, 2))); + return 1; +} + +static int +_edje_lua_part_fn_box_remove_all(lua_State *L) +{ + Edje_Lua_Edje_Part_Object *obj = _edje_lua_checkudata(L, 1, &mPart); + lua_pushboolean(L, + edje_object_part_box_remove_all(obj->ed->obj, obj->key, lua_toboolean(L, 2))); + return 1; +} + +const luaL_Reg lPart_fn[] = { + {"swallow", _edje_lua_part_fn_swallow}, + {"unswallow", _edje_lua_part_fn_unswallow}, + + {"custom_state", _edje_lua_part_fn_custom_state}, + + {"text_select_none", _edje_lua_part_fn_text_select_none}, + {"text_select_all", _edje_lua_part_fn_text_select_all}, + {"text_insert", _edje_lua_part_fn_text_insert}, + + {"table_pack", _edje_lua_part_fn_table_pack}, + {"table_unpack", _edje_lua_part_fn_table_unpack}, + {"table_clear", _edje_lua_part_fn_table_clear}, + + {"box_append", _edje_lua_part_fn_box_append}, + {"box_prepend", _edje_lua_part_fn_box_prepend}, + {"box_insert_before", _edje_lua_part_fn_box_insert_before}, + {"box_insert_at", _edje_lua_part_fn_box_insert_at}, + {"box_remove", _edje_lua_part_fn_box_remove}, + {"box_remove_at", _edje_lua_part_fn_box_remove_at}, + {"box_remove_all", _edje_lua_part_fn_box_remove_all}, + {NULL, NULL} // sentinel +}; + +/* + * Group + */ + +const luaL_Reg lGroup_mt[]; + +const luaL_Reg lGroup_get[]; + +const luaL_Reg lGroup_set[]; + +const luaL_Reg lGroup_fn[]; + +const Edje_Lua_Reg mGroup = { + lGroup_mt, + lGroup_get, + lGroup_set, + lGroup_fn +}; + +const Edje_Lua_Reg *cGroup[] = { + &mClass, + &mObject, + &mGroup, + NULL // sentinel +}; + +static int +_edje_lua_group_mt_index(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + lua_getmetatable(L, 1); + if (!_edje_lua_look_fn(L)) + { + // look in lGroup_fn + if (!_edje_lua_look_get(L)) + { + // look in lGroup_get + const char *key = luaL_checkstring(L, 2); + Edje *ed = _edje_fetch(obj->eo); + Edje_Real_Part *rp = _edje_real_part_recursive_get(ed, key); + if (rp) + { + // check if lua userdata exists + Evas_Object *part = (Evas_Object *) edje_object_part_object_get(obj->eo, key); + _edje_lua_get_reg(L, part); + if (lua_isnil(L, -1)) + { + // create it + lua_pop(L, 1); + Edje_Lua_Edje_Part_Object *tar = + lua_newuserdata(L, sizeof(Edje_Lua_Edje_Part_Object)); + tar->eo = part; + tar->ed = ed; + tar->key = key; + tar->L = L; + tar->rp = rp; + _edje_lua_set_class(L, -1, cPart); + _edje_lua_new_reg(L, -1, tar); // freed in _edje_lua_edje_part_del_cb + _edje_lua_new_reg(L, -1, part); // freed in _edje_lua_edje_part_del_cb + evas_object_event_callback_add(tar->eo, + EVAS_CALLBACK_DEL, + _edje_lua_edje_part_del_cb, + L); + } + } + else + { + // look in obj environment table + lua_getfenv(L, 1); + lua_pushvalue(L, 2); // key + lua_rawget(L, -2); + } + } + } + return 1; +} + +const luaL_Reg lGroup_mt[] = { + {"__index", _edje_lua_group_mt_index}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_group_get_group(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + const char *file, *group; + edje_object_file_get(obj->eo, &file, &group); + lua_pushstring(L, group); + return 1; +} + +static int +_edje_lua_group_get_mouse(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + int x, y; + evas_pointer_canvas_xy_get(evas_object_evas_get(obj->eo), &x, &y); + x -= obj->ed->x; + y -= obj->ed->y; + lua_createtable(L, 2, 0); + lua_pushnumber(L, x); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, y); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_group_get_mouse_buttons(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + lua_pushnumber(L, evas_pointer_button_down_mask_get(obj->ed->evas)); + return 1; +} + +static int +_edje_lua_group_get_size_min(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + int w, h; + edje_object_size_min_get(obj->eo, &w, &h); + lua_createtable(L, 2, 0); + lua_pushnumber(L, w); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, h); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_group_get_size_max(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + int w, h; + edje_object_size_max_get(obj->eo, &w, &h); + lua_createtable(L, 2, 0); + lua_pushnumber(L, w); + lua_rawseti(L, -2, 1); + lua_pushnumber(L, h); + lua_rawseti(L, -2, 2); + return 1; +} + +static int +_edje_lua_group_get_scale(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + lua_pushnumber(L, edje_object_scale_get(obj->eo)); + return 1; +} + +static int +_edje_lua_group_get_load_error(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + lua_pushnumber(L, edje_object_load_error_get(obj->eo)); + return 1; +} + +static int +_edje_lua_group_get_load_error_str(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + lua_pushstring(L, edje_load_error_str(edje_object_load_error_get(obj->eo))); + return 1; +} + +static int +_edje_lua_group_get_play(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + lua_pushboolean(L, edje_object_play_get(obj->eo)); + return 1; +} + +static int +_edje_lua_group_get_animation(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + lua_pushboolean(L, edje_object_animation_get(obj->eo)); + return 1; +} + +static int +_edje_lua_group_get_frametime(lua_State *L) +{ + lua_pushnumber(L, edje_frametime_get()); + return 1; +} + +const luaL_Reg lGroup_get[] = { + {"group", _edje_lua_group_get_group}, + {"mouse", _edje_lua_group_get_mouse}, + {"mouse_buttons", _edje_lua_group_get_mouse_buttons}, + {"size_min", _edje_lua_group_get_size_min}, + {"size_max", _edje_lua_group_get_size_max}, + {"scale", _edje_lua_group_get_scale}, + {"load_error", _edje_lua_group_get_load_error}, + {"load_error_str", _edje_lua_group_get_load_error_str}, + {"play", _edje_lua_group_get_play}, + {"animation", _edje_lua_group_get_animation}, + {"frametime", _edje_lua_group_get_frametime}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_group_set_group(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + edje_object_file_set(obj->eo, obj->ed->file->path, luaL_checkstring(L, 2)); + return 0; +} + +static int +_edje_lua_group_set_size_min(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->ed->collection->prop.min.w = luaL_checkint(L, -2); + obj->ed->collection->prop.min.h = luaL_checkint(L, -1); + obj->ed->dirty = 1; + _edje_recalc(obj->ed); + return 0; +} + +static int +_edje_lua_group_set_size_max(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + luaL_checktype(L, 2, LUA_TTABLE); + lua_rawgeti(L, 2, 1); + lua_rawgeti(L, 2, 2); + obj->ed->collection->prop.max.w = luaL_checkint(L, -2); + obj->ed->collection->prop.max.h = luaL_checkint(L, -1); + obj->ed->dirty = 1; + _edje_recalc(obj->ed); + return 0; +} + +static int +_edje_lua_group_set_scale(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + edje_object_scale_set(obj->eo, luaL_checknumber(L, 2)); + return 0; +} + +static int +_edje_lua_group_set_play(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + edje_object_play_set(obj->eo, lua_toboolean(L, 2)); + return 0; +} + +static int +_edje_lua_group_set_animation(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + edje_object_animation_set(obj->eo, lua_toboolean(L, 2)); + return 0; +} + +static void +_edje_lua_group_text_change_cb(void* data, Evas_Object *obj, const char* part) +{ + Edje_Lua_Ref *ref = data; + lua_State *L = ref->L; + _edje_lua_get_ref(L, ref); + _edje_lua_get_reg(L, obj); + lua_pushstring(L, part); + int err_code; + if (err_code = lua_pcall(L, 2, 0, 0)) + _edje_lua_error(L, err_code); +} + +static int +_edje_lua_group_set_text_change_cb(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + edje_object_text_change_cb_set(obj->eo, _edje_lua_group_text_change_cb, _edje_lua_new_ref(L, 2)); + return 0; +} + +static int +_edje_lua_group_set_frametime(lua_State *L) +{ + edje_frametime_set(luaL_checknumber(L, 2)); + return 0; +} + +const luaL_Reg lGroup_set[] = { + {"group", _edje_lua_group_set_group}, + {"size_min", _edje_lua_group_set_size_min}, + {"size_max", _edje_lua_group_set_size_max}, + {"scale", _edje_lua_group_set_scale}, + {"play", _edje_lua_group_set_play}, + {"animation", _edje_lua_group_set_animation}, + {"text_change_cb", _edje_lua_group_set_text_change_cb}, + {"frametime", _edje_lua_group_set_frametime}, + {NULL, NULL} // sentinel +}; + +static int +_edje_lua_group_fn_timer(lua_State *L) +{ + Edje_Lua_Timer *tar = lua_newuserdata(L, sizeof(Edje_Lua_Timer)); + _edje_lua_set_class(L, -1, cTimer); + tar->et = ecore_timer_add(luaL_checknumber(L, 2), _edje_lua_timer_cb, tar); + tar->L = L; + _edje_lua_new_reg(L, -1, tar); // freed in _edje_lua_timer_cb/del + tar->cb = _edje_lua_new_ref(L, 3); // freed in _edje_lua_timer_cb/del + return 1; +} + +static int +_edje_lua_group_fn_animator(lua_State *L) +{ + Edje_Lua_Animator *tar = lua_newuserdata(L, sizeof(Edje_Lua_Animator)); + _edje_lua_set_class(L, -1, cAnimator); + tar->ea = ecore_animator_add(_edje_lua_animator_cb, tar); + tar->L = L; + _edje_lua_new_reg(L, -1, tar); // freed in _edje_lua_animator_cb/del + tar->cb = _edje_lua_new_ref(L, 2); // freed in _edje_lua_animator_cb/del + return 1; +} + +static int +_edje_lua_group_fn_poller(lua_State *L) +{ + int interval; + Edje_Lua_Poller *tar; + tar = lua_newuserdata(L, sizeof(Edje_Lua_Poller)); + _edje_lua_set_class(L, -1, cPoller); + + interval = luaL_checknumber(L, 2); + if ((interval <= 0) || ((interval & 1) != 0)) + { + return 0; + } + + // Only 1 type of poller currently implemented in ecore + tar->ep = ecore_poller_add(ECORE_POLLER_CORE, interval, + _edje_lua_poller_cb, tar); + tar->L = L; + _edje_lua_new_reg(L, -1, tar); // freed in _edje_lua_poller_cb/del + tar->cb = _edje_lua_new_ref(L, 3); // freed in _edje_lua_poller_cb/del + + return 1; +} + +static int +_edje_lua_group_fn_transform(lua_State *L) +{ + Edje_Lua_Transform *tar = lua_newuserdata(L, sizeof(Edje_Lua_Transform)); + evas_transform_identity_set (&(tar->et)); + _edje_lua_set_class(L, -1, cTransform); + tar->L = L; + return 1; +} + +static int +_edje_lua_group_fn_signal_emit(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + edje_object_signal_emit(obj->eo, + luaL_checkstring(L, 2), luaL_checkstring(L, 3)); + return 0; +} + +Edje_Program * +_edje_lua_program_get_byname(Evas_Object * obj, const char *prog_name) +{ + Edje_Program *epr; + int i; + Edje *ed; + ed = _edje_fetch(obj); + if (!ed) + return NULL; + if (!prog_name) + return NULL; + for (i = 0; i < ed->table_programs_size; i++) + { + epr = ed->table_programs[i]; + if ((epr->name) && (strcmp(epr->name, prog_name) == 0)) + return epr; + } + return NULL; +} + +static int +_edje_lua_group_fn_program_run(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + Edje_Program *pr = + _edje_lua_program_get_byname(obj->eo, luaL_checkstring(L, 2)); + if (pr) + _edje_program_run(obj->ed, pr, 0, "", ""); + return 0; +} + +static int +_edje_lua_group_fn_program_stop(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + Edje_Program *pr = + _edje_lua_program_get_byname(obj->eo, luaL_checkstring(L, 2)); + int program_id = pr->id; + Edje_Running_Program *runp; + Eina_List *l; + obj->ed->walking_actions = 1; + EINA_LIST_FOREACH(obj->ed->actions, l, runp) + if (program_id == runp->program->id) + _edje_program_end(obj->ed, runp); + obj->ed->walking_actions = 0; + return 0; +} + +static int +_edje_lua_group_fn_message_send(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + int type = luaL_checkint(L, 2); + void *msg = NULL; + int i; + int size; + switch (type) + { + case EDJE_MESSAGE_NONE: + break; + case EDJE_MESSAGE_SIGNAL: + break; + case EDJE_MESSAGE_STRING: + { + Edje_Message_String *msg_string = + malloc(sizeof(Edje_Message_String)); + msg_string->str = (char *)luaL_checkstring(L, 4); + msg = msg_string; + } + break; + case EDJE_MESSAGE_INT: + { + Edje_Message_Int *msg_int = malloc(sizeof(Edje_Message_Int)); + + msg_int->val = luaL_checkint(L, 4); + msg = msg_int; + } + break; + case EDJE_MESSAGE_FLOAT: + { + Edje_Message_Float *msg_float = malloc(sizeof(Edje_Message_Float)); + + msg_float->val = luaL_checknumber(L, 4); + msg = msg_float; + } + break; + case EDJE_MESSAGE_STRING_SET: + { + if (lua_type(L, 4) != LUA_TTABLE) + break; + size = lua_objlen(L, 4); + Edje_Message_String_Set *msg_string_set = + malloc(sizeof(Edje_Message_String_Set) + + (size - 1) * sizeof(char *)); + msg_string_set->count = size; + for (i = 0; i < size; i++) + { + lua_rawgeti(L, 4, i + 1); + msg_string_set->str[i] = (char *)luaL_checkstring(L, -1); + lua_pop(L, 1); + } + msg = msg_string_set; + } + break; + case EDJE_MESSAGE_INT_SET: + { + if (lua_type(L, 4) != LUA_TTABLE) + break; + size = lua_objlen(L, 4); + Edje_Message_Int_Set *msg_int_set = + malloc(sizeof(Edje_Message_Int_Set) + (size - 1) * sizeof(int)); + msg_int_set->count = size; + for (i = 0; i < size; i++) + { + lua_rawgeti(L, 4, i + 1); + msg_int_set->val[i] = luaL_checkint(L, -1); + lua_pop(L, 1); + } + msg = msg_int_set; + } + break; + case EDJE_MESSAGE_FLOAT_SET: + { + if (lua_type(L, 4) != LUA_TTABLE) + break; + size = lua_objlen(L, 4); + Edje_Message_Float_Set *msg_float_set = + malloc(sizeof(Edje_Message_Float_Set) + + (size - 1) * sizeof(double)); + msg_float_set->count = size; + for (i = 0; i < size; i++) + { + lua_rawgeti(L, 4, i + 1); + msg_float_set->val[i] = luaL_checknumber(L, -1); + lua_pop(L, 1); + } + msg = msg_float_set; + } + break; + case EDJE_MESSAGE_STRING_INT: + { + Edje_Message_String_Int *msg_string_int = + malloc(sizeof(Edje_Message_String_Int)); + msg_string_int->str = (char *)luaL_checkstring(L, 4); + msg_string_int->val = luaL_checkint(L, 5); + msg = msg_string_int; + } + break; + case EDJE_MESSAGE_STRING_FLOAT: + { + Edje_Message_String_Float *msg_string_float = + malloc(sizeof(Edje_Message_String_Float)); + msg_string_float->str = (char *)luaL_checkstring(L, 4); + msg_string_float->val = luaL_checknumber(L, 5); + msg = msg_string_float; + } + break; + case EDJE_MESSAGE_STRING_INT_SET: + { + if (lua_type(L, 5) != LUA_TTABLE) + break; + size = lua_objlen(L, 5); + Edje_Message_String_Int_Set *msg_string_int_set = + malloc(sizeof(Edje_Message_String_Int_Set) + + (size - 1) * sizeof(int)); + msg_string_int_set->str = (char *)luaL_checkstring(L, 4); + msg_string_int_set->count = size; + for (i = 0; i < size; i++) + { + lua_rawgeti(L, 5, i + 1); + msg_string_int_set->val[i] = luaL_checkint(L, -1); + lua_pop(L, 1); + } + msg = msg_string_int_set; + } + break; + case EDJE_MESSAGE_STRING_FLOAT_SET: + { + if (lua_type(L, 5) != LUA_TTABLE) + break; + size = lua_objlen(L, 5); + Edje_Message_String_Float_Set *msg_string_float_set = + malloc(sizeof(Edje_Message_String_Float_Set) + + (size - 1) * sizeof(double)); + msg_string_float_set->str = (char *)luaL_checkstring(L, 4); + msg_string_float_set->count = size; + for (i = 0; i < size; i++) + { + lua_rawgeti(L, 5, i + 1); + msg_string_float_set->val[i] = luaL_checknumber(L, -1); + lua_pop(L, 1); + } + msg = msg_string_float_set; + } + break; + default: + break; + } + + if (msg) + { + edje_object_message_send(obj->eo, type, luaL_checkint(L, 3), msg); + free(msg); + } + + return 0; +} + +static void +_edje_lua_group_signal_callback(void *data, Evas_Object * edj, + const char *signal, const char *source) +{ + Edje_Lua_Ref *cb = data; + lua_State *L = cb->L; + _edje_lua_get_ref(L, cb); // signal callback function + if (lua_isfunction(L, -1)) + { + _edje_lua_get_reg(L, edj); + lua_pushstring(L, signal); // signal + lua_pushstring(L, source); // source + int err_code; + if (err_code = lua_pcall(L, 3, 0, 0)) + _edje_lua_error(L, err_code); + } +} + +static int +_edje_lua_group_fn_signal_callback_add(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + if (lua_type(L, 4) == LUA_TFUNCTION) + { + Edje_Lua_Ref *ref = _edje_lua_new_ref(L, 4); + obj->cb = eina_list_append(obj->cb, ref); + edje_object_signal_callback_add(obj->eo, + luaL_checkstring(L, 2), + luaL_checkstring(L, 3), + _edje_lua_group_signal_callback, + ref); // freed in _edje_lua_group_fn_signal_callback_del + } + return 0; +} + +static int +_edje_lua_group_fn_signal_callback_del(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + Edje_Lua_Ref *ref = edje_object_signal_callback_del(obj->eo, + luaL_checkstring(L, 2), + luaL_checkstring(L, 3), + _edje_lua_group_signal_callback); + obj->cb = eina_list_remove(obj->cb, ref); + _edje_lua_free_ref(L, ref); // created in _edje_lua_group_fn_signal_callback_add + return 0; +} + +static int +_edje_lua_group_fn_freeze(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + edje_object_freeze(obj->eo); + return 0; +} + +static int +_edje_lua_group_fn_thaw(lua_State *L) +{ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata(L, 1, &mGroup); + edje_object_thaw(obj->eo); + return 0; +} + +const luaL_Reg lGroup_fn[] = { + {"timer", _edje_lua_group_fn_timer}, + {"animator", _edje_lua_group_fn_animator}, + {"poller", _edje_lua_group_fn_poller}, + {"transform", _edje_lua_group_fn_transform}, + {"signal_emit", _edje_lua_group_fn_signal_emit}, + {"message_send", _edje_lua_group_fn_message_send}, + {"program_run", _edje_lua_group_fn_program_run}, + {"program_stop", _edje_lua_group_fn_program_stop}, + {"signal_callback_add", _edje_lua_group_fn_signal_callback_add}, + {"signal_callback_del", _edje_lua_group_fn_signal_callback_del}, + {"freeze", _edje_lua_group_fn_freeze}, + {"thaw", _edje_lua_group_fn_thaw}, + {NULL, NULL} // sentinel +}; + +/* + * Lua bindings + */ + +const luaL_Reg lScript_get[]; + +const luaL_Reg lScript_set[]; + +const luaL_Reg lScript_fn[]; + +const Edje_Lua_Reg mScript = { + lNil, + lScript_get, + lScript_set, + lScript_fn +}; + +const Edje_Lua_Reg *cScript[] = { + &mClass, + &mObject, + &mGroup, + &mScript, + NULL // sentinel +}; + +/* + * macro for adding an evas_object in the lua_script_only object + */ +#define _EDJE_LUA_SCRIPT_FN_ADD(DEF, CLASS, FUNC) \ +static int \ +DEF (lua_State *L) \ +{ \ + int set = lua_gettop (L) == 2; \ + Edje_Lua_Evas_Object *obj = _edje_lua_checkudata (L, 1, &mScript); \ + Edje_Lua_Evas_Object *tar = lua_newuserdata (L, sizeof (Edje_Lua_Evas_Object)); \ + _edje_lua_set_class (L, -1, CLASS); \ + tar->eo = FUNC (obj->ed->evas); \ + tar->ed = obj->ed; \ + tar->L = L; \ + tar->cb = NULL; \ + evas_object_move (tar->eo, obj->ed->x, obj->ed->y); \ + _edje_lua_new_reg (L, -1, tar); /* freed in _edje_lua_object_del_cb */ \ + _edje_lua_new_reg (L, -1, tar->eo); /* freed in _edje_lua_object_del_cb */ \ + evas_object_smart_member_add (tar->eo, obj->eo); \ + evas_object_clip_set (tar->eo, obj->ed->clipper); \ + evas_object_event_callback_add (tar->eo, EVAS_CALLBACK_DEL, _edje_lua_object_del_cb, L); \ + if (set) \ + { \ + lua_getfield (L, -1, "set"); \ + lua_pushvalue (L, -2); \ + lua_pushvalue (L, 2); \ + int err_code; \ + if (err_code = lua_pcall (L, 2, 0, 0)) \ + _edje_lua_error (L, err_code); \ + } \ + return 1; \ +} + +_EDJE_LUA_SCRIPT_FN_ADD(_edje_lua_script_fn_rectangle, + cRectangle, + evas_object_rectangle_add) +_EDJE_LUA_SCRIPT_FN_ADD(_edje_lua_script_fn_image, + cImage, + evas_object_image_add) +_EDJE_LUA_SCRIPT_FN_ADD(_edje_lua_script_fn_table, + cTable, + evas_object_table_add) +_EDJE_LUA_SCRIPT_FN_ADD(_edje_lua_script_fn_line, + cLine, + evas_object_line_add) +_EDJE_LUA_SCRIPT_FN_ADD(_edje_lua_script_fn_polygon, + cPolygon, + evas_object_polygon_add) +_EDJE_LUA_SCRIPT_FN_ADD(_edje_lua_script_fn_group, cGroup, edje_object_add) + +const luaL_Reg lScript_fn[] = { + {"rectangle", _edje_lua_script_fn_rectangle}, + {"image", _edje_lua_script_fn_image}, + {"table", _edje_lua_script_fn_table}, + {"line", _edje_lua_script_fn_line}, + {"polygon", _edje_lua_script_fn_polygon}, + {"group", _edje_lua_script_fn_group}, + {NULL, NULL} // sentinel +}; + +const luaL_Reg lScript_get[] = { + {NULL, NULL} // sentinel +}; + +const luaL_Reg lScript_set[] = { + {NULL, NULL} // sentinel +}; + +/* + * creates and exports a lua_script_only object + */ +void +_edje_lua_script_fn_new(Edje * ed) +{ + lua_State *L = ed->L; + Edje_Lua_Evas_Object *tar = lua_newuserdata(L, sizeof(Edje_Lua_Evas_Object)); + _edje_lua_set_class(L, -1, cScript); + tar->eo = ed->obj; + tar->ed = ed; + tar->L = L; + tar->cb = NULL; + _edje_lua_new_reg(L, -1, tar); // freed in _edje_lua_object_del_cb + _edje_lua_new_reg(L, -1, ed); // freed in edje_load.c::_edje_file_del + _edje_lua_new_reg(L, -1, ed->obj); // freed in _edje_lua_object_del_cb + evas_object_event_callback_add(tar->eo, EVAS_CALLBACK_DEL, + _edje_lua_object_del_cb, L); +} + +/* + * creates and exports an Edje group with associated Lua scripts in the parts and programs sections + */ +void +_edje_lua_group_fn_new(Edje * ed) +{ + lua_State *L = ed->L; + Edje_Lua_Evas_Object *tar = lua_newuserdata(L, sizeof(Edje_Lua_Evas_Object)); + _edje_lua_set_class(L, -1, cGroup); + tar->eo = ed->obj; + tar->ed = ed; + tar->L = L; + tar->cb = NULL; + _edje_lua_new_reg(L, -1, tar); // freed in _edje_lua_object_del_cb + _edje_lua_new_reg(L, -1, ed); // freed in edje_load.c::_edje_file_del + _edje_lua_new_reg(L, -1, ed->obj); // freed in _edje_lua_object_del_cb + evas_object_event_callback_add(tar->eo, EVAS_CALLBACK_DEL, + _edje_lua_object_del_cb, L); +} + +/* + * this function loads all the Lua bindings into the global Lua state + */ +static void +_edje_lua_open(lua_State *L) +{ + /* + * export classes + */ + _edje_lua_new_class(L, cTimer); + _edje_lua_new_class(L, cAnimator); + _edje_lua_new_class(L, cPoller); + _edje_lua_new_class(L, cTransform); + _edje_lua_new_class(L, cRectangle); + _edje_lua_new_class(L, cImage); + _edje_lua_new_class(L, cTable); + _edje_lua_new_class(L, cLine); + _edje_lua_new_class(L, cPolygon); + _edje_lua_new_class(L, cGroup); + _edje_lua_new_class(L, cDescription); + _edje_lua_new_class(L, cPart); + _edje_lua_new_class(L, cScript); + + /* + * export constants + */ + _edje_lua_new_const(L, "MESSAGE_NONE", EDJE_MESSAGE_NONE); + _edje_lua_new_const(L, "MESSAGE_SIGNAL", EDJE_MESSAGE_SIGNAL); + _edje_lua_new_const(L, "MESSAGE_STRING", EDJE_MESSAGE_STRING); + _edje_lua_new_const(L, "MESSAGE_INT", EDJE_MESSAGE_INT); + _edje_lua_new_const(L, "MESSAGE_FLOAT", EDJE_MESSAGE_FLOAT); + _edje_lua_new_const(L, "MESSAGE_STRING_SET", EDJE_MESSAGE_STRING_SET); + _edje_lua_new_const(L, "MESSAGE_INT_SET", EDJE_MESSAGE_INT_SET); + _edje_lua_new_const(L, "MESSAGE_FLOAT_SET", EDJE_MESSAGE_FLOAT_SET); + _edje_lua_new_const(L, "MESSAGE_STRING_INT", EDJE_MESSAGE_STRING_INT); + _edje_lua_new_const(L, "MESSAGE_STRING_FLOAT", EDJE_MESSAGE_STRING_FLOAT); + _edje_lua_new_const(L, "MESSAGE_STRING_INT_SET", EDJE_MESSAGE_STRING_INT_SET); + _edje_lua_new_const(L, "MESSAGE_STRING_FLOAT_SET", EDJE_MESSAGE_STRING_FLOAT_SET); + + _edje_lua_new_const(L, "PART_TYPE_NONE", EDJE_PART_TYPE_NONE); + _edje_lua_new_const(L, "PART_TYPE_RECTANGLE", EDJE_PART_TYPE_RECTANGLE); + _edje_lua_new_const(L, "PART_TYPE_TEXT", EDJE_PART_TYPE_TEXT); + _edje_lua_new_const(L, "PART_TYPE_IMAGE", EDJE_PART_TYPE_IMAGE); + _edje_lua_new_const(L, "PART_TYPE_SWALLOW", EDJE_PART_TYPE_SWALLOW); + _edje_lua_new_const(L, "PART_TYPE_TEXTBLOCK", EDJE_PART_TYPE_TEXTBLOCK); + _edje_lua_new_const(L, "PART_TYPE_GRADIENT", EDJE_PART_TYPE_GRADIENT); + _edje_lua_new_const(L, "PART_TYPE_GROUP", EDJE_PART_TYPE_GROUP); + _edje_lua_new_const(L, "PART_TYPE_BOX", EDJE_PART_TYPE_BOX); + + _edje_lua_new_const(L, "TEXT_EFFECT_NONE", EDJE_TEXT_EFFECT_NONE); + _edje_lua_new_const(L, "TEXT_EFFECT_PLAIN", EDJE_TEXT_EFFECT_PLAIN); + _edje_lua_new_const(L, "TEXT_EFFECT_OUTLINE", EDJE_TEXT_EFFECT_OUTLINE); + _edje_lua_new_const(L, "TEXT_EFFECT_OTLINE", EDJE_TEXT_EFFECT_SOFT_OUTLINE); + _edje_lua_new_const(L, "TEXT_EFFECT_SHADOW", EDJE_TEXT_EFFECT_SHADOW); + _edje_lua_new_const(L, "TEXT_EFFECT_SOFT_SHADOW", EDJE_TEXT_EFFECT_SOFT_SHADOW); + _edje_lua_new_const(L, "TEXT_EFFECT_OUTLINE_SHADOW", EDJE_TEXT_EFFECT_OUTLINE_SHADOW); + _edje_lua_new_const(L, "TEXT_EFFECT_OUTLINE_SOFT_SHADOW", EDJE_TEXT_EFFECT_OUTLINE_SOFT_SHADOW); + _edje_lua_new_const(L, "TEXT_EFFECT_FAR_SHADOW", EDJE_TEXT_EFFECT_FAR_SHADOW); + _edje_lua_new_const(L, "TEXT_EFFECT_FAR_SOFT_SHADOW", EDJE_TEXT_EFFECT_FAR_SOFT_SHADOW); + _edje_lua_new_const(L, "TEXT_EFFECT_GLOW", EDJE_TEXT_EFFECT_GLOW); + + _edje_lua_new_const(L, "RENDER_BLEND", EVAS_RENDER_BLEND); + _edje_lua_new_const(L, "RENDER_BLEND_REL", EVAS_RENDER_BLEND_REL); + _edje_lua_new_const(L, "RENDER_COPY", EVAS_RENDER_COPY); + _edje_lua_new_const(L, "RENDER_COPY_REL", EVAS_RENDER_COPY_REL); + _edje_lua_new_const(L, "RENDER_ADD", EVAS_RENDER_ADD); + _edje_lua_new_const(L, "RENDER_ADD_REL", EVAS_RENDER_ADD_REL); + _edje_lua_new_const(L, "RENDER_SUB", EVAS_RENDER_SUB); + _edje_lua_new_const(L, "RENDER_SUB_REL", EVAS_RENDER_SUB_REL); + _edje_lua_new_const(L, "RENDER_TINT", EVAS_RENDER_TINT); + _edje_lua_new_const(L, "RENDER_TINT_REL", EVAS_RENDER_TINT_REL); + _edje_lua_new_const(L, "RENDER_MASK", EVAS_RENDER_MASK); + _edje_lua_new_const(L, "RENDER_MUL", EVAS_RENDER_MUL); + + _edje_lua_new_const(L, "BORDER_FILL_NONE", EVAS_BORDER_FILL_NONE); + _edje_lua_new_const(L, "BORDER_FILL_DEFAULT", EVAS_BORDER_FILL_DEFAULT); + _edje_lua_new_const(L, "BORDER_FILL_SOLID", EVAS_BORDER_FILL_SOLID); + + _edje_lua_new_const(L, "POINTER_MODE_AUTOGRAB", EVAS_OBJECT_POINTER_MODE_AUTOGRAB); + _edje_lua_new_const(L, "POINTER_MODE_NOGRAB", EVAS_OBJECT_POINTER_MODE_NOGRAB); + + _edje_lua_new_const(L, "ASPECT_CONTROL_NEITHER", EVAS_ASPECT_CONTROL_NEITHER); + _edje_lua_new_const(L, "ASPECT_CONTROL_HORIZONTAL", EVAS_ASPECT_CONTROL_HORIZONTAL); + _edje_lua_new_const(L, "ASPECT_CONTROL_VERTICAL", EVAS_ASPECT_CONTROL_VERTICAL); + _edje_lua_new_const(L, "ASPECT_CONTROL_BOTH", EVAS_ASPECT_CONTROL_BOTH); + + _edje_lua_new_const(L, "CALLBACK_RENEW", ECORE_CALLBACK_RENEW); + _edje_lua_new_const(L, "CALLBACK_CANCEL", ECORE_CALLBACK_CANCEL); +} + +/* + * main Lua state + * created by edje_init () + * closed by edje_shutdown () + * any other private Lua state inherits from this global state + */ +static lua_State *Ledje = NULL; + +lua_State * +_edje_lua_state_get () +{ + return Ledje; +} + +/* + * custom memory allocation function + * raises an error, if memory usage is above the given maximum + */ +static void * +_edje_lua_alloc(void *ud, void *ptr, size_t osize, size_t nsize) +{ + Edje_Lua_Alloc *ela = ud; + + ela->cur += nsize - osize; + if (ela->cur > ela->max) + { + fprintf(stderr, + "Edje Lua memory limit of %i bytes reached (%i allocated)\n", + ela->max, ela->cur); + return NULL; + } + if (nsize == 0) + { + free(ptr); /* ANSI requires that free(NULL) has no effect */ + return NULL; + } + else + /* ANSI requires that realloc(NULL, size) == malloc(size) */ + return realloc(ptr, nsize); +} + +void +_edje_lua_init() +{ + if (Ledje != NULL) return; + /* + * create main Lua state with the custom memory allocation function + */ + static Edje_Lua_Alloc ela = { 1e7, 0 }; // TODO make the memory limit configurable? + Ledje = lua_newstate(_edje_lua_alloc, &ela); + if (!Ledje) + { + fprintf(stderr, "Lua error: Lua state could not be initialized\n"); + exit(-1); + } + + /* + * configure Lua garbage collector + * TODO optimize garbage collector for typical edje use or make it configurable + */ + lua_gc(Ledje, LUA_GCSETPAUSE, 200); + lua_gc(Ledje, LUA_GCSETSTEPMUL, 200); + + /* + * sandbox Lua + * no access to io, os and package routines + * no loading and execution of files + * no loading and execution of strings + * no access to the OS environment + */ + luaopen_base(Ledje); + luaopen_table(Ledje); + luaopen_string(Ledje); + luaopen_math(Ledje); + luaopen_os(Ledje); + + /* + * FIXME + * this is just for debug purposes + * remove it in the final version + */ + lua_pushnil(Ledje); + lua_setglobal(Ledje, "load"); + lua_pushnil(Ledje); + lua_setglobal(Ledje, "loadfile"); + lua_pushnil(Ledje); + lua_setglobal(Ledje, "loadstring"); + lua_pushnil(Ledje); + lua_setglobal(Ledje, "dofile"); + lua_pushnil(Ledje); + lua_setglobal(Ledje, "dostring"); + + lua_getglobal(Ledje, "os"); + lua_pushnil(Ledje); + lua_setfield(Ledje, -2, "exit"); + lua_pushnil(Ledje); + lua_setfield(Ledje, -2, "setlocale"); + lua_pushnil(Ledje); + lua_setfield(Ledje, -2, "getenv"); + lua_pushnil(Ledje); + lua_setfield(Ledje, -2, "remove"); + lua_pushnil(Ledje); + lua_setfield(Ledje, -2, "tmpname"); + lua_pushnil(Ledje); + lua_setfield(Ledje, -2, "rename"); + lua_pushnil(Ledje); + lua_setfield(Ledje, -2, "execute"); + lua_pushnil(Ledje); + + /* + * we need a weak value registry + * so that deleted and unused objects can be garbage collected + */ + lua_createtable(Ledje, 1, 0); + //lua_pushstring(Ledje, "v"); + lua_pushstring(Ledje, ""); + lua_setfield(Ledje, -2, "__mode"); + lua_setmetatable(Ledje, LUA_REGISTRYINDEX); + + /* + * load Lua Evas/Edje bindings + */ + _edje_lua_open(Ledje); +} + +void +_edje_lua_shutdown() +{ + if (Ledje == NULL) return; + lua_close(Ledje); +} diff --git a/legacy/edje/src/lib/edje_lua_script_only.c b/legacy/edje/src/lib/edje_lua_script_only.c new file mode 100644 index 0000000000..ddeb4ea513 --- /dev/null +++ b/legacy/edje/src/lib/edje_lua_script_only.c @@ -0,0 +1,282 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifdef HAVE_ALLOCA_H +# include +#elif defined __GNUC__ +# define alloca __builtin_alloca +#elif defined _AIX +# define alloca __alloca +#elif defined _MSC_VER +# include +# define alloca _alloca +#else +# include +# ifdef __cplusplus +extern "C" +# endif +void *alloca(size_t); +#endif + +#include "edje_private.h" + +int +_edje_lua_script_only(Edje * ed) +{ + if ((ed->collection) && (ed->collection->L) && + (ed->collection->lua_script_only)) + return 1; + return 0; +} + +void +_edje_lua_script_only_init(Edje * ed) +{ + if (ed->collection && ed->collection->L) + { + ed->L = _edje_lua_new_thread(ed->collection->L); // freed in _edje_lua_script_only_shutdown + _edje_lua_new_reg(ed->collection->L, -1, ed->L); // freed in _edje_lua_script_only_shutdown + lua_pop(ed->collection->L, 1); /* thread */ + + lua_State *L = ed->L; + _edje_lua_script_fn_new(ed); + lua_pop(L, 1); /* script */ + + lua_getglobal(L, "init"); + if (!lua_isnil (L, -1)) + { + lua_pushvalue(L, LUA_GLOBALSINDEX); /* set function environment from collection thread to edje object thread */ + lua_setfenv(L, -2); + _edje_lua_get_reg(L, ed); + int err_code; + if (err_code = lua_pcall(L, 1, 0, 0)) + _edje_lua_error(L, err_code); + } + else + lua_pop(L, 1); + } +} + +void +_edje_lua_script_only_shutdown(Edje * ed) +{ + if (ed->collection && ed->collection->L && ed->L) + { + lua_State *L = ed->L; + lua_getglobal(L, "shutdown"); + if (!lua_isnil (L, -1)) + { + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfenv(L, -2); + _edje_lua_get_reg(L, ed); + int err_code; + if (err_code = lua_pcall(L, 1, 0, 0)) + _edje_lua_error(L, err_code); + } + else + lua_pop (L, 1); + } +} + +void +_edje_lua_script_only_show(Edje * ed) +{ + if (ed->collection && ed->collection->L && ed->L) + { + lua_State *L = ed->L; + lua_getglobal(L, "show"); + if (!lua_isnil (L, -1)) + { + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfenv(L, -2); + _edje_lua_get_reg(L, ed); + int err_code; + if (err_code = lua_pcall(L, 1, 0, 0)) + _edje_lua_error(L, err_code); + } + else + lua_pop (L, 1); + } +} + +void +_edje_lua_script_only_hide(Edje * ed) +{ + if (ed->collection && ed->collection->L && ed->L) + { + lua_State *L = ed->L; + lua_getglobal(L, "hide"); + if (!lua_isnil (L, -1)) + { + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfenv(L, -2); + _edje_lua_get_reg(L, ed); + int err_code; + if (err_code = lua_pcall(L, 1, 0, 0)) + _edje_lua_error(L, err_code); + } + else + lua_pop (L, 1); + } +} + +void +_edje_lua_script_only_move(Edje * ed) +{ + if (ed->collection && ed->collection->L && ed->L) + { + lua_State *L = ed->L; + lua_getglobal(L, "move"); + if (!lua_isnil (L, -1)) + { + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfenv(L, -2); + _edje_lua_get_reg(L, ed); + lua_pushnumber(L, ed->x); + lua_pushnumber(L, ed->y); + int err_code; + if (err_code = lua_pcall(L, 3, 0, 0)) + _edje_lua_error(L, err_code); + } + else + lua_pop (L, 1); + } +} + +void +_edje_lua_script_only_resize(Edje * ed) +{ + if (ed->collection && ed->collection->L && ed->L) + { + lua_State *L = ed->L; + lua_getglobal(L, "resize"); + if (!lua_isnil (L, -1)) + { + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfenv(L, -2); + _edje_lua_get_reg(L, ed); + lua_pushnumber(L, ed->w); + lua_pushnumber(L, ed->h); + int err_code; + if (err_code = lua_pcall(L, 3, 0, 0)) + _edje_lua_error(L, err_code); + } + else + lua_pop (L, 1); + } +} + +void +_edje_lua_script_only_message(Edje * ed, Edje_Message * em) +{ + if (ed->collection && ed->collection->L && ed->L) + { + lua_State *L = ed->L; + lua_getglobal(L, "message"); + if (!lua_isnil (L, -1)) + { + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfenv(L, -2); + _edje_lua_get_reg(L, ed); + lua_pushnumber(L, em->type); + lua_pushnumber(L, em->id); + int nargs = 3; + int i; + int count; + switch (em->type) + { + case EDJE_MESSAGE_NONE: + break; + case EDJE_MESSAGE_SIGNAL: + break; + case EDJE_MESSAGE_STRING: + lua_pushstring(L, ((Edje_Message_String *) em->msg)->str); + nargs += 1; + break; + case EDJE_MESSAGE_INT: + lua_pushnumber(L, ((Edje_Message_Int *) em->msg)->val); + nargs += 1; + break; + case EDJE_MESSAGE_FLOAT: + lua_pushnumber(L, ((Edje_Message_Float *) em->msg)->val); + nargs += 1; + break; + case EDJE_MESSAGE_STRING_SET: + count = ((Edje_Message_String_Set *) em->msg)->count; + lua_createtable(L, count, 0); + for (i = 0; i < count; i++) + { + lua_pushstring(L, ((Edje_Message_String_Set *) em->msg)->str[i]); + lua_rawseti(L, -2, i + 1); + } + nargs += 1; + break; + case EDJE_MESSAGE_INT_SET: + count = ((Edje_Message_Int_Set *) em->msg)->count; + lua_createtable(L, count, 0); + for (i = 0; i < count; i++) + { + lua_pushnumber(L, ((Edje_Message_Int_Set *) em->msg)->val[i]); + lua_rawseti(L, -2, i + 1); + } + nargs += 1; + break; + case EDJE_MESSAGE_FLOAT_SET: + count = ((Edje_Message_Float_Set *) em->msg)->count; + lua_createtable(L, count, 0); + for (i = 0; i < count; i++) + { + lua_pushnumber(L, ((Edje_Message_Float_Set *) em->msg)->val[i]); + lua_rawseti(L, -2, i + 1); + } + nargs += 1; + break; + case EDJE_MESSAGE_STRING_INT: + lua_pushstring(L, ((Edje_Message_String_Int *) em->msg)->str); + lua_pushnumber(L, ((Edje_Message_String_Int *) em->msg)->val); + nargs += 2; + break; + case EDJE_MESSAGE_STRING_FLOAT: + lua_pushstring(L, ((Edje_Message_String_Float *) em->msg)->str); + lua_pushnumber(L, ((Edje_Message_String_Float *) em->msg)->val); + nargs += 2; + break; + case EDJE_MESSAGE_STRING_INT_SET: + lua_pushstring(L, ((Edje_Message_String_Int_Set *) em->msg)->str); + count = ((Edje_Message_String_Int_Set *) em->msg)->count; + lua_createtable(L, count, 0); + for (i = 0; i < count; i++) + { + lua_pushnumber(L, ((Edje_Message_String_Int_Set *) em->msg)->val[i]); + lua_rawseti(L, -2, i + 1); + } + nargs += 2; + break; + case EDJE_MESSAGE_STRING_FLOAT_SET: + lua_pushstring(L, ((Edje_Message_String_Float_Set *) em->msg)->str); + count = ((Edje_Message_String_Float_Set *) em->msg)->count; + lua_createtable(L, count, 0); + for (i = 0; i < count; i++) + { + lua_pushnumber(L, ((Edje_Message_String_Float_Set *) em->msg)->val[i]); + lua_rawseti(L, -2, i + 1); + } + nargs += 2; + break; + default: + break; + } + int err_code; + if (err_code = lua_pcall(L, nargs, 0, 0)) + _edje_lua_error(L, err_code); + } + else + lua_pop (L, 1); + } +} + diff --git a/legacy/edje/src/lib/edje_main.c b/legacy/edje/src/lib/edje_main.c index abaa7603cc..0d8f9f3607 100644 --- a/legacy/edje/src/lib/edje_main.c +++ b/legacy/edje/src/lib/edje_main.c @@ -30,6 +30,7 @@ edje_init(void) _edje_edd_setup(); _edje_text_init(); _edje_box_init(); + _edje_lua_init(); embryo_init(); eet_init(); @@ -91,6 +92,7 @@ edje_shutdown(void) _edje_real_part_mp = NULL; embryo_shutdown(); + _edje_lua_shutdown(); ecore_job_shutdown(); eet_shutdown(); eina_shutdown(); diff --git a/legacy/edje/src/lib/edje_message_queue.c b/legacy/edje/src/lib/edje_message_queue.c index 65ed934e75..24d68f7b2e 100644 --- a/legacy/edje/src/lib/edje_message_queue.c +++ b/legacy/edje/src/lib/edje_message_queue.c @@ -558,12 +558,17 @@ _edje_message_process(Edje_Message *em) return; } /* now this message is destined for the script message handler fn */ - if (!((em->edje->collection) && (em->edje->collection->script))) return; - if (_edje_script_only(em->edje)) + if (!(em->edje->collection)) return; + if ((em->edje->collection->script) && _edje_script_only (em->edje)) { _edje_script_only_message(em->edje, em); return; } + if (em->edje->collection->L) + { + _edje_lua_script_only_message(em->edje, em); + return; + } fn = embryo_program_function_find(em->edje->collection->script, "message"); if (fn == EMBRYO_FUNCTION_NONE) return; /* reset the engine */ diff --git a/legacy/edje/src/lib/edje_private.h b/legacy/edje/src/lib/edje_private.h index 87e750d33f..4fafe66406 100644 --- a/legacy/edje/src/lib/edje_private.h +++ b/legacy/edje/src/lib/edje_private.h @@ -23,6 +23,8 @@ #include "Edje.h" #include "Edje_Edit.h" +#include + #ifdef __GNUC__ # if __GNUC__ >= 4 // BROKEN in gcc 4 on amd64 @@ -179,7 +181,8 @@ typedef struct _Edje_Patterns Edje_Patterns; #define EDJE_ACTION_TYPE_DRAG_VAL_PAGE 6 #define EDJE_ACTION_TYPE_SCRIPT 7 #define EDJE_ACTION_TYPE_FOCUS_SET 8 -#define EDJE_ACTION_TYPE_LAST 9 +#define EDJE_ACTION_TYPE_LUA_SCRIPT 9 +#define EDJE_ACTION_TYPE_LAST 10 #define EDJE_TWEEN_MODE_NONE 0 #define EDJE_TWEEN_MODE_LINEAR 1 @@ -447,10 +450,12 @@ struct _Edje_Part_Collection #endif Embryo_Program *script; /* all the embryo script code for this group */ - const char *part; unsigned char script_only; + + unsigned char lua_script_only; + lua_State *L; }; struct _Edje_Part @@ -728,6 +733,7 @@ struct _Edje unsigned short text_part_change : 1; unsigned short all_part_change : 1; #endif + lua_State *L; }; struct _Edje_Calc_Params @@ -1334,6 +1340,27 @@ void _edje_script_only_move(Edje *ed); void _edje_script_only_resize(Edje *ed); void _edje_script_only_message(Edje *ed, Edje_Message *em); +lua_State *_edje_lua_state_get(); +lua_State *_edje_lua_new_thread(lua_State *L); +void _edje_lua_free_thread(lua_State *L); +void _edje_lua_new_reg(lua_State *L, int index, void *ptr); +void _edje_lua_get_reg(lua_State *L, void *ptr); +void _edje_lua_free_reg(lua_State *L, void *ptr); +void _edje_lua_script_fn_new(Edje *ed); +void _edje_lua_group_fn_new(Edje *ed); +void _edje_lua_init(); +void _edje_lua_shutdown(); +void _edje_lua_error(lua_State *L, int err_code); + +int _edje_lua_script_only(Edje *ed); +void _edje_lua_script_only_init(Edje *ed); +void _edje_lua_script_only_shutdown(Edje *ed); +void _edje_lua_script_only_show(Edje *ed); +void _edje_lua_script_only_hide(Edje *ed); +void _edje_lua_script_only_move(Edje *ed); +void _edje_lua_script_only_resize(Edje *ed); +void _edje_lua_script_only_message(Edje *ed, Edje_Message *em); + void _edje_entry_init(Edje *ed); void _edje_entry_shutdown(Edje *ed); void _edje_entry_real_part_init(Edje_Real_Part *rp); diff --git a/legacy/edje/src/lib/edje_program.c b/legacy/edje/src/lib/edje_program.c index 0c5d2342e4..b7219996b8 100644 --- a/legacy/edje/src/lib/edje_program.c +++ b/legacy/edje/src/lib/edje_program.c @@ -752,6 +752,43 @@ _edje_program_run(Edje *ed, Edje_Program *pr, int force, const char *ssig, const if (_edje_block_break(ed)) goto break_prog; _edje_recalc_do(ed); } + else if (pr->action == EDJE_ACTION_TYPE_LUA_SCRIPT) + { + //printf ("running Lua program script %i\n", pr->id); + +// _edje_emit(ed, "program,start", pr->name); + if (_edje_block_break(ed)) goto break_prog; + + if (ed->L == NULL) /* private state does not yet exist, create it */ + { + ed->L = _edje_lua_new_thread(ed->collection->L); + _edje_lua_new_reg(ed->collection->L, -1, ed->L); // freed in edje_load.c::_edje_file_del + lua_pop(ed->collection->L, 1); + } + lua_State *L = ed->L; + lua_pushnumber(L, pr->id); + lua_gettable(L, LUA_GLOBALSINDEX); + if (!lua_isnil(L, -1)) + { + lua_pushvalue(L, LUA_GLOBALSINDEX); /* set function environment from collection thread to edje object thread */ + lua_setfenv(L, -2); + _edje_lua_get_reg(L, ed); + if (lua_isnil(L, -1)) /* group object does not yet exist, create it */ + { + lua_pop(L, 1); + _edje_lua_group_fn_new (ed); + } + lua_pushstring(L, ssig); + lua_pushstring(L, ssrc); + int err_code; + if (err_code = lua_pcall(L, 3, 0, 0)) + _edje_lua_error(L, err_code); + } + + // _edje_emit(ed, "program,stop", pr->name); + if (_edje_block_break(ed)) goto break_prog; + _edje_recalc_do(ed); + } else if (pr->action == EDJE_ACTION_TYPE_FOCUS_SET) { if (!pr->targets) diff --git a/legacy/edje/src/lib/edje_script_only.c b/legacy/edje/src/lib/edje_script_only.c index e8835c4e7f..21af43a90b 100644 --- a/legacy/edje/src/lib/edje_script_only.c +++ b/legacy/edje/src/lib/edje_script_only.c @@ -20,7 +20,7 @@ # ifdef __cplusplus extern "C" # endif -void *alloca (size_t); +void *alloca(size_t); #endif #include "edje_private.h" @@ -76,25 +76,25 @@ typedef struct _Sinfo Sinfo; struct _Sinfo { - struct { + struct + { Embryo_Function - obj_init, obj_shutdown, obj_show, obj_show_immediate, - obj_hide, obj_hide_immediate, obj_move, obj_move_immediate, - obj_resize, obj_resize_immediate, obj_message - ; + obj_init, obj_shutdown, obj_show, obj_show_immediate, + obj_hide, obj_hide_immediate, obj_move, obj_move_immediate, + obj_resize, obj_resize_immediate, obj_message; } fn; - struct { - Ecore_Job - *show, *hide, *move, *resize - ; + struct + { + Ecore_Job * show, *hide, *move, *resize; } job; - struct { + struct + { int id; - Eina_Hash *hash; // FIXME: hash -> bad. too big. one-way lookup etc. + Eina_Hash *hash; // FIXME: hash -> bad. too big. one-way lookup etc. } oid; }; -static void _call_fn(Edje *ed, const char *fname, Embryo_Function fn); +static void _call_fn(Edje * ed, const char *fname, Embryo_Function fn); /* frankly - these make the code shorter to type and read - just sanity for * development */ @@ -124,23 +124,26 @@ struct _Oid /* FIXME: using eina_hash and strings is just nasty! make a custom int hash */ static int -_oid_alloc(Edje *ed) +_oid_alloc(Edje * ed) { SI_RETURN(0); - + si->oid.id++; return si->oid.id; } static Oid * -_oid_track(Edje *ed, Evas_Object *o) +_oid_track(Edje * ed, Evas_Object * o) { Oid *oi; + char buf[64]; + SI_RETURN(NULL); - + oi = calloc(1, sizeof(Oid)); - if (!oi) return NULL; + if (!oi) + return NULL; oi->oid = _oid_alloc(ed); if (!oi->oid) { @@ -153,15 +156,17 @@ _oid_track(Edje *ed, Evas_Object *o) evas_object_clip_set(oi->obj, oi->ed->clipper); evas_object_geometry_get(oi->obj, &(oi->x), &(oi->y), &(oi->w), &(oi->h)); snprintf(buf, sizeof(buf), "%i", oi->oid); - if (!si->oid.hash) si->oid.hash = eina_hash_string_superfast_new(NULL); + if (!si->oid.hash) + si->oid.hash = eina_hash_string_superfast_new(NULL); eina_hash_add(si->oid.hash, buf, oi); return oi; } static Oid * -_oid_find(Edje *ed, int oid) +_oid_find(Edje * ed, int oid) { char buf[64]; + SI_RETURN(NULL); snprintf(buf, sizeof(buf), "%i", oid); @@ -169,9 +174,10 @@ _oid_find(Edje *ed, int oid) } static void -_oid_del(Edje *ed, int oid) +_oid_del(Edje * ed, int oid) { char buf[64]; + SI; snprintf(buf, sizeof(buf), "%i", oid); @@ -179,147 +185,179 @@ _oid_del(Edje *ed, int oid) } static void -_oid_free(Oid *oid) +_oid_free(Oid * oid) { free(oid); } static Eina_Bool -_oid_freeall_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata) +_oid_freeall_cb(const Eina_Hash * hash, const void *key, void *data, + void *fdata) { Oid *oid = data; + evas_object_del(oid->obj); free(oid); return 1; } static void -_oid_freeall(Edje *ed) +_oid_freeall(Edje * ed) { SI; - if (!si->oid.hash) return; + if (!si->oid.hash) + return; eina_hash_foreach(si->oid.hash, _oid_freeall_cb, ed); eina_hash_free(si->oid.hash); si->oid.hash = NULL; } static Eina_Bool -_oid_moveall_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata) +_oid_moveall_cb(const Eina_Hash * hash, const void *key, void *data, + void *fdata) { Oid *oid = data; + evas_object_move(oid->obj, oid->ed->x + oid->x, oid->ed->y + oid->y); return 1; } static void -_oid_moveall(Edje *ed) +_oid_moveall(Edje * ed) { SI; - if (!si->oid.hash) return; + if (!si->oid.hash) + return; eina_hash_foreach(si->oid.hash, _oid_moveall_cb, ed); } /**********/ static Embryo_Cell -_exp_e_obj_del(Embryo_Program *ep, Embryo_Cell *params) +_exp_e_obj_del(Embryo_Program * ep, Embryo_Cell * params) { Edje *ed = embryo_program_data_get(ep); + Oid *oid; + SI_RETURN(-1); CHKPARAM(1); - if (!(oid = _oid_find(ed, params[1]))) return -1; + if (!(oid = _oid_find(ed, params[1]))) + return -1; evas_object_del(oid->obj); _oid_del(ed, oid->oid); _oid_free(oid); return 0; } - + static Embryo_Cell -_exp_e_obj_rect_add(Embryo_Program *ep, Embryo_Cell *params) +_exp_e_obj_rect_add(Embryo_Program * ep, Embryo_Cell * params) { Edje *ed = embryo_program_data_get(ep); + Evas_Object *o; + Oid *oid; + SI_RETURN(-1); - + o = evas_object_rectangle_add(evas_object_evas_get(ed->obj)); - if (!o) return 0; + if (!o) + return 0; oid = _oid_track(ed, o); - if (oid) return oid->oid; + if (oid) + return oid->oid; return 0; } - + static Embryo_Cell -_exp_e_obj_show(Embryo_Program *ep, Embryo_Cell *params) +_exp_e_obj_show(Embryo_Program * ep, Embryo_Cell * params) { Edje *ed = embryo_program_data_get(ep); + Oid *oid; + SI_RETURN(-1); CHKPARAM(1); - if (!(oid = _oid_find(ed, params[1]))) return -1; + if (!(oid = _oid_find(ed, params[1]))) + return -1; evas_object_show(oid->obj); return 0; } - + static Embryo_Cell -_exp_e_obj_hide(Embryo_Program *ep, Embryo_Cell *params) +_exp_e_obj_hide(Embryo_Program * ep, Embryo_Cell * params) { Edje *ed = embryo_program_data_get(ep); + Oid *oid; + SI_RETURN(-1); CHKPARAM(1); - if (!(oid = _oid_find(ed, params[1]))) return -1; + if (!(oid = _oid_find(ed, params[1]))) + return -1; evas_object_hide(oid->obj); return 0; } - + static Embryo_Cell -_exp_e_obj_move(Embryo_Program *ep, Embryo_Cell *params) +_exp_e_obj_move(Embryo_Program * ep, Embryo_Cell * params) { Edje *ed = embryo_program_data_get(ep); + Oid *oid; + SI_RETURN(-1); - + CHKPARAM(3); - if (!(oid = _oid_find(ed, params[1]))) return -1; - if ((oid->x == params[2]) && (oid->y == params[3])) return -1; + if (!(oid = _oid_find(ed, params[1]))) + return -1; + if ((oid->x == params[2]) && (oid->y == params[3])) + return -1; oid->x = params[2]; oid->y = params[3]; evas_object_move(oid->obj, ed->x + oid->x, ed->y + oid->y); return 0; } - + static Embryo_Cell -_exp_e_obj_resize(Embryo_Program *ep, Embryo_Cell *params) +_exp_e_obj_resize(Embryo_Program * ep, Embryo_Cell * params) { Edje *ed = embryo_program_data_get(ep); + Oid *oid; + SI_RETURN(-1); - + CHKPARAM(3); - if (!(oid = _oid_find(ed, params[1]))) return -1; - if ((oid->w == params[2]) && (oid->h == params[3])) return -1; + if (!(oid = _oid_find(ed, params[1]))) + return -1; + if ((oid->w == params[2]) && (oid->h == params[3])) + return -1; oid->w = params[2]; oid->h = params[3]; evas_object_resize(oid->obj, oid->w, oid->h); return 0; } - + static Embryo_Cell -_exp_e_obj_geometry_set(Embryo_Program *ep, Embryo_Cell *params) +_exp_e_obj_geometry_set(Embryo_Program * ep, Embryo_Cell * params) { Edje *ed = embryo_program_data_get(ep); + Oid *oid; + SI_RETURN(-1); - + CHKPARAM(5); - if (!(oid = _oid_find(ed, params[1]))) return -1; + if (!(oid = _oid_find(ed, params[1]))) + return -1; if ((oid->x == params[2]) && (oid->y == params[3]) && - (oid->w == params[4]) && (oid->h == params[5])) return -1; + (oid->w == params[4]) && (oid->h == params[5])) + return -1; oid->x = params[2]; oid->y = params[3]; oid->w = params[4]; @@ -328,47 +366,57 @@ _exp_e_obj_geometry_set(Embryo_Program *ep, Embryo_Cell *params) evas_object_resize(oid->obj, oid->w, oid->h); return 0; } - + static Embryo_Cell -_exp_e_obj_geometry_get(Embryo_Program *ep, Embryo_Cell *params) +_exp_e_obj_geometry_get(Embryo_Program * ep, Embryo_Cell * params) { Edje *ed = embryo_program_data_get(ep); + Oid *oid; + SI_RETURN(-1); - + CHKPARAM(5); - if (!(oid = _oid_find(ed, params[1]))) return -1; + if (!(oid = _oid_find(ed, params[1]))) + return -1; SETINT(oid->x, params[2]); SETINT(oid->y, params[3]); SETINT(oid->w, params[4]); SETINT(oid->h, params[5]); return 0; } - + static Embryo_Cell -_exp_e_obj_color_set(Embryo_Program *ep, Embryo_Cell *params) +_exp_e_obj_color_set(Embryo_Program * ep, Embryo_Cell * params) { Edje *ed = embryo_program_data_get(ep); + Oid *oid; + SI_RETURN(-1); CHKPARAM(5); - if (!(oid = _oid_find(ed, params[1]))) return -1; + if (!(oid = _oid_find(ed, params[1]))) + return -1; evas_object_color_set(oid->obj, params[2], params[3], params[4], params[5]); return 0; } static Embryo_Cell -_exp_e_obj_color_get(Embryo_Program *ep, Embryo_Cell *params) +_exp_e_obj_color_get(Embryo_Program * ep, Embryo_Cell * params) { Edje *ed = embryo_program_data_get(ep); + Oid *oid; + int r, g, b, a; + SI_RETURN(-1); CHKPARAM(5); - if (!(oid = _oid_find(ed, params[1]))) return -1; - evas_object_color_get(oid->obj, &r, &g , &b, &a); + if (!(oid = _oid_find(ed, params[1]))) + return -1; + evas_object_color_get(oid->obj, &r, &g, &b, &a); SETINT(r, params[2]); SETINT(g, params[3]); SETINT(b, params[4]); @@ -377,16 +425,19 @@ _exp_e_obj_color_get(Embryo_Program *ep, Embryo_Cell *params) } static Embryo_Cell -_exp_e_signal_emit(Embryo_Program *ep, Embryo_Cell *params) +_exp_e_signal_emit(Embryo_Program * ep, Embryo_Cell * params) { Edje *ed = embryo_program_data_get(ep); + char *sig = NULL, *src = NULL; + SI_RETURN(-1); - + CHKPARAM(2); GETSTR(sig, params[1]); GETSTR(src, params[2]); - if ((!sig) || (!src)) return -1; + if ((!sig) || (!src)) + return -1; _edje_emit(ed, sig, src); return 0; } @@ -394,25 +445,26 @@ _exp_e_signal_emit(Embryo_Program *ep, Embryo_Cell *params) /**********/ int -_edje_script_only(Edje *ed) +_edje_script_only(Edje * ed) { if ((ed->collection) && (ed->collection->script) && (ed->collection->script_only)) - return 1; + return 1; return 0; } void -_edje_script_only_init(Edje *ed) +_edje_script_only_init(Edje * ed) { Sinfo *si; - + si = calloc(1, sizeof(Sinfo)); - if (!si) return; + if (!si) + return; ed->script_only_data = si; embryo_program_data_set(ed->collection->script, ed); - + EXPF(e_obj_del); EXPF(e_obj_rect_add); EXPF(e_obj_show); @@ -424,7 +476,7 @@ _edje_script_only_init(Edje *ed) EXPF(e_obj_color_set); EXPF(e_obj_color_get); EXPF(e_signal_emit); - + embryo_program_vm_push(ed->collection->script); embryo_program_max_cycle_run_set(ed->collection->script, 5000000); @@ -445,7 +497,7 @@ _edje_script_only_init(Edje *ed) } void -_edje_script_only_shutdown(Edje *ed) +_edje_script_only_shutdown(Edje * ed) { SI; @@ -461,28 +513,29 @@ static void _show_job(void *data) { Edje *ed = data; + SI; - + ZERJ(show); CLFN(obj_show); } void -_edje_script_only_show(Edje *ed) +_edje_script_only_show(Edje * ed) { SI; - + IFFN(obj_show) - { - IFNJ(hide) - { - DELJ(show); - ADDJ(show, _show_job); - } - else - { - DELJ(hide); - } - } + { + IFNJ(hide) + { + DELJ(show); + ADDJ(show, _show_job); + } + else + { + DELJ(hide); + } + } IFNO(obj_show_immediate) return; CLFN(obj_show_immediate); } @@ -491,28 +544,29 @@ static void _hide_job(void *data) { Edje *ed = data; + SI; - + ZERJ(hide); CLFN(obj_hide); } void -_edje_script_only_hide(Edje *ed) +_edje_script_only_hide(Edje * ed) { SI; - + IFFN(obj_hide) - { - IFNJ(show) - { - DELJ(hide); - ADDJ(hide, _hide_job); - } - else - { - DELJ(show); - } - } + { + IFNJ(show) + { + DELJ(hide); + ADDJ(hide, _hide_job); + } + else + { + DELJ(show); + } + } IFNO(obj_hide_immediate) return; CLFN(obj_hide_immediate); } @@ -521,8 +575,9 @@ static void _move_job(void *data) { Edje *ed = data; + SI; - + _oid_moveall(ed); ZERJ(move); IFNO(obj_move) return; @@ -531,7 +586,7 @@ _move_job(void *data) CLFN(obj_move); } void -_edje_script_only_move(Edje *ed) +_edje_script_only_move(Edje * ed) { SI; @@ -547,33 +602,34 @@ static void _resize_job(void *data) { Edje *ed = data; + SI; - + ZERJ(resize); PINT(ed->w); PINT(ed->h); CLFN(obj_resize); } void -_edje_script_only_resize(Edje *ed) +_edje_script_only_resize(Edje * ed) { SI; IFFN(obj_resize) - { - DELJ(resize); - ADDJ(resize, _resize_job); - } + { + DELJ(resize); + ADDJ(resize, _resize_job); + } PINT(ed->w); PINT(ed->h); CLFN(obj_resize_immediate); } void -_edje_script_only_message(Edje *ed, Edje_Message *em) +_edje_script_only_message(Edje * ed, Edje_Message * em) { SI; - + IFNO(obj_message) return; _edje_message_parameters_push(em); CLFN(obj_message); @@ -582,10 +638,10 @@ _edje_script_only_message(Edje *ed, Edje_Message *em) /**************************************************/ static void -_call_fn(Edje *ed, const char *fname, Embryo_Function fn) +_call_fn(Edje * ed, const char *fname, Embryo_Function fn) { int ret; - + ret = embryo_program_run(ed->collection->script, fn); if (ret == EMBRYO_PROGRAM_FAIL) { @@ -593,15 +649,14 @@ _call_fn(Edje *ed, const char *fname, Embryo_Function fn) "ENTRY POINT: %s\n" "ERROR: %s\n", fname, - embryo_error_string_get(embryo_program_error_get(ed->collection->script))); + embryo_error_string_get(embryo_program_error_get + (ed->collection->script))); } else if (ret == EMBRYO_PROGRAM_TOOLONG) { printf("EDJE: ERROR with embryo script.\n" "ENTRY POINT: %s\n" "ERROR: Script exceeded maximum allowed cycle count of %i\n", - fname, - embryo_program_max_cycle_run_get(ed->collection->script)); + fname, embryo_program_max_cycle_run_get(ed->collection->script)); } } - diff --git a/legacy/edje/src/lib/edje_smart.c b/legacy/edje/src/lib/edje_smart.c index c1b6f780df..aad086cde4 100644 --- a/legacy/edje/src/lib/edje_smart.c +++ b/legacy/edje/src/lib/edje_smart.c @@ -99,6 +99,7 @@ _edje_smart_del(Evas_Object * obj) _edje_edjes = eina_list_remove(_edje_edjes, obj); evas_object_smart_data_set(obj, NULL); if (_edje_script_only(ed)) _edje_script_only_shutdown(ed); + if (_edje_lua_script_only(ed)) _edje_lua_script_only_shutdown(ed); _edje_file_del(ed); _edje_unref(ed); } @@ -121,6 +122,11 @@ _edje_smart_move(Evas_Object * obj, Evas_Coord x, Evas_Coord y) _edje_script_only_move(ed); return; } + if (_edje_lua_script_only(ed)) + { + _edje_lua_script_only_move(ed); + return; + } for (i = 0; i < ed->table_parts_size; i++) { @@ -159,6 +165,11 @@ _edje_smart_resize(Evas_Object * obj, Evas_Coord w, Evas_Coord h) _edje_script_only_resize(ed); return; } + if (_edje_lua_script_only(ed)) + { + _edje_lua_script_only_resize(ed); + return; + } // evas_object_resize(ed->clipper, ed->w, ed->h); ed->dirty = 1; _edje_recalc_do(ed); @@ -180,6 +191,11 @@ _edje_smart_show(Evas_Object * obj) _edje_script_only_show(ed); return; } + if (_edje_lua_script_only(ed)) + { + _edje_lua_script_only_show(ed); + return; + } _edje_emit(ed, "show", NULL); } @@ -198,6 +214,11 @@ _edje_smart_hide(Evas_Object * obj) _edje_script_only_hide(ed); return; } + if (_edje_lua_script_only(ed)) + { + _edje_lua_script_only_hide(ed); + return; + } _edje_emit(ed, "hide", NULL); }