[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LUA Vs Javascript
- From: Petite Abeille <petite_abeille@...>
- Date: Sat, 28 Jun 2008 10:10:54 +0200
On Jun 28, 2008, at 4:04 AM, Patrick Donnelly wrote:
Implementing a type method for all classes seems like a sane solution
to this problem.
One way to look at this is to leverage Lua's module _NAME:
http://www.lua.org/manual/5.1/manual.html#5.3
Define your classes as module and query their _NAME attribute:
local function Type( anObject )
if type( anObject ) == 'table' then
return anObject._NAME or ( getmetatable( anObject ) or
{} )._NAME
end
return type( anObject )
end
http://dev.alt.textdrive.com/browser/HTTP/HTTPExtra.lua#L528
Additionally, one can systematically define a meaningful __tostring
metamethod:
function meta:__tostring()
return ( '%s/%s' ):format( self._NAME, self._VERSION )
end
"Lua gives you the power; you build the mechanisms."
-- Roberto Ierusalimschy, Programming in Lua, December 2003
--
PA.
http://alt.textdrive.com/nanoki/