lua-users home
lua-l archive

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



On May 30, 2006, at 08:09, google wrote:

Now,according to the reference manual,the somedata is a table.
But really it is a userdata. Is there something Wrong?

It's a bit more exotic then that as any object can have a metatable associated with it:

local aString = "abcd"
local aFunction = aString[ "upper" ]

print( aFunction( aString ) )
-- or print( aString.upper( aString ) )
-- or print( aString:upper() )

> ABCD

local aNil = nil

debug.setmetatable( aNil, { __index = { toString = function( aValue ) return tostring( aValue ):upper() end } } )

print( aNil:toString() )

> NIL

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/