Skip to content

Surprising is behaviour #71

@rakiru

Description

@rakiru

Currently, a new _LuaTable python object is created every time a Lua table is access from Python. This causes a case where the table appears to not be itself:

>>> import lupa
>>> lua = lupa.LuaRuntime()
>>> lua.execute("foo = {}")
>>> f = lua.globals().foo
>>> g = lua.globals().foo
>>> f is g
False
>>> f
<Lua table at 0x0000000000327C18>
>>> g
<Lua table at 0x0000000000327C18>

The repr makes it especially confusing, since it shows the address of the underlying Lua object.

My suggestion would be to use a weakref cache when creating the objects, either in py_from_lua or the new_lua_* functions. I don't imagine this would greatly affect performance for cache misses, and in addition to fixing the identity issue, should cut down on some garbage.

I'm not actually able to compile lupa on my current machine, and I don't have much experience with Cython, but I can attempt a patch for this if I get the go-ahead.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions