[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Exceptions (was Re: Custom extensions to Lua)
- From: David Given <dg@...>
- Date: Fri, 12 Aug 2005 14:55:06 +0100
On Friday 12 August 2005 14:08, Roberto Ierusalimschy wrote:
[...]
> I still think that we can do that with finalizers. As long as each
> object has a proper finalizer (i.e., a __gc metamethod), all we have to
> do in case of errors is to call collectgarbage() to finalize what was
> left.
I'd just like to point out that the various Java people we have here will, if
you mention finalisers to them, start frothing at the mouth and using phrases
like 'utterly brain-damaged', 'my god, what were they thinking', 'spawn of
satan' and in some circumstances 'eeeeeeeaaaaaagh'.
Just think about these:
begin
local oo
begin
local o = createobject()
o:setfinaliser(function(self)
oo = o
end)
end -- o becomes unreachable here
-- What's oo set to now?
end -- oo becomes unreachable here
-- How many times did the finaliser get called?
...
o:setfinaliser(function(self)
call_function_that_might_yield() -- what happens here?
end)
...
Of course, Java makes life much harder for itself because of the vast plethora
of different types of soft reference (there are *six* reachability states).
Not pleasant.
Lua gets away with __gc because it has very restricted functionality;
finalisers can only be written in C, the finalised objects can't be
resurrected, the finalisers can't block, etc. IMO, this is a Very Good Thing.
--
+- David Given --McQ-+
| dg@cowlark.com | Quidquid latine dictum sit, altum viditur.
| (dg@tao-group.com) |
+- www.cowlark.com --+
Attachment:
pgpL7n4_PwuVu.pgp
Description: PGP signature