lua-users home
lua-l archive

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

Quae Quack wrote:
> I urge you to consider my proposal for __next (see mailing list post
> with subject " __pairs isn't what we need" )
> If you are against a __next though, a way for C to respect proxy tables
> is very much required. Not sure how you would solve this, as there is no
> lua_pairs...

// S> table
lua_getfield(L, LUA_ENVIRONINDEX, "pairs");
lua_insert(L, -2);
lua_call(L, 1, 3);
// S> key table iterator
int iter = lua_gettop(L);
do {
  lua_pushvalue(L, iter-2);
  lua_pushvalue(L, iter-1);
  lua_pushvalue(L, iter);
  lua_call(L, 2, LUA_MULTRET);
  if (lua_isnil(L, -1)) break;
  lua_copy(L, -1, iter);
  // ... do stuff
  lua_settop(L, iter);
} while (1);
lua_settop(L, iter-3);

Or something like that.

- tom