lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 12 April 2018 at 13:47, Viacheslav Usov <> wrote:
> On Thu, Apr 12, 2018 at 2:35 PM, Dibyendu Majumdar <>
> wrote:
>> As I was writing my initial post I did think about suggesting a
>> try/finally type approach.
> I am not exactly sure what you mean here. Are you talking about libraries
> interacting with Lua?
> Or are you talking about some kind of try/finally syntax in Lua, where
> finally would release resources?


>> But the problem with Lua is that it has adopted a longjmp based exception
>> handling method ...
> For the record, Lua can be compiled in a mode that relies on C++ exceptions
> for that.

Actually in the early C++ days, people did implement the invocation of
destructors in a framework that used longjmp/setjmp. If I recall
correctly MFC libraries used various macros to emulate this. The
destructors used to be added to the currently active TRY context
linked list and the code invoked the destructors when an exception was
caught. So perhaps it is possible although with a dyanamic language
like Lua you don't necessarily know which objects have a __gc
metamethod. In Lua you probably need a C api to explicitly add the
object to the current protected call context / finalization list - and
then maybe in the protected call api any such objects can be finalised
in a deterministic manner.