lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Op So. 24 Feb. 2019 om 10:49 het 奥斯陆君王 <qtiuto@gmail.com> geskryf:
>
> I think the following two statement should be equal
> 1.    v>= 1 and v <= 1
> 2.    v== 1

I disagree. It is a fundamental principle of Lua that values of
different types are not equal.

But let's read a little further.

> Howerver, they may produce two different result for a userdata or a
> table that override the metamethod correctly(ignore the bad cases).
> Provide a way to let them result both true?
> For compatiblity, other than allow it for __eq metamethod, a better
> way will be add a new metamethod entry like __peq (equal to primitive
> type).
>
> I got the idea when I found out there is no way to make
> ffi.new('int',1)==1 for standard lua. I think you may advise me to add
> a method like ffi.equals or patch the vm by myself(patch every
> version? a diff file?).

I do advise you to add a method, not an equals method, but a cast
method, so that v:cast(1) returns
a value of the same type (and subtype, if applicable) as v, and then
you can cleanly test for v==v:cast(1).
If you are a keystroke saver, make cast your __call metamethod, and
test for v==v(1).

> All of them are possible ways. But if lua
> does support it, it will be less time-consuming to port luajit codes
> to lua since luajit seems dying.

Stagnating, maybe. Not dying. The source code is still being included
in its entirety in numerous active projects.