Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
guijun opened this issue Nov 24, 2017 · 3 comments

Comments

@guijun
Copy link

guijun commented Nov 24, 2017

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) << ",";

}

@satoren
Copy link
Owner

satoren commented Nov 24, 2017

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) << ",";
}

@guijun
Copy link
Author

guijun commented Nov 27, 2017

Hi, it works.

@guijun
Copy link
Author

guijun commented Nov 30, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants