Original Post
Hi, I am a newbie of Lua and got some problem abourt coroutine of Lua Following is my code: #include // Include the Lua header and make sure the linker knows it's pure C extern "C" { #include "lua\lua.h" #include "lua\luaxlib.h" } int PrintString ( lua_State * pLuaState ) { printf("I have been run\n"); return 0; } main () { lua_State *LuaMain, *LuaThread; // Initialize a Lua state LuaMain = lua_open(); //Load Script lua_dofile(LuaMain, "test.lua"); lua_register ( LuaMain, "PrintString", PrintString); LuaThread = lua_newthread(LuaMain); lua_getglobal(LuaThread, "co_func"); lua_resume(LuaThread, 0); lua_resume(LuaThread, 0); <===== seem not work Sleep(100); return 0; } Test.lua function co_func() while 1 do PrintString() coroutine.yield() end end After I run this, I expected it will show 2 line of "I have been run" in console, but I only got one. This means the secound "lua_resume" did not work Do I have something wrong in the coding? Thanks, from Rookie