[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: how to prevent bugs without static type checking?
- From: Geoff Leyland <geoff_leyland@...>
- Date: Thu, 25 Oct 2012 10:17:13 +1300
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.