[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: how to prevent bugs without static type checking?
- From: Rob Hoelz <rob@...>
- Date: Wed, 24 Oct 2012 13:35:32 +0200
On 10/24/12 1:06 PM, steve donovan wrote:
> On Wed, Oct 24, 2012 at 12:50 PM, Thijs Schreijer
> <thijs@thijsschreijer.nl> wrote:
>> And a devil in the details of argument checking; should the MT chain be
>> traversed to see whether a subclass satisfies as a class higher up in the
>> hierarchy
> Ah, but again there are different ways to peel the avocado. An MT
> chain is one way, but I tend to use 'fat metatable inheritance' where
> the contents of the base class is copied into the new derived class,
> with a _base field pointing to the original base class. Faster method
> dispatch for the price of larger metatables - a good trade-off if the
> number of objects outnumbers the number of classes significantly.
>
>> maybe that requires an __istype() or similar function as well.
> That would be best, and would depend on the OOP scheme being used.
>
> steve d.
>
Just thought I'd chime in since lua-typical was mentioned; typical
currently works using the following algorithm:
- If __type is a valid metafield for the value and is a string, return
__type.
- If __type is a valid metafield for the value and is a function,
return __type(value).
- If io.type(value) returns a non-nil value, return io.type(value).
- Return type(value).
There's no reason that I couldn't incorporate Thijs' typex metatable
lookup logic into this; I just decided to do the minimum for
the first release.
-Rob