[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Porting another scripting language programs to Lua
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 11 Sep 2003 23:08:52 -0300
>Is there any Lua programming idiom that could be used to emulate goto
>behaviour ?
I'd say no, unless the goto's in your language is used in a strict fashion.
For this, something like this may work, but it's tricky:
repeat
...
do break end -- was goto label
...
notgoto=true
until true
if notgoto then
...
else
... do goto part here
end
>The other alternative would be to extend Lua with goto semantics
Lua's VM has a JUMP instruction. If you only want to convert the legacy
scripts once, you may get by with a hack that precompiles converted legacy
scripts to Lua bytecode and then editing the bytecode to add the correct
jumps. In the place of goto, use something like "do return end", just to
reserve an instruction slot. You still need to find a way to know where labels
are in the bytecode. Perhaps a fake "local LABEL" will do it. Once you know
where gotos are and where they must go to, they it's pretty trivial to change
the bytecode to a JMP.
--lhf