Exemplo n.º 1
0
        public SharpClass RegMethod(string name, MethodBase[] methodInfo, bool isAsync = false)
        {
            MethodReflection method = new MethodReflection(methodInfo);

#if !IL2CPP
            for (int i = 0; i < methodInfo.Length; i++)
            {
                var mi = methodInfo[i] as MethodInfo;
                if (mi != null)
                {
                    if (DelegateCache.GetMethodDelegate(classType, mi, "CallDel", out CallDel fn, out Delegate del))
                    {
                        method.luaFunc[i] = fn;
                        method.del[i]     = del;
                    }
                }
            }
#endif
            //Luna.Log("反射方式实现");
            LuaRef luaFun = LuaRef.CreateFunction(State, MethodReflection.Call, method);
            if (IsTagMethod(name, out var tag))
            {
                meta.RawSet(tag, luaFun);
            }
            else
            {
                meta.RawSet(name, luaFun);
            }

            if (classType.IsArray)
            {
                if (name == "Get")
                {
                    SetMemberFunction(LunaNative.___get_indexed, luaFun);
                }

                if (name == "Set")
                {
                    SetMemberFunction(LunaNative.___set_indexed, luaFun);
                }
            }

            if (isAsync)
            {
                LuaRef r = new LuaRef(State, "coroutine.__async");
                luaFun = r.Call <LuaRef>(luaFun);

                meta.RawSet("_async_" + name, luaFun);
            }

            return(this);
        }
Exemplo n.º 2
0
        public LuaRef RegMethod(MethodInfo methodInfo, bool isProp)
        {
#if LUNA_SCRIPT
            string callFnName = (methodInfo.IsStatic && !isProp) ? "StaticCall" : "Call";
#else
            string callFnName = "Call";
#endif
            if (DelegateCache.GetMethodDelegate(classType, methodInfo, callFnName, out LuaNativeFunction luaFunc, out Delegate del))
            {
                return(LuaRef.CreateFunction(State, luaFunc, del));
            }

            return(null);
        }