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

           lvl = GLevels:NewDbLevel("truc",{{test,text},{deux,integer}} )

GLevels is luna Object
the second argument (table of table) defines a future sql statement to create a table
I have problem to decode the table of table part in c++ :

its start here :
-------------
   //we test if we have a table
    if (lua_istable(L,-1))
    {
        DecodeTable(L,dbview);
    }


The Decode Table function is :
------------------------------

 void DecodeTable(lua_State *L,Cdbview &dbview )
 {
lua_pushnil(L); while (lua_next(L,-2) != 0) {
       if lua_istable(L,-1)
           DecodeField(L,dbview);
lua_pop(L, 1); } lua_pop(L, 1); }


and the decode field function is :
------------------------------

 void DecodeField(lua_State *L,Cdbview &dbview )
 {
lua_pushnil(L); string name;
      string type;
      int t(0);
      while (lua_next(L, -2) != 0) {
       switch(t)
       {case 0 : name = luaL_checkstring(L, -1); break;
        case 1 : type = luaL_checkstring(L, -1); break;
        case 2 : break;// constraint -- TODO
       }
       t++;
lua_pop(L, 1); }
      if (t>1)
      {
       Cdbcolumn c(name);
       c.type_name(type.c_str());
       dbview.add(c);
      }
lua_pop(L, 1); }


The stack gets corrupted in the DecodeField function, and I get I have lost track of the lua stack state.
Could you help, please.

Thank you

Noël Frankinet