lua-users home
lua-l archive

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


On Wed, May 30, 2012 at 11:42 PM, Geoff Leyland
<geoff_leyland@fastmail.fm> wrote:
> On 31/05/2012, at 4:00 PM, Miles Bader wrote:
>
>> Something like type predicates would be much better.  So the trick is,
>> assuming a standard set of type predicates, how do you extend them to
>> work on user types?
>
> Does the typeinfo function I suggested earlier count as a predicate?  You could call it "istype" if that helped: istype(obj).typename.  One feature of returning at table is that the return value of typeinfo can be cached:
>
> local t = typeinfo(obj)
>
> if t.string then
>  ...
> elseif t.number then
>  ...
> elseif t.mytype then
>  ...
> end

I'd like it better if it were t.is(string), because then you're not
using strings for type matching but instead confirming the actual type
object.

/s/ Adam