lua-users home
lua-l archive

Re: Metamethods: fallbacks or overrides?

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


On 17/08/14 05:17 PM, Philipp Janda wrote:
Am 17.08.2014 um 20:22 schrieb Thiago L.:
On 17/08/14 03:09 PM, Philipp Janda wrote:
Don't forget:
__tostring
I thought __tostring was a fallback... (Lua doesn't know what to do, but
instead of throwing an error it returns the memory address or a hash or
w/e)
 debug.setmetatable( 1, {
 __tostring = function( v ) return "X"..v.."X" end
 } )
 print( 1, 2, 3 )
==>
 X1X X2X X3X
Or my favourite:
 debug.setmetatable( "", {
 __tostring = function( v ) return "bye bye" end
 } )
 print( "hello world" )
==>
 bye bye
Philipp
Ouch... and we don't have a rawtostring()...
Sometimes I don't know what's wrong with ppl... this is one of them...

AltStyle によって変換されたページ (->オリジナル) /