lua-users home
lua-l archive

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


> Behalf Of steve donovan
> Sent: woensdag 24 oktober 2012 12:15
> Subject: Re: how to prevent bugs without static type checking?
> 
> On Wed, Oct 24, 2012 at 11:43 AM, Thijs Schreijer
<thijs@thijsschreijer.nl>
> wrote:
> > If the "typical" library by Rob Hoelz can be combined with my "typex"
> > library, then that could pretty much fill this gap.
> 
> I'd like to harmoize Penlight with this, and fill in MT.__type.
> Standards are a good thing!
> 
> However, is the idea that __type (or tostring(__type)) should always
resolve
> to a sensible name for a type?

Yes, fallback it the lua-type. That is for userdata's and tables. If there
is a __type or similar (whatever the convention) value or function (for
tables also in the table itself, not just the metatable), then use that
If not, then a table is just a table, but for userdata's, collect the
metatable name from the registry, and report that (if not found, a userdata
is also just a userdata)

That would be the most complete approach I think.

Just a definition would be required on what names to look for; __type, or
.class(), .superclass(), etc.
And some standard preprocessor symbols

Thijs

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 (plant -> flower -> tulip, does a tulip satisfy an argument
requiring a plant-type), maybe that requires an __istype() or similar
function as well.