lua-users home
lua-l archive

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


The author of the os and io extensions in
    http://lua-users.org/wiki/ExtensionProposal
is criticized for polluting the standard namespaces.  Now I can see the
point in those cases, since the functions are never called object-ly,
but always os.foo or io.foo.

However: what about the case of string functions?  

For example, having been a Pascal programmer when there was not much
else to program in, I would love to write s[i] for s:sub(i,i).  
The closest I can get is to use LHF's tip and assign something to 
string metamethod __call so that s(i) means that.  Fooling around 
with __index scares me.

Or an iterator over string elements similar to table.pairs/ipairs:

    for i in s:chars() do -- etc

If I have to write 

    for i in myext.chars(s) do -- etc

the temptation is rather to pollute the global namespace:

    for i in chars(s) do -- etc

(Actually I rather like this: why must strings be less important
than tables?)

Dirk