]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Add support for variable number of arguments
authorCharlie Brej <cbrej@cs.man.ac.uk>
Wed, 8 Jul 2009 23:23:23 +0000 (00:23 +0100)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Wed, 8 Jul 2009 23:23:23 +0000 (00:23 +0100)
Functions can pick up the full array of arguments passed in using the "_args"
local variable. This is a hash with arguments stored indexed from "0" to "N".
The "count" entry in the _args hash contains the number of vars passed in.

src/plugins/splash/script/script-execute.c

index 9856b0ed161d036db601ec0ffa282d9ca21be4c6..4356a3df4541ddd78f7c74df884ab14455efc759 100644 (file)
@@ -464,17 +464,33 @@ static script_return_t script_execute_function_with_parlist (script_state_t    *
   ply_list_t *parameter_names = function->parameters;
   ply_list_node_t *node_name = ply_list_get_first_node (parameter_names);
   ply_list_node_t *node_data = ply_list_get_first_node (parameter_data);
-
-  while (node_name && node_data)
+  int index = 0;;
+  script_obj_t *arg_obj = script_obj_new_hash ();
+  
+  while (node_data)
     {
       script_obj_t *data_obj = ply_list_node_get_data (node_data);
-      char *name = ply_list_node_get_data (node_name);
+      char *name;
+      asprintf (&name, "%d", index);
+      index++;
+      script_obj_hash_add_element (arg_obj, data_obj, name);
+      free(name);
       
-      script_obj_hash_add_element (sub_state->local, data_obj, name);
-      node_name = ply_list_get_next_node (parameter_names, node_name);
+      if (node_name)
+        {
+          name = ply_list_node_get_data (node_name);
+          script_obj_hash_add_element (sub_state->local, data_obj, name);
+          node_name = ply_list_get_next_node (parameter_names, node_name);
+        }
       node_data = ply_list_get_next_node (parameter_data, node_data);
     }
 
+  script_obj_t *count_obj = script_obj_new_int (index);
+  script_obj_hash_add_element (arg_obj, count_obj, "count");
+  script_obj_hash_add_element (sub_state->local, arg_obj, "_args");
+  script_obj_unref (count_obj);
+  script_obj_unref (arg_obj);
+
   script_return_t reply;
   switch (function->type)
     {