lua-users home
lua-l archive

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


On Wed, May 7, 2008 at 5:21 PM, Aaron Saarela
<Aaron.Saarela@emergent.net> 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

this is frustrating and very confusing to unmangle.

in my experience, it's better to avoid this by rethinking your flow.
as a general rule, try to do _all_ the flow control on one side:
either in Lua or in C++.

i tend to favor doing it all in Lua. for this, the easiest is to make
all the C functions very 'non-flow controlling': don't yield(), don't
call other Lua functions (except strictly as 'contained' callbacks).

if you do this, from the C++ side, it'll look as a single, monolithic
call to Lua that takes some time, but returns only when it has really
finished (quitting time?). in the meantime, some C functions have been
called, but they have all returned without any 'overlapping'

in the end, most of your C++ program will be 'just' an API to access
your inner data, with all the program logic in Lua.  if you reach
this, you'll have great flexibility and won't hit this kind of
limitations.

-- 
Javier