[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [Patch] Finalization of function objects
- From: Thomas Harning <harningt@...>
- Date: Tue, 22 Jan 2008 21:16:37 -0500
Nodir Temirhodzhaev wrote:
> Luiz Henrique de Figueiredo sent:
>
> "Finalization of function objects" patch for Lua 5.1.2
>
> What is the rationale for this patch?
For rationale see this old article:
"Generic: Change the Way You Write Exception-Safe Code - Forever" (
http://www.ddj.com/cpp/184403758).
Patch is naive implementation of this idea and hint for Lua team.
Has there been any work on enhancing this? I've found a few glitches on
another machine that I haven't had the chance to get the code from...
Examples from memory...
Adding a finalizer for non-error then one for error... something 'wrong'
happens....
print"-- Finalize on error"
do
local function add5(x)
finally(x, print, false)
finally("Z", print, false)
finally("Z", print, true)
return x + 5
end
add5(5)
assert(not pcall(add5), "Error expected")
print"OK"
end
-----OUTPUT
-- Finalize on error
Z
Z Z
nil Z
OK
Another error I recall is when an error is thrown from a coroutine... no
finalizers are executed in that case....