# Issue passing array to UDF function using "C" Client

**URL:** <https://discuss.aerospike.com/t/issue-passing-array-to-udf-function-using-c-client/4432>\
**Category:** User Defined Functions (UDF)\
**Tags:** udf\
**Created:** [July 27, 2017, 6:39am UTC](https://discuss.aerospike.com/t/issue-passing-array-to-udf-function-using-c-client/4432 "2017-07-27T06:39:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thube\_rahul](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@thube\_rahul](https://discuss.aerospike.com/u/thube_rahul)\
**Post date:** [July 27, 2017, 6:39am UTC](https://discuss.aerospike.com/t/issue-passing-array-to-udf-function-using-c-client/4432/1 "2017-07-27T06:39:48Z")

</div>

hi there,

I am having issues accessing array values in UDF function, using C as client.

I have a UDF function to update bins using input array, which is working fine from AQL. The issue here is, i am unable to access array values in UDF function.

Below is the sample C code, please let me know if i missing something while passing the arguments. // **C Code** \*\*\*\*\*\*\*\*\*\* as\_arraylist args; as\_arraylist\_inita(&args, 1);

```
   char *name_token[3] = {"email","rt@gmail.com","T"};
   as_arraylist_append_str(&args,*name_token);
   //as_arraylist_append_str(&args,name_token);
    
   as_val * p_return_val = NULL;
   if (aerospike_key_apply(as_ptr, &err, NULL, &key, "common_lua_functions", "mul_bin_update",(as_list*)&args, &p_return_val) != AEROSPIKE_OK) 
     {
      return("UDF Normal bin apply failed");
     }

```

//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

---

<div class="post-metadata">

**Author:** ![thube\_rahul](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@thube\_rahul](https://discuss.aerospike.com/u/thube_rahul)\
**Post date:** [July 31, 2017, 4:15am UTC](https://discuss.aerospike.com/t/issue-passing-array-to-udf-function-using-c-client/4432/2 "2017-07-31T04:15:21Z")

</div>

Hi guys,

I am still stuck with this issue. Any hint for this issue will be very much helpful.

---

<div class="post-metadata">

**Author:** ![thube\_rahul](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@thube\_rahul](https://discuss.aerospike.com/u/thube_rahul)\
**Post date:** [August 4, 2017, 6:03am UTC](https://discuss.aerospike.com/t/issue-passing-array-to-udf-function-using-c-client/4432/3 "2017-08-04T06:03:30Z")

</div>

Hi Experts,

I have created a record UDF, using two dimensional array as input parameter.

I am able to successfully test the UDF using AQL + JSON combination.

However, when I am testing it using ‘C’ code, the UDF misbehaves. Tried with couple of approaches:

1. Took 3 list of integer elements, ‘append’ it to the final list (having 3 elements) – works well
2. When we try to make it generic using a list with N element (instead of fixed number of element, i.e. 3), it only stores the first appended value. Simply ignoring all subsequent list append requests.

Following code snippet describes the same.

```
My expected output is : [[2, 3, 4], [3, 4, 5], [4, 5, 6]]

```

Appreciate your expertise to pass two (and multi) dimensional array to a ‘LUA’ function using ‘C’

//======== LUA function

```
function mul_bin_update(rec, arr_values)   
local arr_val = {}  
arr_val = arr_values  
local listContent,result  
info("mylog %s", tostring(rec))  
info("mylog %s", tostring(arr_val))   
end

```

//======== C Code for Approach - 1

```
    as_arraylist args1;
    as_arraylist args2;
    as_arraylist args3;
    as_arraylist args_c;
    as_arraylist args;
   
    as_arraylist_inita(&args1,3);
    as_arraylist_inita(&args2,3);
    as_arraylist_inita(&args3,3);
    as_arraylist_inita(&args_c,3);
    as_arraylist_inita(&args,1);
    
	as_arraylist_append_int64(&args1,2);
    as_arraylist_append_int64(&args1,3);
    as_arraylist_append_int64(&args1,4);
   
    as_arraylist_append_int64(&args2,3);
    as_arraylist_append_int64(&args2,4);
    as_arraylist_append_int64(&args2,5);
    
    as_arraylist_append_int64(&args3,4);
    as_arraylist_append_int64(&args3,5);
    as_arraylist_append_int64(&args3,6);
    
    as_arraylist_append_list(&args_c,&args1);
    as_arraylist_append_list(&args_c,&args2);
    as_arraylist_append_list(&args_c,&args3);
    
    as_arraylist_append_list(&args,&args_c);
    
      as_val * p_return_val = NULL;
      if (aerospike_key_apply(&as, &err, NULL, &key, "common_lua_functions", "mul_bin_update",(as_list*)&args, &p_return_val) != AEROSPIKE_OK) 
       {
             LOG("aerospike_key_apply() returned %d - %s", err.code, err.message);
       }

```

//======== C Code for Approach - 2

```
	int size=3;
    as_arraylist args1;
    as_arraylist args_c;
    as_arraylist args;
    
    as_arraylist_inita(&args1,size);
    as_arraylist_inita(&args_c,size);
    as_arraylist_inita(&args,1);

    for (i = 1 ; i <= size ; i++)
    {       
         as_arraylist_append_int64(&args1,1+i);
         as_arraylist_append_int64(&args1,2+i);
         as_arraylist_append_int64(&args1,3+i);

         as_arraylist_append_list(&args_c,&args1);
    } 
    
     as_arraylist_append_list(&args,&args_c);

     as_val * p_return_val = NULL;
     if (aerospike_key_apply(&as, &err, NULL, &key, "common_lua_functions", "mul_bin_update",(as_list*)&args, &p_return_val) != AEROSPIKE_OK) 
      {
            LOG("aerospike_key_apply() returned %d - %s", err.code, err.message);
      }

```
