Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__pairs metamethod is ignored when iterating Lua tables from Python #80

Open
immerrr opened this issue Aug 12, 2016 · 1 comment
Open

Comments

@immerrr
Copy link

immerrr commented Aug 12, 2016

Here's a simple example:

In [16]: copy, proxy = LuaRuntime().execute("""
obj = {foo=123, bar=345}

proxy = {}
setmetatable(proxy, {
  __index = function(self, key)
    return obj[key]
  end,

  __newindex = function(self, key, value)
    obj[key] = value
  end,

  __pairs = function(self)
    return pairs(obj)
  end,
})

copy = {}
for k,v in pairs(proxy) do
  copy[k] = v
end

return copy, proxy
""")

In [17]: copy['foo']
Out[17]: 123

In [18]: proxy['foo']
Out[18]: 123

In [19]: list(copy.items())
Out[19]: [(u'foo', 123), (u'bar', 345)]

In [20]: list(proxy.items())
Out[20]: []
@scoder
Copy link
Owner

scoder commented Aug 16, 2016

Pull request welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants