[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Running the GC to clear resource holding object on failure
- From: Tom N Harris <telliamed@...>
- Date: Sat, 02 Aug 2014 18:30:10 -0400
On Saturday, August 02, 2014 01:38:17 PM Marc Balmer wrote:
> The Lua script is called from C code using lua_pcall(). Now we notice a
> problem: What if the script contains an error and p:close() is never
> called? In this case the connection to the printer remains open until the
> GC kicks in, which can take long. And during this time, our networked
> (ticket) printer is blocked.
You want RAII[1]. Although not baked into the language, there are a few ways
to accomplish it with Lua. I had my own go at it[2] that works pretty well in
5.2.
[1] http://lua-users.org/wiki/ResourceAcquisitionIsInitialization
[2] http://www.whoopdedo.org/doku/lua/index
--
tom <telliamed@whoopdedo.org>