lua-users home
lua-l archive

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


> On Thu, Nov 28, 2019 at 1:28 PM Robert Virding wrote:
> 
> > So in some case a string integer becomes a float:
> >
> > > "123" + 1
> > 124.0
> > > math.abs("123")
> > 123.0
> >
> > while in some other cases no conversion is done:
> >
> > > math.max("123", -2.3, 1)
> > attempt to compare string with number
> >
> >
> 
> BTW, I've asked similar question about S2N-conversion anarchy in Lua
> See question #5 in my post
> http://lua-users.org/lists/lua-l/2019-02/msg00049.html

As you said in your message, "using [S2N-coercion] is considered a bad
practice". Currently, they exist in Lua for compatibility only. The
trend is to remove them in the future. (Lua 5.4 already removed them
from bitwise operators, which themselves are somewhat new, and it
moved the arithmetic coercions from the core to a library.)

So, the rule is: when in doubt, don't use it. We will try to convey
that in the manual.

-- Roberto