Re:A function decorator that rewrites the bytecode to enable...
by daurnimator on Monday September 20, 2021 @10:31PM
(#28601457)
Lua has `goto` since 5.2; you don't need a continue keyword. e.g.
for z=1,10 do
for y=1,10 do
for x=1,10 do
if x^2 + y^2 == z^2 then
print('found a Pythagorean triple:', x, y, z)
print('now trying next z...')
goto zcontinue
end
end
end
::zcontinue::
end
Re:A function decorator that rewrites the bytecode to enable...
by OJFord on Tuesday September 21, 2021 @07:24AM
(#28603931)
That's nicer than continue really (as someone who doesn't know and has never written Lua) - works for whichever level of nested loops like that that you want, and allows/somewhat forces you to come up with a name that might be clearer what it's for.
Re:A function decorator that rewrites the bytecode to enable...
by jstanley on Tuesday September 21, 2021 @09:46AM
(#28604974)
In Perl, "next" can take a label:
LOOP:
while (foo()) {
while (bar()) {
if (baz()) { next LOOP; }
}
}
Re:A function decorator that rewrites the bytecode to enable...
by Viliam1234 on Tuesday September 21, 2021 @04:56PM
(#28609826)
Similar in Java (it is called "break", and the optional label is written the same way), although I'd guess most Java developers don't know about it.
Re:A function decorator that rewrites the bytecode to enable...
by ufo on Monday September 20, 2021 @11:14PM
(#28601736)
I know we can do that, but I still want continue ;)
Re:A function decorator that rewrites the bytecode to enable...
by klyrs on Monday September 20, 2021 @09:53PM
(#28601237)
It's truly a thing of beauty. I can't wait to test what happens when you put labels or gotos in expressions...
Re:A function decorator that rewrites the bytecode to enable...
by tedunangst on Monday September 20, 2021 @10:15PM
(#28601379)
Yeah, you can patch calls to continue() to instead be jumps.
I wonder if we could use a similar mechanism to finally add a "continue" to Lua.