[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A guide to building Lua modules
- From: Dirk Laurie <dirk.laurie@...>
- Date: Wed, 16 Apr 2014 10:23:29 +0200
2014-04-16 9:34 GMT+02:00 Aapo Talvensaari <aapo.talvensaari@gmail.com>:
>> the string table is global and people can patch it anyway -
>> the metatable just has __index=string.
>
> What was the main reason that the strings don't share the metatable (i.e.
> every string has a new { __index = string }, and not like every string has
> (the same) 'string' as a metatable? Also it is not possible to setmetatable
> to strings. Just being curious.
Lua strings are internalized. I.e. every time you have "my_long_string",
even if it is created by table.concat({"my","long","string"},"_"), it refers
to exactly the same string. It will be chaos if some string you have
just strung together has a metatable you did not know about.