lua-users home
lua-l archive

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


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?

    function Func()
        local success = fcall(function() -- protected inner function
            running = true
            finally(function() running = false end)
            mutex:lock()
            finally(function() mutex:unlock() end)
            if running then return false end
            return true
        end)
        if not success then return false end
        return Idle_loop()
    end

--
- tom
telliamed@whoopdedo.org