Page 1 of 1

Passing Multiple Arrays (tables) From C to Lua

PostPosted: Tue Apr 12, 2016 12:52 pm
by Kyle.Gilbertson
I have a C function that returns two lists to Lua like this:

lua_checkstack(L, m); // where m is the combined size of the two arrays
lua_newtable(L);
for (i=1; i <= idx1; i++) {
lua_pushnumber(L, List1[i - 1]);
lua_rawseti(L, -2, i);
}
lua_newtable(L);
for (j=1; j <= idx2; j++) {
lua_pushnumber(L, List2[j - 1]);
lua_rawseti(L, -2, j);
}
return 2;

It seems to work, but not always. Is something missing here? This is what the call looks like in Lua:
List1, List2 = Cfunction(source, period);

It seems like List2 always gets populated, but List1 doesn't. Is there a better way to do this?