New embryo function: get_program_id
authorEduardo Lima (Etrunko) <eduardo.lima@intel.com>
Tue, 4 Dec 2012 20:21:59 +0000 (20:21 +0000)
committerEduardo de Barros Lima <eblima@gmail.com>
Tue, 4 Dec 2012 20:21:59 +0000 (20:21 +0000)
It is now you can run programs with names generated dinamically. Say that you
have 10 programs indexed somehow. You can now call them using the following snippet:

script {
   new program_id[15], i;
   for (i = 0; i < 10; i++) {
      snprintf(program_id, 15, "my_program_%d", i+1);
      run_program(get_program_id(program_id));
   }
}

Signed-off-by: Eduardo Lima (Etrunko) <eduardo.lima@intel.com>
SVN revision: 80199

legacy/edje/ChangeLog
legacy/edje/data/include/edje.inc
legacy/edje/src/lib/edje_embryo.c

index 3b2e13c..1fcc946 100644 (file)
 2012-11-23  Bruno Dilly
 
         * Support message sending on edje player.
+
+2012-11-23  Eduardo Lima (Etrunko)
+
+        * Add embryo function get_program_id
index 55eb9ee..50f2bbe 100644 (file)
@@ -85,6 +85,7 @@ native       cancel_anim(id);
 native       emit             (sig[], src[]);
 native       get_part_id      (part[]);
 native       get_image_id      (image[]);
+native       get_program_id   (program[]);
 native       set_state        (part_id, state[], Float:state_val);
 native       get_state        (part_id, dst[], maxlen, &Float:val);
 native       set_tween_state  (part_id, Float:tween, state1[], Float:state1_val, state2[], Float:state2_val);
index 1522dbb..77f23b1 100644 (file)
@@ -855,6 +855,29 @@ _edje_embryo_fn_get_image_id(Embryo_Program *ep, Embryo_Cell *params)
    return -1;
 }
 
+/* get_program_id(program[]) */
+static Embryo_Cell
+_edje_embryo_fn_get_program_id(Embryo_Program *ep, Embryo_Cell *params)
+{
+   Edje *ed;
+   Edje_Program **prog;
+   char *p;
+   int i;
+
+   CHKPARAM(1);
+   ed = embryo_program_data_get(ep);
+   GETSTR(p, params[1]);
+   if (!p) return -1;
+   prog = ed->table_programs;
+   if (!prog) return -1;
+   for (i = 0; i < ed->table_programs_size; i++, prog++)
+     {
+        if (!(*prog)->name) continue;
+        if (!strcmp((*prog)->name, p)) return (*prog)->id;
+     }
+   return -1;
+}
+
 static Embryo_Cell
 _edje_embryo_fn_play_sample(Embryo_Program *ep, Embryo_Cell *params)
 {
@@ -3050,6 +3073,7 @@ _edje_embryo_script_init(Edje_Part_Collection *edc)
    embryo_program_native_call_add(ep, "emit", _edje_embryo_fn_emit);
    embryo_program_native_call_add(ep, "get_part_id", _edje_embryo_fn_get_part_id);
    embryo_program_native_call_add(ep, "get_image_id", _edje_embryo_fn_get_image_id);
+   embryo_program_native_call_add(ep, "get_program_id", _edje_embryo_fn_get_program_id);
    embryo_program_native_call_add(ep, "set_state", _edje_embryo_fn_set_state);
    embryo_program_native_call_add(ep, "get_state", _edje_embryo_fn_get_state);
    embryo_program_native_call_add(ep, "set_tween_state", _edje_embryo_fn_set_tween_state);