lupa icon indicating copy to clipboard operation
lupa copied to clipboard

Surprising table equality behavior

Open dubois opened this issue 11 years ago • 5 comments

import lupa r = lupa.LuaRuntime() r.globals().test == r.globals().test False

I can supply a patch that adds richcmp and hash to _LuaTable.

dubois avatar May 09 '13 05:05 dubois

Sounds like a good idea.

scoder avatar Jun 15 '13 11:06 scoder

I never got around to adding the patch :-P. Here it is! https://gist.github.com/dubois/9478877

dubois avatar Mar 11 '14 03:03 dubois

Thanks. A couple of comments:

  • looks very good functionality wise
  • lacks tests
  • I prefer pull requests :)
  • "richcmp()" is bidirectional, so you can't be sure the first argument is "self", it might be the second (which is, I guess, why you thought you'd have to type the first argument explicitly)
  • "uintptr_t" appears to be C99. Not sure I want to require that. There's also the "stdint.h not in MSVC" issue. Tricky ground.
  • the comparison operators should use the CPython constants (from cpython.object cimport Py_EQ, ...), not plain integers. There's also no need to explicitly return True/False, just return the comparison result.
  • there's a special type "Py_hash_t" that Cython defines as return value of "hash()" (and that it backports for Py<3.2)

scoder avatar Mar 11 '14 07:03 scoder

I'm pretty sure this occurs with all _LuaObject, since I've experienced this with _LuaFunction too

SoulSen avatar Aug 22 '20 06:08 SoulSen

Don't know why this was closed. Doesn't look like it's resolved. PR welcome, as described above.

scoder avatar Aug 22 '20 06:08 scoder