lua-users home
lua-l archive

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



19.02.2016, 13:08, "Luiz Henrique de Figueiredo" <lhf@tecgraf.puc-rio.br>:
>>  local cx = complex.new(0, 0)
>>  local cx2 = complex.new(1, 1)
>>  print(cx < cx2)
>>
>>  and the mesasge 'attempt to compare two userdata values'
>
> Indeed, my complex library does not set the __lt metamethod since I thought
> it made no sense.
>
> If you want better error message, do
>
> complex.__lt=function () error"complex numbers cannot be compared" end

You right, comlexes cannot be ordered, but a particular user may be confused by a strange message about mysterious 'userdata' while they work with complex numbers.