lua-users home
lua-l archive

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



On 28-Feb-07, at 1:50 PM, Brian Hassink wrote:

Actually, in looking at this some more it appears as though it's not
possible to put a lua_yield() call within a SWIG wrapped function.  The
semantics of a SWIG wrapped function are different from that of a
lua_CFunction.

So, how would one do something like...

	result = block(self, event)

...where block() is a SWIG wrapped function that takes the script
context (i.e. state) and an event as arguments, and blocks (yields) the
script until the event occurs, after which the details are copied into a
result structure (resumes)?


I don't know a lot about SWIG (and it may not be the optimal binding
system for you, in fact, but that's another issue).

However, it seems like the easiest solution is to write block() in
Lua. There's no shame in that :)

function block(event) return coroutine.yield(event) end

That assumes that you have a supervisor (event loop, I guess)
which handles the coroutines. You could write this in Lua,
as well; I've put an example on the wiki at http://lua-users.org/wiki/CoroutinesAsEventHandlers