lua-users home
lua-l archive

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


For user convenience, I'm trying to implement an "addcleanup" C function
that registers functions without signature to be executed in reverse order
on script completion, interruption, or error. This allows the user to easily
specify some cleanup actions that must be performed irrespective of how
the script comes to a halt.

The actual cleanup calls are performed by pushing the function
onto the thread stack and calling lua_resume(). This seems to work
fine with two exceptions: when the script is interrupted with its
thread in a yielded state, it seems that a subsequently pushed function
cannot be resumed, and a fresh thread is needed. Also, when a C
function is pushed onto the stack, it cannot be resumed.

I'd rather not have users worry about whether a function is C or
Lua implemented. Is there a clean way of wrapping up a C function
to a Lua function, that is, do the equivalent of:

function wrap(mycfunction)
    return function() mycfunction() end
end

on the C side? Preferably something that does not involve building
a string for parsing/compilation.

---
Albert-Jan