lua-users home
lua-l archive

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


hello every one.

I have a question about lua_yield
below is the actually listing of lua_yield 5..

/* ldo.c,v 2.37 2005/12/22 16:19:56 */


LUA_API int lua_yield (lua_State *L, int nresults) {
luai_userstateyield(L, nresults);
lua_lock(L);
if (L->nCcalls > 0)
luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
L->base = L->top - nresults; /* protect stack slots below */
L->status = LUA_YIELD;
lua_unlock(L);
return -1;
}

Why lua_yield return error in C-call boundary?
practically lua_yield is called in C because lua_yield is C-API.
I try to use it for Sleep like function through registering CFunction to Lua-VM.

static BOOL Sleep(lua_State *L)
{
DWORD SleepTicks;
SleepTicks = luaL_checkinteger(L, 1);
return lua_yield(L, 0);
}

I execute a script through lua_pcall and it always return LUA_ERRRUN.
then lua_resume can't execute the code at suspend position.

the reference manual has follows

The lua_yield function can only be called as the return _expression_ of a C function
, as follows

return lua_yield (L, nresults);

above that explicitly mention that lua_yield use always the last position in user C function.

is anybody tell me why?





"우리 인터넷, Daum" http://www.daum.net 『평생쓰는 무료 한메일넷』