lua-users home
lua-l archive

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


Negative indexes are okay for the simple case, but when working with two
or three tables, they are a pain.  I'll just use my own macro:

#define lua_nice_newtable(L) (lua_newtable(L), lua_gettop(L))

for example:

int lua_odbclibopen(lua_State *L)
{
  int metatable, methods;

  {metatable = lua_nice_newtable(L);
   set_method(L, "gc", dbc_gcmethod);

   {methods = lua_nice_newtable(L);
    set_closure(L, "Execute",    sql_execute,     metatable);
    set_closure(L, "TableList",  sql_table_list,  metatable);
    set_closure(L, "Close",      dbc_close,       metatable);

    {lua_pushvalue(L, LUA_GLOBALSINDEX);
     set_closure(L, "DBConnect", dbc_connect, metatable);

     {lua_pushstring(L, "gettable");
      lua_pushvalue(L, methods);
      lua_settable(L, metatable);}

     lua_pop(L, 3);}}}
}

- Peter