lua-users home
lua-l archive

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

On 1/06/2012, at 2:33 AM, Coda Highland wrote:

> On Thu, May 31, 2012 at 12:03 AM, Geoff Leyland <> wrote:
>> On 31/05/2012, at 4:52 PM, Coda Highland wrote:
>>> I'd like it better if it were, because then you're not
>>> using strings for type matching but instead confirming the actual type
>>> object.
>> What's your objection to strings?
> Namespace collisions

Good point.  I've only used this is in code I control, so that problem didn't come up.

> but why use strings when you don't have to?

Avoiding requiring modules.  If type A is defined in module A, and you want to check for it in module B, then you have to require module A in module B before you can typeinfo(obj)[A], but with strings you can do a typeinfo(obj).A without requiring anything.

As I said before, there's no problem putting metatables and/or strings in the typeinfo table for an object.