lua-users home
lua-l archive

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

Aladdin Lampé wrote:

Indeed, the calculations (Lua scripts) are provided by the users of my application, and I don't feel like explaining in the documentation that it is forbidden to test whether 1 < decNumber.tonumber("1.5") and that what they should write instead is: decNumber.tonumber("1") < decNumber.tonumber("1.5")...

Users of my original integrated float/integer complained about the
same thing.

See my earlier post on implementing an automatic "cast" or conversion
from Lua_Number to your userdata type in the implementation of
comparison operators for your userdata.

Here's how it looks now in pbLua

f = nxt.float()   -- No parameters makes 0.0
i = 3
j = "5"

> =f<i
> =i<f
> j<i

The comparison will try to convert a number (or string if possible) to
a float before comparing with the float userdata.

You will run into a range issue at some point....