3

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?

Community
  • 1
  • 1
user64675
  • 482
  • 7
  • 25

1 Answers1

-1

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

max1220
  • 44
  • 5