[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Time consuming function
- From: Eugen-Andrei Gavriloaie <shiretu@...>
- Date: Mon, 31 Mar 2008 19:34:41 +0300
On Mar 31, 2008, at 2:27 PM, Alex Davies wrote:
Hey,
I don't have a need for coroutines (or at least, haven't thought of
one yet), but may be able to help. Firstly:
int w_cfunc_call(lua_State *pLuaState)
{
enqueue_request(...);
lua_yield(pLuaState,1);
return 1;
}
should be:
int w_cfunc_call(lua_State *pLuaState)
{
enqueue_request(...);
return lua_yield(pLuaState,1);
}
(lua_yield returns -1, to indicate to the vm that it's yielding).
Well, still no joy... Same error:
`attempt to yield across metamethod/C-call boundary`
I sent previous mail thinking that I was making a mistake by returning
1 instead of -1.
But unfortunately this is not the problem... I am missing something
else.... :((((
I will try to experiment with the second solution: using luajit
Secondly, somewhere in your code you've got a C call waiting to
return. Eg, if you try and yield from inside an __index metamethod,
you'll get the error your seeing. Reason being that the (c) gettable
function is still waiting for your metamethod to finish. The most
common cause of that I believe is a lua_pcall, which does not allow
yielding. One solution to this is to install luajit (recommended
anyway), which brings with it coco which allows yielding and
resuming from anywhere, even mid function. It does that by
allocating c stacks as required, something that is impossible in
ansi c but works well in practice.
- Alex