xlua如何泛型调用方法
xlua泛型调用
大多数情况是c#中写好对应的回调类型去调用,穷举所有类型。如果穷举少了,那么xlua中泛型如何去调用呢?
// An highlighted block
var foo = 'bar';
-- lua
local foo_generic = xlua.get_generic_method(CS.GetGenericMethodTest, 'Foo')
local bar_generic = xlua.get_generic_method(CS.GetGenericMethodTest, 'Bar')
local foo = foo_generic(CS.System.Int32, CS.System.Double)
local bar = bar_generic(CS.System.Double, CS.UnityEngine.GameObject)-- call instance method
local o = CS.GetGenericMethodTest()
local ret = foo(o, 1, 2) -- 这里是实例调用,需要传一个实例 oprint(ret)-- call static
methodbar(2, nil) -- 静态方法直接传参数
核心就是xlua.get_generic_method这个方法。
链接: 查看这个地址.