Passing bytes from LUA to C

Hi all,

I’m trying to pass some information (BLOB in aerospike aka byte in a java client aka bytes in LUA) from a LUA filtering routine to a C function.

Unfortunately from C side I’m not able to access any kind of information (lua_isnumber, lua_isstring and lua_istable return false).

If I simply pass a byte (and NOT an array of byte) the information is retrieved correctly in the C routine.

Does somebody have any idea why this scenario is not working or does somebody have any pointer to the aerospike/lua documentation?

Thanks you soooo much!

My code is: From the Java Client I create a byte array of size = 6 and invoke a LUA routine called testingC in a prova2.lua file. I pass to LUA the byte

byte[] java_query_pool={13, 15, 11, 0, 99, 77};
rs =client.queryAggregate(null, stmt, "prova2", "testingC", Value.get(java_query_pool) );

in the LUA routine i can correctly retrieve the array of byte and I’m able to retrieve the size of the array and the contents of the array (i.e. I’m able to retrieve the 6-th data = 77)

local function myfilter1(pool_query)
  local fromlua=require("fromlua")     
  local sizee=bytes.size(pool_query)
  info (sizee)
  local unbyte=bytes.get_byte(pool_query,6)        
  info (unbyte)

If i pass the pool_query (bytes) to the C routine the data is not available on C side (is even not recognized like strin/number/table). If i pass the unbyte (simple one byte) to C, the data is correctly retrieved

WORKING SCENARIO:

From LUA

local return_value = fromlua.match(unbyte); 

to the C routine

static int match(lua_State * L) 
{
  int rtrn = lua_tonumber(L, -1);

NOT WORKING SCENARIO

from LUA

local return_value = fromlua.match(pool_query);

to C

static int match(lua_State * L) {
  syslog(LOG_INFO, "whattisit");
  if (lua_isnumber(L, -1)) {
    syslog(LOG_INFO, "iz a number");
  } 
  else if (lua_isstring(L, -1)) {
    syslog(LOG_INFO, "iz a string");
  } 
  else if (lua_istable(L, -1)) {
    syslog(LOG_INFO, "iz a table");
  }
  else syslog(LOG_INFO, "iz NONE"); <-- this is printed out
  const void *rtrn=lua_topointer(L, -1); <-- return pointer to ZERO
  //int rtrn = lua_tonumber(L, -1);  <-- return ZERO
  //const char *value = lua_tostring(L, -1); <-- return NULL

Any helps is more than appreciate! Thankssss

Hello community

seems the bytes from LUA are userdata in C:

lua_isuserdata(L, -1)

I suppose I’ve to use

const as_bytes *ud = lua_touserdata(L, -1);

to retrieve the data

I keep update when i will got a successful scenario

Hi all, I’m still having some issues trying to retrieve from the lua stack the array of byte (from c code).

Unfortunately if I try to

as_bytes *ud = lua_touserdata(L, -1);

the structure returned is not consistent (size 32562 instead of 7) and If i try to retrieve some data from it I receive a SIGSEGV.

I’ve been checked my code against the as_lua example (that is working with no major issue).

Does anybody of you has a working example passing Bytes from lua to as_byte in c? Thanksssss Angelo

PS: I’m wondering where can i find the aerospike source code that put on the stack the bytes structure so that i can track down what’s going on behind my source code

ok, i’ve figured out → again, my fault… i had to use

as_bytes * ud=mod_lua_tobytes(L, -1);

I leave the thread if anyone else will have the same problem