lua-users home
lua-l archive

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


On Dec 13, 2010, at 10:27 PM, Jonathan Castello wrote:

> If you're going to use __call, why not drop __index altogether? I
> don't really like having two different syntaxes for what's arguably
> the same operation.

As you wish :P

getmetatable( '' )[ '__call' ] = function( self, a, b ) return self:sub( a, b or a ) end


print( #aString, aString( 1 ) )
print( #aString, aString( 1, 2 ) )
print( #aString, aString:upper() )

> 3	a
> 3	ab
> 3	ABC