lua-users home
lua-l archive

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


2016-06-25 4:38 GMT+02:00 Duane Leslie <parakleta@darkreality.org>:

> I know I can trivially monkey-patch `math.tointeger` to run its
> arguments through `tonumber` first, but should `math.tointeger` also
> explicitly convert strings to integers where possible?

In general, only arithmetic operators do that, and only concat
converts from number to string. For example, you can't get away
with

    n = input_line:match"%d+"
    for i=1,n do
    ...

or with

    n = tonumber(input_line)
    if #n>8 then
    ...