[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: CppCon talk about Lua
- From: Andreas Weis <der_ghulbus@...>
- Date: Fri, 3 Nov 2017 07:53:08 +0100
Good point about the error handling.
I thought about this too, but unfortunately I found the topic to be too
complex to reasonably fit into the time available for such a talk.
In later Lua versions you can compile the source as C++ code and
configure it to use exceptions instead of longjmps, but I would already
consider that a fairly advanced topic.
Thank you all for the kind words and the very valuable suggestions!
On 10/31/2017 10:07 AM, Kevin Martin wrote:
I thought it was a really good presentation. I really like the call function as I can see that it would simplify a lot of our code.
On 30 Oct 2017, at 21:05, Andreas Weis <email@example.com> wrote:
If you feel that I gravely misrepresented some aspect of the language or
you think that there is something that is clearly missing from the
presentation, I will gladly take your advice into consideration.
One thing that comes to mind is our biggest pain point, which is error handling. I have found very little guidance on mixing c++ exceptions and Lua.
We compile Lua as C (because we don’t really understand LUAI_THROW/LUAI_CATCH and how they mix with our own exceptions). Our understanding is that if we’re inside a C++ function, and a lua api function errors, our destructors won’t be called because it will longjmp to the nearest pcall. The most common example is calling lua_gettable on something with an __index metamethod - as there is no way to know prior to trying the gettable that the metamethod will fail.
At the moment we wrap all our code in try/catch blocks and translate any c++ exceptions to lua errors, we use lua_pcall instead of lua_call, and from the lua side, we try to ensure that nothing else can error while we’re inside a try block and there are objects that need destructors called.