[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua 5.1: Anyone using the guard/finalize patch?
- From: Tom N Harris <telliamed@...>
- Date: Fri, 25 Feb 2011 19:16:07 -0500
On 02/24/2011 11:30 PM, Joshua Jensen wrote:
Remind me... isn't this the patch that only cleans up on function exit?
The finalize patch I cited originally cleans up on a per block basis. I
"think" this might be preferable in my case.
Yes, the finalizers are called on function exit or tail-call. But you
can manually rewind to a saved point with the finalize function. That
may not have been present in the first generation of the patch.
Also, this applies to 5.1.4 only. Particularly the lua version which
relies on setenv/getenv and newproxy. I need to clean it up to handle
varargs and return results better (it chokes on nil, as usual) And I
don't think that it works with tail-calls either. I've put the last copy
of final.lua at http://whoopdedo.org/doku/lua/index
Can you split your code into inner and outer functions like this?
local success = fcall(function() -- protected inner function
running = true
finally(function() running = false end)
finally(function() mutex:unlock() end)
if running then return false end
if not success then return false end