Why can't gotos in Lua jump out of functions?
From the Programming In Lua book 3rd edition page 38
Exercise 4.5: Can you explain why Lua has the restriction that a goto
cannot jump out of a function? (Hint: how would you implement that
feature?)
I have a few guesses as to why it may be so:
If you jump from one function into another and the second one returns,
where does the PC go?
If you have a = f() but f does a goto to after that line of code, what is
the value of a?
Is it not possible to define a standard behaviour because of different
platforms' calling conventions?
I wonder how the author would answer that question. Maybe I'll e-mail him.
In the meantime, does anybody else have some ideas?
No comments:
Post a Comment