lua-users home
lua-l archive

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

I am very new to Lua too, and not a good person to talk about "low level" things, fell free to correct me.
But I think this is explained in that way because of string concatenations.

If you do something like this inside a loop:

myName = myName .. 'blah'

This will leave a lot of "new strings" in memory to be cleaned by the garbage collector, instead of just "replace" the value of "myName" variable.


Hector Vido

Em quarta-feira, 25 de maio de 2022 13:38:54 BRT, Lars Müller <> escreveu:

In fact it changes the environment table: myName = something is
equivalent to _ENV["myName"] = something

Local variables work similarly: local myName = something; myName =
something_else doesn't change the value something, it changes the
contents of the variable myName, which is basically a
"pointer"/"reference" to a value.

On 25.05.22 18:35, Duke Normandin wrote:
> On Wed, 25 May 2022 11:11:42 -0500
> Javier Guerra Giraldez <> wrote:
>> when you change myName, it changes the variable, not the value.
> That does NOT make sense to me! The variable name, i.e. myName is
> not changed. The contents of variable myName has been changed to
> another string.
> I get it that 'blah' and 'blah-blau' are 2 different strings and
> are set in stone. But I don't see the point of even bringing the
> subject of string immutability unless it's in the context of they
> being constants.
> Duke
> ** Text only please. Bottom post works best for me **