Skip to content

equality check of python objects in lua #141

Open
@mfrigerio17

Description

@mfrigerio17

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions