On 2018-02-25 01:28 AM, Coda Highland wrote:
On Sat, Feb 24, 2018 at 9:33 PM, Soni "They/Them" L. <firstname.lastname@example.org> wrote:
Lua's C API is not idiomatic. I don't see setjmp/longjmp used by things likeIt is, as is the case with so many things, a tradeoff.
POSIX (as far as I know nothing in POSIX says you have to use setjmp/longjmp
to handle errors) or libuv.
It would be more idiomatic to return error codes, and have the caller
propagate errors. (Using setjmp/longjmp internally is fine tho.)
This would also increase compatibility with some libraries and programming
setjmp/longjmp is faster at runtime and simpler to code. It does of
course have a lot of limitations you have to be careful with, but
error codes also have a lot of things you have to be careful with --
among other things, using error codes implies using out parameters,
which is pretty smelly in its own right.
Certainly the compatibility note is, well, noteworthy. But it doesn't
seem to be worth the cost of refactoring the entire Lua codebase and
API (thereby breaking literally every single C extension ever written)
to accomplish that when you can write API wrappers to adapt Lua to
work in the other environments (possibly using C++ mode).
Don't forget that Lua is stackless, so any errors only have to go as far as about a handful of stack frames anyway.
(Unless you're using something like lua_call. Not something I see often, tho. Plus, you'd get to handle cleanup (freeing OS resources) *while keeping the original backtrace*!)
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.