其实好像跟协程一样的写法
private string luaString = @"
function test(len)
print(len)
for i=1,10,1 do
coroutine.yield(i*10)
end
end
function start()
co = coroutine.create(test) --创造线程(协成?)
return co
end
";
// Use this for initialization
void Start () {
LuaState lua = new LuaState ();
lua.Start ();
lua.DoString (luaString);
LuaFunction func = lua ["start"] as LuaFunction;
//func.BeginPCall ();
//func.PCall ();
//LuaThread thread = func.CheckLuaThread (); 通过CheckLuaThread()获取返回值
//func.EndPCall ();
LuaThread thread = func.Invoke<LuaThread>(); //通过Invoke获得线程返回值
thread.name = "test"; //设置线程的名称,应该使用于区别的
for (int i = 0; i < 10; i++) {
int ret;
thread.Resume (10, out ret); //继续方法,传参和接收返回值
Debug.Log (ret);
}
thread.Dispose ();
func.Dispose ();
lua.Dispose ();
thread = null;
func = null;
lua = null;
}