[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: upcoming changes in Lua 5.2
- From: Miles Bader <miles@...>
- Date: Wed, 20 Feb 2008 08:42:32 +0900
Miles Bader <miles@gnu.org> writes:
> E.g., callable(...), indexable(...) etc.
>
> Maybe a single general predicate would work, e.g., something like
> "applicable (OBJ, KEY)" where KEY is the assocated metamethod ('__call',
> '__index', etc).
Here's an example:
local applicable_prims = {
__call = 'function', __index = 'table', __newindex = 'table',
__add = 'number',
-- ...etc...
}
function applicable (obj, key)
if applicable_prims[key] == type (obj) then
return true
else
local mt = getmetatable (obj)
return mt and mt[key]
end
end
-miles
--
"Don't just question authority,
Don't forget to question me."
-- Jello Biafra