From 66a08965c61647a915ad839164e1db488f755dac Mon Sep 17 00:00:00 2001 From: Charlie Brej Date: Thu, 9 Jul 2009 00:23:23 +0100 Subject: [PATCH] [script] Add support for variable number of arguments 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 | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/plugins/splash/script/script-execute.c b/src/plugins/splash/script/script-execute.c index 9856b0ed..4356a3df 100644 --- a/src/plugins/splash/script/script-execute.c +++ b/src/plugins/splash/script/script-execute.c @@ -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) { -- 2.47.3