> new code. Fortunately, it doesn't
One problem with this proposal (or the similar one with a 4th parameter)
is that we will have to create the scoped variable in all loops.
Consider this code:
do
local f, s, var = explist
local <mark> s = s -- added!
while true do
...
The creation of a scoped variable needs to allocate memory, and therefore
it could fail without creating the scoped variable!
So, I think the correct code should be more like this:
do
local <mark> _s = nil -- added!
local f, s, var = explist
_s = s -- added!
while true do
...
Anyway, Lua will have to allocate a scoped variable for every loop,
independently whether it needs it or not.
I'm not seeing why the scoped local (?) needs to be "allocated". Are you actually meaning a malloc? I would have thought in the implementation that the local would be annotated somehow similar to closure upvalues that are pulled off the function stack during return or error. Except the scoped local never needs to be pulled off the stack because when the scope ends for any reason, the value it stores is __exit()ed. (It is probably nonsensical for a local to be scoped and an upvalues.)