API functions like lua_getfield() respect proxies, so why not lua_next() as well?
Hrm. Maybe putting the table iteration hook in __pairs, rather than __next, is the better choice.
If lua_next() respected an iteration metamethod, then most C table iterations would pick up an extra O(n) overhead cost.
And __pairs also gives you the power to use a state variable other than the table itself, which can be handy.
I'd still like to have a version of next() available in Lua that respects proxy tables -- though that's easy enough to get:
function next(t,k)
local f,s = pairs(t)
return f(s,k)
end
One can use a similar trick at the API level to make a version of lua_next() that respects the __pairs metamethod -- but, there's enough extra overhead in each call that you probably want to be careful about just where you use it.