lua-users home
lua-l archive

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

Miles Bader <> 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
         local mt = getmetatable (obj)
         return mt and mt[key]


"Don't just question authority,
Don't forget to question me."
-- Jello Biafra