I use Lua for arrays manipulating; arrays are simple binary data:
local ram_ctx = {0,0,0,0,0,0,0,0,0}
I want to pass it to GUI written in C. The problem is if I pass it directly like func(ram_ctx), Lua function seems to stop executing after a call. Corresponding C function are not executed (it can be empty). But if I make global array in Lua and access it with lua_getglobal - everything seems to be OK. What I'm doing wrong or is it possible at all? It is not OK to pass array name as argument in order to call it as global array
Lua code:
function device_init()
--set_callback(1000000000000, 0)
local array = {0xFF,0,0,0,0,0,0}
--create_memory_popup("Test")
set_memory_popup(array)
end
Here is C code I try to use:
static int32_t lua_set_popup_memory (lua_State *L)
{
int32_t argnum = lua_gettop(L);
if (1 != argnum)
{
out_error("Function %s expects 1 argument got %d\n", __PRETTY_FUNCTION__, argnum);
return 0;
}
if (0 == lua_istable(L, -1))
{
out_log("No array found");
return 0;
}
int32_t a_size = lua_rawlen(L, -1);
uint8_t *buf = calloc(1, a_size);
for (int i=1;;i++)
{
lua_rawgeti(L,-1, i);
if (lua_isnil(L,-1))
break;
buf[i] = lua_tonumber(L,-1);
lua_pop(L, 1);
}
set_popup_memory(memory_popup, 0, buf, a_size);
free(buf);
return 0;
}