lua-users home
lua-l archive

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


well that is one approach, yet, to make it generally useful it should work on all the common approaches I think.

(sorry for top-posting, client doesn't support it)

Geoff Leyland <geoff_leyland@fastmail.fm> wrote:

>On 24/10/2012, at 11: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 (plant -> flower -> tulip, does a tulip satisfy an argument
>> requiring a plant-type), maybe that requires an __istype() or similar
>> function as well.
>
>
>My take on this is [1]: 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...".
>
>(Having said that, I'm not sure that long inheritance chains are a symptom of good practice)
>
>
>[1] https://github.com/geoffleyland/rima/blob/master/lua/rima/lib/object.lua