lua-users home
lua-l archive

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


On 25/10/2012, at 9:37 AM, Thijs Schreijer <thijs@thijsschreijer.nl> wrote:

> Geoff Leyland <geoff_leyland@fastmail.fm> wrote:
> 

>> give the object's metatable a __typeinfo field that's a table that has fields that are true if the object is of that type, so, for if value is a tulip:
>> 
>> getmetatable(value).__typeinfo -> { table=true, plant=true, flower=true, tulip=true }
>> 
>> and there's a typeinfo function so you can check with "if typeinfo(value).flower then...".
> 
> well that is one approach, yet, to make it generally useful it should work on all the common approaches I think.

Sorry, to be clear: I use this method sometimes for objects with inheritance chains.

argcheck, on the other hand, tries any method I can think of to guess whether an object is a given type.  I haven't got to typex yet, and I haven't written a two-line "add_type_checker" yet, but I'm bumbling in that direction.