Unity熱更新04-XLua呼叫C#-012-Lua呼叫C# 泛型
阿新 • • 發佈:2020-10-29
print("*********Lua呼叫C# 泛型函式相關知識點***********") local obj = CS.Lesson12() local child = CS.Lesson12.TestChild() local father = CS.Lesson12.TestFather() --支援有約束有引數的泛型函式 obj:TestFun1(child, father) obj:TestFun1(father, child) --lua中不支援 沒有約束的泛型函式 --obj:TestFun2(child) --lua中不支援 有約束 但是沒有引數的泛型函式 --obj:TestFun3() --lua中不支援 非class的約束 --obj:TestFun4(child) --有一定的使用限制 --Mono打包 這種方式支援使用 --il2cpp打包 如果泛型引數是引用型別才可以使用 --il2cpp打包 如果泛型引數是值型別,除非C#那邊已經呼叫過了 同類型的泛型引數 lua中才能夠被使用 --補充知識 讓上面 不支援使用的泛型函式 變得能用 --得到通用函式 --設定泛型型別再使用 --xlua.get_generic_method(類, "函式名") local testFun2 = xlua.get_generic_method(CS.Lesson12, "TestFun2") local testFun2_R = testFun2(CS.System.Int32) --呼叫 --成員方法 第一個引數 傳呼叫函式的物件 --靜態方法 不用傳 testFun2_R(obj, 1)