Avoid __pairs metamethod in stdnse.keys

This allows stdnse.keys to be used in a __pairs metamethod to, for
instance, yield keys in sorted order. Using next() bypasses the __pairs
metamethod that would be called when pairs() was used. Otherwise,
infinite recursion was possible.
This commit is contained in:
dmiller 2014-09-23 05:23:06 +00:00
parent 4312ef5133
commit 379759d539

View file

@ -1416,8 +1416,10 @@ end
-- @return A table of keys
function keys(t)
local ret = {}
for k, _ in pairs(t) do
local k, v = next(t)
while k do
ret[#ret+1] = k
k, v = next(t, k)
end
return ret
end