lua-users home
lua-l archive

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


On Wed, Apr 23, 2014 at 1:56 PM, Lukas Prokop <admin@lukas-prokop.at> wrote:
> 2014-04-23 11:53 GMT+02:00 Lukas Prokop <admin@lukas-prokop.at>:
>> Now my point is that we can use this as indices.
>
> I misunderstood your point. You mean indices for the string library,
> not indexing in a table. In that case, indices are converted to integers.
>
>     The Lua value must be an integer, or a number or string convertible
>     to an integer (see §3.4.3); otherwise, lua_tointegerx returns 0.
>
> Since infinity is not an integer, it is treated as 0.

Okay, thank you. So coming to the root of the problem, I guess there are 2
questions related to the same topic (which are partially answered by the
spec):

1. Shall inf, -inf and -nan be allowed as indices for strings?
2. Shall inf, -inf and -nan be numbers in general?
   [leading to a change in semantics of lua_tointegerx]

Why shall we discuss it? Because this is non-intuitive for me:

    > a = "hello world"
    > inf = 1/0
    > = a:sub(inf)
    hello world
    > = a:find("e", inf)
    2   2

I have to point out that languages like python do not support infinity as
indices as well. Any other pros/cons?

best regards,
meisterluk



It'd take more than a change in lua_tointegerx, because these values don't have integer representations. You'd need something like:
lua_isnan(L, n): returns true if the value at index n is NaN.
lua_isinfinity(L, n): returns 1 if the value at index n is infinity, -1 if the value is -infinity, and 0 otherwise.

--
Sent from my Game Boy.