lua-users home
lua-l archive

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


On Dec 13, 2010, at 10:06 PM, Javier Guerra Giraldez wrote:

> (PS: to answer PA, that would break current  (''):find() usage )

Yes, yes... I know it's dumb... but since when are we in the business of preventing people from shooting themselves in the foot?!? :P

getmetatable( '' )[ '__call' ] = function( self, a, b ) return self:sub( a, b ) end
getmetatable( '' )[ '__index' ] = function( self, key ) if type( key ) == 'number' then return string.char( string.byte( self, key ) ) end return string[ key ] end

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

> 3	a
> 3	ab
> 3	ABC