lua-users home
lua-l archive

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


Hello.

"Finalization of function objects" patch for Lua 5.1.2

Each lua thread have own finalization stack.
Call frames may push finalizers to the fin. stack.
When call frame returned or error occured then finalizers called.

Patch file is attached and includes examples.


Lua functions:


finally (... [, status])

... - sequence of finalizers.
  finalizer - {closeable_object | {argument, function}}.
  closeable_object - object has `close' or `__gc' methods.
  Finalizers will be called in reverse order.
status (boolean) - call finalizers on success (true) or on failure (false).
Returns base index of finalization stack for finalize().


finalize ([base [, error_object]])

base - index of finalization stack, returned by finally(),
  by default - base of current call frame.
error_object - call only finalizers with "false" status (on failure)
  with this error_object as second argument.


C functions:


int lua_finally (lua_State *L, int n, int scope);

n - number of objects on stack to move to finalization stack.
scope - attach objects to current (0) or previous (-1) call frame.
Returns base index of finalization stack for lua_finalize().


void lua_finalize (lua_State *L, int base, int failure);

base - index of finalization stack, returned by lua_finally().
failure - there is error_object on stack.


Links:

1) http://www.digitalmars.com/d/exception-safe.html

2) http://lua-users.org/wiki/ResourceAcquisitionIsInitialization

Attachment: lua-5.1.2-finpatch.tar.gz
Description: GNU Zip compressed data