lua-users home
lua-l archive

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


Hello all,

I have the following lua statement
c=f:AddCombobox("test",{list={"one","two","three"}})
That I want to decode in C

for the first argument I have :
luaL_checkstring(L, 1)

for the second argument a use :

      GetTableField(L,"list",&contents);

which boils down to

  bool GetTableField(lua_State *L,const char *key,string  *field)
  {
      lua_pushstring(L,key);
      lua_gettable(L,-2);
      if (!lua_istable(L,-1))
      {
          lua_pop(L,1);
          return false;
      }
      if (field)
          *field = TableToXml(L);
      lua_pop(L,1);
      return true;
  }
so far so good
now I want to decode that table ({"one","two","three"})

and I use
  string & TableToXml(lua_State *L)
  {  static string ret;
     ret.clear();
     lua_pushnil(L);  /* first key */
     while (lua_next(L, -1) != 0)
     {
       ret += "<ITEM>";
       ret +=  luaL_checkstring(L, -1);
       ret += "</ITEM>";
lua_pop(L, 1); /* removes `value'; keeps `key' for next iteration */
     }
     return ret;
  }

but does not work, I have messed the stack somewhere, could someone help me ?
A pointer on stack manipulation function from C would be nice
Best regards

--
Noël Frankinet
Gistek Software SA
http://www.gistek.net