lua-users home
lua-l archive

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

On 2019-10-07, Roberto Ierusalimschy wrote:
Is there a plan to make LUA_NOCVTN2S and LUA_NOCVTS2N the default, i.e.
no implicit conversion between numbers/strings?

No (at least for now).

That is fine.

There may still be a need to conditionally compile stringmetamethods
with LUA_NOCVTN2S or another macro. See my previous reply.

The incompatibility is introduced in 5.4 . If this is conditioned in
this release, users who define LUA_NOCVTN2S will not see another
incompatibility in this regard when LUA_NOCVTN2S ever becomes the

> 8.1 – Incompatibilities in the Language
> * The coercion of strings to numbers in arithmetic and bitwise operations
>   has been removed from the core language. The string library does a
>   similar job for arithmetic (but not for bitwise) operations using the
>   string metamethods. However, unlike in previous versions, the new
>   implementation preserves the implicit type of the numeral in the string.
>   For instance, the result of "1" + "2" now is an integer, not a float.

There may be a need to turn off implicit string to number conversion for
this case as well. The behavior corresponds to lstrlib.c stringmetamethods.

  > getmetatable''.__add
  function: 0x55da4540e5dd
  > '3'+'a'
  stdin:1: attempt to add a 'string' with a 'string' # expected
  > '3'+'4'
  7  # unexpected