lua-users home
lua-l archive

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


>The first is that lua_getn() has gone away -- what's the proper
>replacement?

Just found Peter Shook's reply about this in the archives (couldn't 
find anything on lua_getglobals though).  Does this code snippet 
remain valid for Lua5?

static int my_getn(lua_State *L, int index)
{
  int n;
  luaL_checktype(L, index, LUA_TTABLE);  /* is it a table? */
  lua_pushliteral(L, "table");
  lua_gettable(L, LUA_GLOBALSINDEX);
  lua_pushliteral(L, "getn");
  lua_gettable(L, -2);
  lua_pushvalue(L, index);
  lua_call(L, 1, 1);  /* call table.getn(t) */
  n = lua_tonumber(L, -1);
  lua_pop(L, 2);
  return n;
}