lua-users home
lua-l archive

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


On 31/05/2012, at 4:00 PM, Miles Bader wrote:

> Something like type predicates would be much better.  So the trick is,
> assuming a standard set of type predicates, how do you extend them to
> work on user types?

Does the typeinfo function I suggested earlier count as a predicate?  You could call it "istype" if that helped: istype(obj).typename.  One feature of returning at table is that the return value of typeinfo can be cached:

local t = typeinfo(obj)

if t.string then
  ...
elseif t.number then
  ...
elseif t.mytype then
  ...
end