3
votes

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?

1
I don't think you need it, actually. And take a look here - Bartek Banachewicz

1 Answers

-1
votes

I think you're looking for the __index meta table.