lua-users home
lua-l archive

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


Both arguments have the sa[nm]e meaning: the sign serves only to
identify the direction (like in physics); in practice you don't want
to use 0.

And since

s:sub(0,#s) == s:sub(1,#s) and (''):sub(n,0) == '', for any string s
and any integer n

and

> =("12345"):sub(1,2.5)
12
> =("12345"):sub(1,2.6)
123

I suppose it would be better all around if string.sub only accepted
non-null integers as indices

On 3/6/10, Scott Vokes <vokes.s@gmail.com> wrote:
>> Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
>>> =("12345"):sub(1,0)
>    The reference manual says (pg. 74 /
> http://www.lua.org/manual/5.1/manual.html#5.4):
> "Indices are allowed to be negative and are interpreted as indexing
> backwards, from the end of the string. Thus, the last character is at
> position -1, and so on." To me, that means sub(1, 0) should return the
> string between the first character and the last character, i.e., the
> empty string.
>
> Scott
>