lua-users home
lua-l archive

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



Well, you can emulate GOSUBs with GOTO, can't you.. (just conceptually,

	a=1
	__GOSUB=77
	a=2
	__GOSUB=77
	a=3
	__LABEL=77
	print(a)
	__RETURN

Where:
	__GOSUB=xx:	__RETURN_TO='#'..linenum; __GOTO=xx; __LABEL='#'..linenum
	__RETURN:	__GOTO=__RETURN_TO

This would probably need the use of C preprocessor (cpp) or something alike to do the macros (& get the linenums!). Is that out of the question?


13.9.2004 kello 20:13, Luiz Henrique de Figueiredo kirjoitti:

 I tried to implement GOTO/GOSUB functionality in Lua.

An year ago, prompted by a similar request here in lua-l, I wrote a simple
patch for luac that did the right thing for the code below:

         a=1
         __GOTO=12
         __LABEL=99
         print("bye",a)
         do return end
         a=2
         __LABEL=12
         print("hello",a)
         a=3
         __GOTO=99

That is, it turned __GOTO into JMPs and __LABEL into NOPS.
This worked great for GOTO but I don't think it will work for GOSUB ... RETURN.
--lhf