lua-users home
lua-l archive

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


> It's a memory-managed language.  There's no destructor in Java either, not,
> nor C# nor.

Probably the only thing that is nice about PHP is that its destructors
work reliably. That means that if an object leaves the scope, the ref
count gets down to zero and it's being destroyed after your destructor
has been called. Very useful for database transaction handling which
can be rolled back automatically if an exception is thrown and the
stack is unwound. I find that this is the one and only feature of PHP
that I appreciate. I once tried to use Lua in a web environment
together with DBs but when it comes to transaction handling you're
lost ...


> (There are finalizers in these, but you're basically screwed if
> you rely on them.)

... as you state there (I can confirm that).

It would be really cool if Lua provided a way to handle stack
unwinding so that one can create transaction objects that either
commit or rollback depending on what is happening.

(maybe you could write code that registers per object error handling
that if an error occurs, all registered handlers of objects that are
on the stack are being called - but I think it would require heavy
uses of the debug library and it certainly wouldn't be pretty.)

Cheers,
Eike