satoren/kaguya

cor2.isThreadDead() is true after kaguya::LuaThread cor2 = state.newThread();

guijun opened this issue · 3 comments

kaguya::LuaThread cor = state.newThread();
state("corfun = function(arg)"
"coroutine.yield(arg) "
"coroutine.yield(arg2) "
"coroutine.yield(arg
3) "
"return arg*4 "
" end");//define corouine function

kaguya::LuaFunction corfun = state["corfun"];//lua function get

//exec coroutine with function and argment
std::cout << int(cor(corfun, 3)) << std::endl;//3
std::cout << int(cor()) << std::endl;//6
//resume template argument is result type
std::cout << cor.resume() << std::endl;//9
std::cout << int(cor()) << std::endl;//12

kaguya::LuaThread cor2 = state.newThread();
//3,6,9,12,
while(!cor2.isThreadDead()) <=====cor2.isThreadDead() is true
{

std::cout << cor2.resume<int>(corfun, 3) << ",";

}

coroutine is return "dead" if function is not assigned.
because can not distinguish both.

Can you try this?

state("corfun = function(arg)"
"coroutine.yield(arg) "
"coroutine.yield(arg2) "
"coroutine.yield(arg3) "
"return arg*4 "
" end");//define corouine function
kaguya::LuaFunction corfun = state["corfun"];//lua function get
kaguya::LuaThread cor2 = state.newThread(corfun);
//3,6,9,12,
while(!cor2.isThreadDead()) 
{
   std::cout << cor2.resume<int>(3) << ",";
}

Hi, it works.

Could you please help me for "attempt to yield across C-call boundary" ?
Luajit 2.1.0 beta3 + kaguya:
1.create a coroutine in C by newThread
2. run a lua function with corutine.yield()
3. error:
attempt to yield across C-call boundary