lua-users home
lua-l archive

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


On Saturday 18 October 2008, David Manura wrote:
> In, say, Python, strings are thought of as immutable tuples of chars
> that can be indexed and sliced[4], so you have a notation like s[1],
> s[-1], s[1:4], and s[2:].  That notation does pose a bit of a
> challenge in Lua since s[i : f()] would normally be interpreted as a
> method call in Lua rather than a range.  Shmuel suggested s(i, j).
> Syntax I think is a secondary decision whose details can be worked out
> later.

i think a nice feature for 5.3 could be to allow more than one parameter as 
index: o[x,y,...] would be interpreted as getmetatable(o).__index(o,x,y,...)  
in the case of tables, only the first parameter would be used; but for 
user-defined access functions having more could be useful.

if that were possible, setting string.__index = string.sub would let you use 
s[i,j]  (but s[i] would return a suffix instead of a single char...)

-- 
Javier

Attachment: signature.asc
Description: This is a digitally signed message part.