Read Lua table from C -



Read Lua table from C -

i'm trying pass lua table c programme don´t know how it.

my lua code:

local stages = {} stages[1] = stage1 stages[2] = stage2 stages[3] = stage3 lstage.buildpollingtable(stages)

my c code:

static int lstage_build_polling_table (lua_state * l) { lual_checktype(l, 1, lua_ttable); lua_getfield(l, 1, "stage1"); lua_getfield(l, 1, "stage2"); lua_getfield(l, 1, "stage3"); stage_t s1 = lstage_tostage(l, -3); stage_t s2 = lstage_tostage(l, -2); stage_t s3 = lstage_tostage(l, -1); printf("%d\n",s1->priority); printf("%d\n",s2->priority); printf("%d\n",s3->priority); homecoming 1; }

what have run on elements? code generates error this:

bad argument #-3 'buildpollingtable' (lstage-stage * expected, got table)

can explain doing wrong?

your table have fields named stage1, etc., fields 1, 2, 3. seek

lua_rawgeti(l,1,1); lua_rawgeti(l,1,2); lua_rawgeti(l,1,3);

instead of

lua_getfield(l, 1, "stage1"); lua_getfield(l, 1, "stage2"); lua_getfield(l, 1, "stage3");

c lua lua-table lua-api

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -