lua-users home
lua-l archive

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


Am Sa., 10. Dez. 2022 um 20:01 Uhr schrieb Paul Ducklin <pducklin@outlook.com>:>
> Because the manual explicitly says, “Don’t do it,”

... of course you are somehow right, I am really obsessive here, sorry...... .

>
> For example, the compiler could decide to keep two copies of the variable
>,,, the loop counter might be a CPU register that isn’t used for anything else...

This would be somehow bizarre concerning my understanding how Lua
works. Please keep in mind that Lua is not a compiler-based language
but an interpreter language - it should clearly work on any CPU, so
Lua in no way would produce CPU-specific code... . As far as it knows
Lua machine has NO "hidden variables" which "live longer" than one Lua
command. Instead all variables are present in the Lua stack. Anything
else would also easily japordize e. g. every coroutine handling... .

> Or the compiler ...in the loop “for n = 1,5” the value of n *will be exactly 5
>at the end of the last iteration*. So if you ever set n to 6 then the loop will
>run forever, or at least until n wraps round past 2^63...

... yes of course ... this would be bad... but this was not my
question. (it is clear to me that you have to do such counter variable
changes with some care... (I am an experienced C programmer - no only
in "full stuffed Visual Studio C", but also in "less fool-proof"
microcontroller C variants... :) ).

> The fact that “it works” is not a good reason to do it… like smoking
> a cigarette while filling up your car with petrol (gasoline). Most of the
> time, you will be fine. But once (and never more than once) you
>and everyone near you will not be fine at all.

Nice comparison, thank you :). I just would be curious what "could
happen"... please excuse my obsessive questioning in this case... .

(maybe some "explosion experts" around here in the forum who survived
such an "explosion" and can give a stunning report :) ).