util =require("xlua.util")
GameObject = CS.UnityEngine.GameObject
WaitForSeconds = CS.UnityEngine.WaitForSeconds
local go =GameObject("Coroutine")local mono = go:AddComponent(typeof(CS.TestMono))
func =function()local a =0whiletruedoprint(a)
a = a +1
coroutine.yield(WaitForSeconds(0.5))if a >=10then
mono:StopCoroutine(b)endendend
b = mono:StartCoroutine(util.cs_generator(func))
三.Lua调用泛型方法
Lua本身只支持,有参有类约束的泛型方法,其余泛型方法都不支持
除非使用Xlua为其提供的方法,但是不建议使用有局限性
如果打包为Mono方式的话可以,但是打包为il2cpp方式有局限性(具体参考下图)
publicclassLesson12{publicclassTestFather{}publicclassTestChild:TestFather, ITest
{}publicinterfaceITest{}publicvoidTestFun1<T>(T t1,T t2)where T : TestFather
{
Debug.Log("有参有约束");}publicvoidTestFun2<T>(T t1){
Debug.Log("有参无约束");}publicvoidTestFun3<T>()where T : TestFather
{
Debug.Log("无参有约束");}publicvoidTestFun4<T>(T t1)where T : ITest
{
Debug.Log("有参有接口约束");}}