lua-users home
lua-l archive

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


On Tue, May 5, 2015 at 12:00 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> Well, tables are mutable, so having metatables attached on an
>> instance of a table makes sense. String are immutable, so I don't
>> see the point for them...
>
> More to the point, strings have no notion of "self", or of being
> created.  If you run "a".."bc" twice, do you create two different
> strings (with two different metatables) or only one? Are they the
> same as "abc"?  Does that depend on whether there is a GC between the
> execution of those expressions? However you answer those questions,
> there will be a lot of drawbacks.
>
> -- Roberto
>

That's a very good point that I hadn't even considered before. If you
start attaching unique metatables to strings, then suddenly two
"identical" strings might not be identical anymore.

It seems like what OP really wants is objects that act as special
types of strings, which is already doable with a table containing a
string.

-- 
Sent from my Game Boy.