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

equality check of python objects in lua #141

Open
mfrigerio17 opened this issue Jun 1, 2020 · 2 comments
Open

equality check of python objects in lua #141

mfrigerio17 opened this issue Jun 1, 2020 · 2 comments

Comments

@mfrigerio17
Copy link

Hi,
The following code fails with TypeError: __eq__() missing 1 required positional argument: 'rhs'

import lupa

lua = lupa.LuaRuntime(unpack_returned_tuples=True)

class foo: 
    def __init__(self): 
        self.a = 1 
    def __eq__(self, rhs): 
        return self.a==rhs.a
    def __hash__(self) :
        return hash(self.a)

f1 = foo()
f2 = foo()

lua.execute('f1 = python.eval("f1")')
lua.execute('f2 = python.eval("f2")')

print(f1==f2)                        # prints 'True' (correct)
lua.execute('print(f1==f2)')         # prints 'false' (wrong)
lua.execute('print(f1.__eq__(f2))')  # prints 'true' (correct)
lua.execute('print(f1.__eq__(f1))')  # fails

Is it a bug or am I missing something?
Python 3.8.2, Lupa 1.9
Thanks

@scoder
Copy link
Owner

scoder commented Jun 7, 2020

Yes, I think it makes sense to support this. However, we also have to make sure it produces something reasonable when comparing a Python object to a Lua object.

PR welcome that adds support for the Lua equality operator to Lupa wrapped Python objects, as well as a bunch of tests that show that the behaviour of different Python and Lua objects is "as expected", both left and right of the comparison operator.

@astoff
Copy link

astoff commented Oct 28, 2023

Should comparison of wrapped objects (both POBJECTs in Lua and Lua objects in Python) follow the host language semantics or the native language semantics?

I would say they should follow the native language semantics, so e.g. Python lists compare by value in Lua and Lua tables compare by identity in Python. See also #249.

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

3 participants