# Arglist to a lua function

**URL:** <https://discuss.aerospike.com/t/arglist-to-a-lua-function/1133>\
**Category:** C Client Library\
**Created:** [April 3, 2015, 8:05pm UTC](https://discuss.aerospike.com/t/arglist-to-a-lua-function/1133 "2015-04-03T20:05:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaylucas](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@jaylucas](https://discuss.aerospike.com/u/jaylucas)\
**Post date:** [April 3, 2015, 8:05pm UTC](https://discuss.aerospike.com/t/arglist-to-a-lua-function/1133/1 "2015-04-03T20:05:02Z")

</div>

My issue is passing arguments to a lua function via the aerospike-c-client. I have to do a multi where query and have the first where clause defined by:

```
as_query query;
as_query_init(&query, asNamespace, asSet);
as_query_where_inita(&query, 1);
as_query_where(&query, binName, as_string_equals(where_val));

```

Now the issue is passing the second where value to lua so lua can do more filtering

```
as_arraylist arglist;
as_arraylist_inita(&arglist, 1);
as_arraylist_append_string(&arglist, "Id");
as_arraylist_append(&arglist, (as_val *) where_val2);

as_query_apply(&query, UDF_MODULE, lua_function, &arglist);
if (aerospike_query_foreach(&as, &err, NULL, &query, query_cb_map, NULL) != AEROSPIKE_OK { ...

```

I have a lua function defined as:

```
function luaFunction(stream, id)
  local function filterId(record)
     if record.Id == id then
        return record
     end
  end
  return stream : filter(filterId) : map(mapUser)
end

```

Unfortunately the lua function doesn’t receive the id field. If I do a static id for testing it works as it should. For example:

```
if record.Id == "1234" then
   return record
end

```

How can I get the lua function take the correct argments from the client-c-library?

---

<div class="post-metadata">

**Author:** ![wchu](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@wchu](https://discuss.aerospike.com/u/wchu)\
**Post date:** [April 3, 2015, 11:01pm UTC](https://discuss.aerospike.com/t/arglist-to-a-lua-function/1133/2 "2015-04-03T23:01:09Z")

</div>

instead of filterSegment, do you mean to have filterId?

See: [https://github.com/aerospike/query-with-filters/blob/master/udf/profile.lua](https://github.com/aerospike/query-with-filters/blob/master/udf/profile.lua)

---

<div class="post-metadata">

**Author:** ![jaylucas](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@jaylucas](https://discuss.aerospike.com/u/jaylucas)\
**Post date:** [April 3, 2015, 11:30pm UTC](https://discuss.aerospike.com/t/arglist-to-a-lua-function/1133/3 "2015-04-03T23:30:05Z")

</div>

Sorry just a simple typo.

And I did see that, that is what I based my code off of. The problem is that the c code that is calling it does not give it the id field properly (Or in the case of that example the password). I am having issues on how (on the c side) to give the string to lua.

This question could also be tied into my other post

---

<div class="post-metadata">

**Author:** ![Mnemaudsyne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/mnemaudsyne/32/200_2.png) [@Mnemaudsyne](https://discuss.aerospike.com/u/Mnemaudsyne)\
**Post date:** [April 30, 2015, 9:06am UTC](https://discuss.aerospike.com/t/arglist-to-a-lua-function/1133/4 "2015-04-30T09:06:04Z")

</div>

Tying this question to the jaylucas’ other post …

> [@Multiple "where" clause query](https://discuss.aerospike.com/t/multiple-where-clause-query/1130):
>
> I don’t know if I am reading the documentation incorrectly but is it possible to have multiple where statements in a query? Basically as\_query\_where(&query, "bin1", as\_string\_equals("somestring")); //and as\_query\_where(&query, "bin2", as\_string\_equals("anotherstring"));
