Create a table with table keys in Lua with the C API -
in lua, can create table keys tables:
t = {} t[{1,2}] = 2
i know how analogous thing using c api. is, writing c function callable lua, return table table keys. tried push table key , use lua_settable, seems nothing.
edit: relevant code:
lua_createtable(l, 0, n); for(i = 0; < n; ++i){ // push key table lua_createtable(l, 2, 0); for(j = 0; j < 2; ++j){ lua_pushinteger(l, j+1); lua_pushinteger(l, j); lua_settable(l, -3); } // push value table lua_createtable(l, 4, 0); for(j = 0; j < 4; ++j){ lua_pushinteger(l, j+1); lua_pushnumber(l, j); lua_settable(l, -3); } lua_settable(l, -3); }
edit: being dumb; used lua_objlen(l, -1)
@ end check on size of table, returns 0 since there no integer keyed entries. also, in lua code processed table, used ipairs
instead of pairs
. silly mistake.
pushing table key , using lua_settable right thing do. likely, forgot push on value , did t = { {} = nil }, of course nothing.
Comments
Post a Comment