lua-users home
lua-l archive

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


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)?

-Brian


-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Brian Hassink
Sent: Wednesday, February 28, 2007 12:42 PM
To: Lua list
Subject: SWIG question

Hello all,

I'd like to tap the collective brainpower of this mailing list to try
and resolve a problem I'm having...

Today, I have a C function that I've registered with Lua whose purpose
is to block the invoking script on a specified event using lua_yield().
When that event occurs, lua_resume() is used to wake up the script.
Simple enough.

I'd like to leverage SWIG in my project, so that I can easily expose
other functions and structures of my application to Lua.  In looking at
the conversion of the few functions I've already got, there would seem
to be a problem with the block function described above.

The function uses the Lua state of the script as a context to associate
the event subscription with, but as far as I can tell the Lua state is
not available to functions wrapped by SWIG.  It seems like the script
will have to pass its state as an explicit argument.  Is this correct,
or is there a way for the function to determine this?

Something along the lines of pthread_self() for Lua, but called from
within a function rather than the script.  BTW, is there a means for a
script to get a handle to its own state for passing to a function if
that's the route I have to go?

Thanks,
Brian