3 ms·
Did Lua's use of setjmp and longjmp for error handling pose any particular challenge? I always thought that was an odd aspect of Lua's implementation.
by mwcampbell 13y ago
Did Lua's use of setjmp and longjmp for error handling pose any particular challenge? I always thought that was an odd aspect of Lua's implementation.
- azakai 13y agosetjmp/longjmp works in emscripten, it does prevent some optimizations in functions where it is called though. But luckily it doesn't seem like it is called in anything performance-sensitive in the benchmarks I've tested.
- alayne 13y agoNot sure if this is related, but you often have to declare local variables volatile when using setjmp/longjmp because they do not preserve registers. It's one case where unoptimized C code will run fine, then -O will push variables into registers and break it. I wonder how difficult it would be to convert Lua to C++ with exceptions.
- yoklov 13y agoThis isn't an issue for Lua, because so much effort has gone into making it extremely portable. Regardless, a port to C++ would be possible, though I'd (without thinking about it much) guess it would take a performance hit due to the increased code size from to the EH tables causing icache misses.
- nitrogen 13y agosetjmp() isn't particularly rare; libpng also uses it for error reporting, for example.