lua-users home
lua-l archive

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


Em 19 de jun de 2017 18:50, "Italo Maia" <italo.maia@gmail.com> escreveu:
(1) '5' + 5 gives you an 10.0 in the interactive console. Isn't this a weakly typed language behavior?
(2) '5' + 5 > 10.0, string plus integer equals float. If an error was throw here, it would be easier to understand than the given behavior.

Dear Italo,
This behavior is called String Coercion.

Lua performs automatic conversion of numbers to strings and vice versa where it is appropriate. This is called coercion.
> = "This is Lua version " .. 5.1 .. " we are using."
This is Lua version 5.1 we are using.
> = "Pi = " .. math.pi
Pi = 3.1415926535898
> = "Pi = " .. 3.1415927
Pi = 3.1415927

Jorge Eduardo de A. Oliveira
Computer Science Undergraduate Student