Reputation: 366
Lua 5.2
I need to iterate an userdata
variable.
As I understand, I can do this using getmetatable
and __pairs
. Like this:
for k, v in getmetatable(userdataVariable).__pairs do
-- someting
end
But I get 'attempt to call a nil value' when I'm trying to do this.
I found a __pairs
implementation here: what is actual implementation of lua __pairs?
function meta.__pairs(t)
return function(t, k)
local v
repeat
k, v = next(t, k)
until k == nil or theseok(t, k, v)
return k, v
end, t, nil
end
But I don't understand what I should do with theseok
? What function should I define here?
Upvotes: 3
Views: 1038