lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

For some time, i couldn't accessing datas from a table i send to a C function.

I was accessing table members like this:

char *params[]={"rotx","roty","rotz","posx","posy","posz",
                "md2_id","current_anim","current_frame",0};
  int nb_params=(sizeof(params)/sizeof(char*))-1;
  for (int i=0; params[i]; i++) {
    lua_getfield(L,1,params[i]);
  }

You can see that the extracted parameters are all pushed (they are put into C vars after the loop. And yes, i check if there's enough room on the stack before doing it).

The problem was that nothing was retrieved.
So i've dumped the lua stack, at the very beginning of my C function.

 ** STACK DUMP (top: 2) **
  type [table] unknown @ 1 <- ??? unknown table
  type [table] unknown @ 2 <- my table

Seeing that, i just changed the stack index in "lua_getfield" to "2".
Ok, it works.

Now, my question is : what is exactly this table ? Does it contain interesting things, or raise it no point for an average programmer like me ?

I tried a google search with "c environment lua table" (and some minor variations), with no luck.

Thank you.