Re: Time consuming function
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Time consuming function
- From: "Alex Davies" <alex.mania@...>
- Date: 2008年3月31日 19:27:44 +0800
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).
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