Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


setjmp/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.


Not 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.


This 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.


setjmp() isn't particularly rare; libpng also uses it for error reporting, for example.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: