lua-users home
lua-l archive

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


Romulo Bahiense wrote:

Lee Smith wrote:

This fails:

 lua_newtable(L); // push 1

 lua_pushnumber(L,tableIndex); // push 1
 lua_newtable(L); // push 1

 lua_pushstring(L, "item1"); // push 1
 lua_pushstring(L, "value (item 2)"); // push 1
 lua_settable(L, -3); // pop 2

 lua_pushstring(L, "item2"); // push 1
 lua_pushstring(L, "value (item 2)"); // push 1
 lua_settable(L, -3); // pop 2

 lua_pushvalue(L, -1); // push 1
 lua_setglobal(L, "2ndtable"); // pop 1


You are missing a << lua_settable(L, -3) >> here.

 tableIndex++;
 lua_pushnumber(L, tableIndex);
 lua_newtable(L); // push 1

 lua_pushstring(L, "item3"); // push 1
 lua_pushstring(L, "value (item 3)"); // push 1
 lua_settable(L, -3); // pop 2

 lua_pushstring(L, "item4"); // push 1
 lua_pushstring(L, "value (item 4)"); // push 1
 lua_settable(L, -3); // pop 2

 lua_pushvalue(L, -1); // push 1
 lua_setglobal(L, "3rdtable"); // pop 1

 lua_settable(L, -3); // push 2
 lua_setglobal(L, "testtable");




Try to replace with this:

  /* ... */

  lua_pushvalue(L, -1); // push 1
  lua_setglobal(L, "2ndtable"); // pop 1

  lua_settable(L, -3);

  tableIndex++;
  lua_pushnumber(L, tableIndex);
  lua_newtable(L); // push 1

  /* ... */

--rb

Awesome, that worked splendidly. Thanks! Now I'm going to write some wrapper functions to hide all this from myself so I don't screw it up all over again :).