[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Turning a C function into a Lua function
- From: virgil@... (Virgil Smith)
- Date: Mon, 15 Sep 2003 10:05:13 -0500
OK, you've confused me and I'm curious. What's wrong with lua_call or
lua_pcall in this context. Scripts should not be able to distinguish Lua
functions from C functions (and you can call either using
lua_call/lua_pcall).
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Albert-Jan
Brouwer
Sent: Monday, September 15, 2003 8:09 AM
To: Lua mailing list
Subject: Turning a C function into a Lua function
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