lua-users home
lua-l archive

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


Had exactly the same situation. Use lua_resume instead of lua_pcall. Of course, you must create the coroutine from c++
On May 8, 2008, at 1:21 AM, Aaron Saarela wrote:

Hi,

I'm launching some Lua code from C++ using lua_pcall using Lua 5.1.3. My Lua script is creating several coroutines and trying to deliver messages between
them. I'm getting the following error on yield however:

attempt to yield across metamethod/C-call boundary

Reading through the mailing list archive I discovered calling yield from a script executed from lua_pcall isn't supported in standard Lua. I found the coco patch that I thought would let me do what I'm after. The coco patch unit
tests all pass but I continue to get the above error.

Here's the flow of my application:

C++: Calls a Lua function that creates a coroutine to do some work.
Lua: Coroutine runs, but then needs to send a message back to C++ and wait for a response. It calls a C++ function to 'send' the message and calls
coroutine.yield.  It's at this point I get the above error.
C++: The message is handled, so it calls another Lua function to deliver the
response.
Lua: The Lua function gets the response, and calls coroutine.resume for the
waiting coroutine, passing it the response.

I've done similar things in Python using a stackless tasklet. It seems I'm
missing a fundamental difference with Lua in this case.

Thanks,
-Aaron