4 ms·
Lua gets closures right. The implementation (http://www.lua.org/doc/jucs05.pdf http://www.lua.org/doc/jucs05.pdf, pgs. 8-10) is a bit novel - essentially, closu
by silentbicycle 16y ago
Lua gets closures right. The implementation (http://www.lua.org/doc/jucs05.pdf http://www.lua.org/doc/jucs05.pdf, pgs. 8-10) is a bit novel - essentially, closures are stack-allocated, but migrated to the heap if still active when the function returns. (This is partially a trade-off to keep compile-time analysis very brief; compiled Lua source is often used as a data serialization format.)
Lua also has support for calling code with a user-defined error handler before unwinding the stack (xpcall), but AFAICT there isn't a way to use it to resume where the error occurred. I tried making a library for restartable exception handling in Lua, but the complete infrastructure isn't there (yet). Maybe a "power patch"...