lua-users home
lua-l archive

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


> 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

Tricky it is :)

> 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.

This looks great! This trick should work all the time unless there are VM
stack issues unbeknownst to me. I have to familiarize myself more with the
bytecode format. Is there any documentation related to the VM other than the
source code itself?

Thanks a lot for your hints.

Marius Gheorghe