lua-users home
lua-l archive

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


On Wed, May 20, 2020 at 4:54 PM Andrea <andrea.l.vitali@gmail.com> wrote:

> could one get away by substituting all returns with a goto label, and after the label put the code necessary to close the variable?

That is exactly how this kind of stuff is done in C, and boy does that lead to ugly code. It is tedious, error prone, and, again, ugly but this can be done. Unfortunately, all that gets broken as soon as somebody starts using long jumps liberally, and Lua is a very liberal user of them, because that is how it implements its errors.

Lua errors and C long jumps are a non-local transfer of control, which invalidates this technique. So something else is needed to make sure important things are done no matter how a block is exited. That is why <close> is _really_ useful in Lua. For the record, other languages (C isn't one) have similar or dissimilar means to meet the need.

Cheers,
V.