public void CreateUserAccountRepository_CallsDelegate()
 {
     Func<IUserAccountRepository> func = () => new TestRepo();
     var sub = new DelegateFactory(func);
     var instance = sub.CreateUserAccountRepository();
     Assert.IsNotNull(instance);
     Assert.IsInstanceOfType(instance, typeof(TestRepo));
 }
示例#2
0
        public static void Run()
        {
            var factory = new DelegateFactory();

            // begin
            var d = factory.Create();
            // end

            d.DynamicInvoke(42);
        }
示例#3
0
        public static void Run()
        {
            var factory = new DelegateFactory();
            var action = new CustomAction<int>(delegate { });

            // begin
            var d = factory.Create(action);
            // end

            d.DynamicInvoke(42);
        }
示例#4
0
 private void RegisterNew()
 {
     var cb = CurrentScope;
     foreach (var rb in FactoryBuilders)
     {
         foreach (var item in rb.Types.Where(i => i.IsGeneric == false))
         {
             switch (item.Scope)
             {
                 case InstanceScope.Transient:
                     if (item.AsType == null)
                         cb.Register(item.Type);
                     else
                         cb.Register(item.AsType, item.Type);
                     break;
                 case InstanceScope.Singleton:
                     if (item.AsType == null)
                         cb.Register(item.Type, Reuse.Singleton);
                     else
                         cb.Register(item.AsType, item.Type, Reuse.Singleton);
                     break;
                 default:
                     if (item.AsType == null)
                         cb.Register(item.Type, Reuse.InCurrentScope);
                     else
                         cb.Register(item.AsType, item.Type, Reuse.InCurrentScope);
                     break;
             }
         }
         foreach (var item in rb.Types.Where(i => i.IsGeneric))
         {
             switch (item.Scope)
             {
                 case InstanceScope.Transient:
                     if (item.AsType == null)
                         cb.Register(item.Type);
                     else
                         cb.Register(item.AsType, item.Type);
                     break;
                 case InstanceScope.Singleton:
                     if (item.AsType == null)
                         cb.Register(item.Type, Reuse.Singleton);
                     else
                         cb.Register(item.AsType, item.Type, Reuse.Singleton);
                     break;
                 default:
                     if (item.AsType == null)
                         cb.Register(item.Type, Reuse.InCurrentScope);
                     else
                         cb.Register(item.AsType, item.Type, Reuse.InCurrentScope);
                     break;
             }
         }
         foreach (var item in rb.Instances)
         {
             var type = item.AsType ?? item.Instance.GetType();
             var factory = new DelegateFactory(
                 (_, registry) => Expression.Constant(item.Instance),
                 Reuse.Transient,
                 null);
             cb.Register(factory, type, null);
         }
         foreach (var item in rb.Funcs)
         {
             if (item.AsType == null)
                 throw new NotSupportedException("Result type must be defined. Declared Func result is not defined");
             //TODO
             /*
             switch (item.Scope)
             {
                 case InstanceScope.Transient:
                     cb.Register(c => item.Func(c.Resolve<IObjectFactory>())).As(item.AsType);
                     break;
                 case InstanceScope.Singleton:
                     cb.Register(c => item.Func(c.Resolve<IObjectFactory>())).As(item.AsType).SingleInstance();
                     break;
                 default:
                     cb.Register(c => item.Func(c.Resolve<IObjectFactory>())).As(item.AsType).InstancePerLifetimeScope();
                     break;
             }*/
         }
     }
 }
示例#5
0
 static int Clear(IntPtr L)
 {
     LuaScriptMgr.CheckArgsCount(L, 0);
     DelegateFactory.Clear();
     return(0);
 }
示例#6
0
        public void Can_fallback_to_next_rule_if_AutoConcreteResolution_is_unable_to_resolve_concrete_type()
        {
            var container = new Container(rules => rules
                                          .WithConcreteTypeDynamicRegistrations()
                                          .WithUnknownServiceResolvers(r => r.ServiceType == typeof(Xx) ? DelegateFactory.Of(_ => new Xx(null)) : null));

            var xx = container.Resolve <Xx>();

            Assert.IsInstanceOf <Xx>(xx);
        }
示例#7
0
 public View OnCreateView(View parent, string name, Context context, IAttributeSet attrs)
 {
     return(DelegateFactory.OnCreateView(parent, name, context, attrs));
 }
示例#8
0
        /// <summary>
        /// Scans the given type storing maps to fields and properties to save on reflection at runtime.
        /// </summary>
        /// <param name="t"></param>
        public void InitType(Type t)
        {
            logger.Debug("Initializing type: " + t.AssemblyQualifiedName);

            if (t.IsSimpleType())
            {
                return;
            }

            if (typeof(IEnumerable).IsAssignableFrom(t))
            {
                if (t.IsArray)
                {
                    typesToCreateForArrays[t] = typeof(List <>).MakeGenericType(t.GetElementType());
                }


                foreach (Type g in t.GetGenericArguments())
                {
                    InitType(g);
                }

                //Handle dictionaries - initalize relevant KeyValuePair<T,K> types.
                foreach (Type interfaceType in t.GetInterfaces())
                {
                    Type[] arr = interfaceType.GetGenericArguments();
                    if (arr.Length == 1)
                    {
                        if (typeof(IEnumerable <>).MakeGenericType(arr[0]).IsAssignableFrom(t))
                        {
                            InitType(arr[0]);
                        }
                    }
                }

                if (t.IsGenericType && t.IsInterface) //handle IEnumerable<Something>
                {
                    var g = t.GetGenericArguments();
                    var e = typeof(IEnumerable <>).MakeGenericType(g);

                    if (e.IsAssignableFrom(t))
                    {
                        typesToCreateForEnumerables[t] = typeof(List <>).MakeGenericType(g);
                    }
                }
#if !NET35
                if (t.IsGenericType && t.GetGenericArguments().Length == 1)
                {
                    Type setType = typeof(ISet <>).MakeGenericType(t.GetGenericArguments());

                    if (setType.IsAssignableFrom(t)) //handle ISet<Something>
                    {
                        var g = t.GetGenericArguments();
                        var e = typeof(IEnumerable <>).MakeGenericType(g);

                        if (e.IsAssignableFrom(t))
                        {
                            typesToCreateForEnumerables[t] = typeof(List <>).MakeGenericType(g);
                        }
                    }
                }
#endif

                return;
            }

            var isKeyValuePair = false;

            var args = t.GetGenericArguments();
            if (args.Length == 2)
            {
                isKeyValuePair = (typeof(KeyValuePair <,>).MakeGenericType(args) == t);
            }

            if (args.Length == 1 && args[0].IsValueType)
            {
                if (args[0].GetGenericArguments().Any() || typeof(Nullable <>).MakeGenericType(args) == t)
                {
                    InitType(args[0]);

                    if (!args[0].GetGenericArguments().Any())
                    {
                        return;
                    }
                }
            }

            //already in the process of initializing this type (prevents infinite recursion).
            if (typesBeingInitialized.Contains(t))
            {
                return;
            }

            typesBeingInitialized.Add(t);

            var props = GetAllPropertiesForType(t, isKeyValuePair);
            typeToProperties[t] = props;
            var fields = GetAllFieldsForType(t);
            typeToFields[t] = fields;


            foreach (var p in props)
            {
                logger.Debug("Handling property: " + p.Name);

                propertyInfoToLateBoundProperty[p] = DelegateFactory.Create(p);

                if (!isKeyValuePair)
                {
                    propertyInfoToLateBoundPropertySet[p] = DelegateFactory.CreateSet(p);
                }

                InitType(p.PropertyType);
            }

            foreach (var f in fields)
            {
                logger.Debug("Handling field: " + f.Name);

                fieldInfoToLateBoundField[f] = DelegateFactory.Create(f);

                if (!isKeyValuePair)
                {
                    fieldInfoToLateBoundFieldSet[f] = DelegateFactory.CreateSet(f);
                }

                InitType(f.FieldType);
            }
        }
        public void TestDelegateFactory()
        {
            TestObject obj = new TestObject();
            IFactory<TestObject> factory = new DelegateFactory<TestObject>(() => obj);
            Assert.IsTrue(ReferenceEquals(factory.Create(), factory.Create()));

            factory = new DelegateFactory<TestObject>(() => new TestObject());
            Assert.IsFalse(ReferenceEquals(factory.Create(), factory.Create()));
        }
    private static int Create(IntPtr L)
    {
        int result;

        try
        {
            int num = LuaDLL.lua_gettop(L);
            if (num == 5 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(int), typeof(int), typeof(int), typeof(bool)))
            {
                string    text = ToLua.ToString(L, 1);
                int       num2 = (int)LuaDLL.lua_tonumber(L, 2);
                int       num3 = (int)LuaDLL.lua_tonumber(L, 3);
                int       num4 = (int)LuaDLL.lua_tonumber(L, 4);
                bool      flag = LuaDLL.lua_toboolean(L, 5);
                AudioClip obj  = AudioClip.Create(text, num2, num3, num4, flag);
                ToLua.Push(L, obj);
                result = 1;
            }
            else if (num == 6 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(int), typeof(int), typeof(int), typeof(bool), typeof(AudioClip.PCMReaderCallback)))
            {
                string   text2    = ToLua.ToString(L, 1);
                int      num5     = (int)LuaDLL.lua_tonumber(L, 2);
                int      num6     = (int)LuaDLL.lua_tonumber(L, 3);
                int      num7     = (int)LuaDLL.lua_tonumber(L, 4);
                bool     flag2    = LuaDLL.lua_toboolean(L, 5);
                LuaTypes luaTypes = LuaDLL.lua_type(L, 6);
                AudioClip.PCMReaderCallback pCMReaderCallback;
                if (luaTypes != LuaTypes.LUA_TFUNCTION)
                {
                    pCMReaderCallback = (AudioClip.PCMReaderCallback)ToLua.ToObject(L, 6);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 6);
                    pCMReaderCallback = (DelegateFactory.CreateDelegate(typeof(AudioClip.PCMReaderCallback), func) as AudioClip.PCMReaderCallback);
                }
                AudioClip obj2 = AudioClip.Create(text2, num5, num6, num7, flag2, pCMReaderCallback);
                ToLua.Push(L, obj2);
                result = 1;
            }
            else if (num == 7 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(int), typeof(int), typeof(int), typeof(bool), typeof(AudioClip.PCMReaderCallback), typeof(AudioClip.PCMSetPositionCallback)))
            {
                string   text3     = ToLua.ToString(L, 1);
                int      num8      = (int)LuaDLL.lua_tonumber(L, 2);
                int      num9      = (int)LuaDLL.lua_tonumber(L, 3);
                int      num10     = (int)LuaDLL.lua_tonumber(L, 4);
                bool     flag3     = LuaDLL.lua_toboolean(L, 5);
                LuaTypes luaTypes2 = LuaDLL.lua_type(L, 6);
                AudioClip.PCMReaderCallback pCMReaderCallback2;
                if (luaTypes2 != LuaTypes.LUA_TFUNCTION)
                {
                    pCMReaderCallback2 = (AudioClip.PCMReaderCallback)ToLua.ToObject(L, 6);
                }
                else
                {
                    LuaFunction func2 = ToLua.ToLuaFunction(L, 6);
                    pCMReaderCallback2 = (DelegateFactory.CreateDelegate(typeof(AudioClip.PCMReaderCallback), func2) as AudioClip.PCMReaderCallback);
                }
                LuaTypes luaTypes3 = LuaDLL.lua_type(L, 7);
                AudioClip.PCMSetPositionCallback pCMSetPositionCallback;
                if (luaTypes3 != LuaTypes.LUA_TFUNCTION)
                {
                    pCMSetPositionCallback = (AudioClip.PCMSetPositionCallback)ToLua.ToObject(L, 7);
                }
                else
                {
                    LuaFunction func3 = ToLua.ToLuaFunction(L, 7);
                    pCMSetPositionCallback = (DelegateFactory.CreateDelegate(typeof(AudioClip.PCMSetPositionCallback), func3) as AudioClip.PCMSetPositionCallback);
                }
                AudioClip obj3 = AudioClip.Create(text3, num8, num9, num10, flag3, pCMReaderCallback2, pCMSetPositionCallback);
                ToLua.Push(L, obj3);
                result = 1;
            }
            else
            {
                result = LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.AudioClip.Create");
            }
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
示例#11
0
    static int SetEase(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes <DG.Tweening.Tween, DG.Tweening.Ease>(L, 1))
            {
                DG.Tweening.Sequence obj  = (DG.Tweening.Sequence)ToLua.ToObject(L, 1);
                DG.Tweening.Ease     arg0 = (DG.Tweening.Ease)ToLua.ToObject(L, 2);
                DG.Tweening.Tween    o    = obj.SetEase(arg0);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes <DG.Tweening.Tween, UnityEngine.AnimationCurve>(L, 1))
            {
                DG.Tweening.Sequence       obj  = (DG.Tweening.Sequence)ToLua.ToObject(L, 1);
                UnityEngine.AnimationCurve arg0 = (UnityEngine.AnimationCurve)ToLua.ToObject(L, 2);
                DG.Tweening.Tween          o    = obj.SetEase(arg0);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes <DG.Tweening.Tween, DG.Tweening.EaseFunction>(L, 1))
            {
                DG.Tweening.Sequence     obj  = (DG.Tweening.Sequence)ToLua.ToObject(L, 1);
                DG.Tweening.EaseFunction arg0 = null;
                LuaTypes funcType2            = LuaDLL.lua_type(L, 2);

                if (funcType2 != LuaTypes.LUA_TFUNCTION)
                {
                    arg0 = (DG.Tweening.EaseFunction)ToLua.ToObject(L, 2);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 2);
                    arg0 = DelegateFactory.CreateDelegate(typeof(DG.Tweening.EaseFunction), func) as DG.Tweening.EaseFunction;
                }

                DG.Tweening.Tween o = obj.SetEase(arg0);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3)
            {
                DG.Tweening.Sequence obj  = (DG.Tweening.Sequence)ToLua.CheckObject(L, 1, typeof(DG.Tweening.Sequence));
                DG.Tweening.Ease     arg0 = (DG.Tweening.Ease)ToLua.CheckObject(L, 2, typeof(DG.Tweening.Ease));
                float             arg1    = (float)LuaDLL.luaL_checknumber(L, 3);
                DG.Tweening.Tween o       = obj.SetEase(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 4)
            {
                DG.Tweening.Sequence obj  = (DG.Tweening.Sequence)ToLua.CheckObject(L, 1, typeof(DG.Tweening.Sequence));
                DG.Tweening.Ease     arg0 = (DG.Tweening.Ease)ToLua.CheckObject(L, 2, typeof(DG.Tweening.Ease));
                float             arg1    = (float)LuaDLL.luaL_checknumber(L, 3);
                float             arg2    = (float)LuaDLL.luaL_checknumber(L, 4);
                DG.Tweening.Tween o       = obj.SetEase(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: DG.Tweening.Sequence.SetEase"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
示例#12
0
        public void FieldGet_ByTypes_NonExisting()
        {
            var fg = DelegateFactory.FieldGet <TestClass, string>("NonExisting");

            Assert.IsNull(fg);
        }
    static int WaitFor(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(Lit.Unity.LitBehaviour), typeof(Lit.Unity._D_OuterBool), typeof(Lit.Unity._D_Void)))
            {
                Lit.Unity.LitBehaviour obj  = (Lit.Unity.LitBehaviour)ToLua.ToObject(L, 1);
                Lit.Unity._D_OuterBool arg0 = null;
                LuaTypes funcType2          = LuaDLL.lua_type(L, 2);

                if (funcType2 != LuaTypes.LUA_TFUNCTION)
                {
                    arg0 = (Lit.Unity._D_OuterBool)ToLua.ToObject(L, 2);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 2);
                    arg0 = DelegateFactory.CreateDelegate(typeof(Lit.Unity._D_OuterBool), func) as Lit.Unity._D_OuterBool;
                }

                Lit.Unity._D_Void arg1      = null;
                LuaTypes          funcType3 = LuaDLL.lua_type(L, 3);

                if (funcType3 != LuaTypes.LUA_TFUNCTION)
                {
                    arg1 = (Lit.Unity._D_Void)ToLua.ToObject(L, 3);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 3);
                    arg1 = DelegateFactory.CreateDelegate(typeof(Lit.Unity._D_Void), func) as Lit.Unity._D_Void;
                }

                UnityEngine.Coroutine o = obj.WaitFor(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(Lit.Unity.LitBehaviour), typeof(float), typeof(Lit.Unity._D_Void)))
            {
                Lit.Unity.LitBehaviour obj  = (Lit.Unity.LitBehaviour)ToLua.ToObject(L, 1);
                float             arg0      = (float)LuaDLL.lua_tonumber(L, 2);
                Lit.Unity._D_Void arg1      = null;
                LuaTypes          funcType3 = LuaDLL.lua_type(L, 3);

                if (funcType3 != LuaTypes.LUA_TFUNCTION)
                {
                    arg1 = (Lit.Unity._D_Void)ToLua.ToObject(L, 3);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 3);
                    arg1 = DelegateFactory.CreateDelegate(typeof(Lit.Unity._D_Void), func) as Lit.Unity._D_Void;
                }

                UnityEngine.Coroutine o = obj.WaitFor(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Lit.Unity.LitBehaviour.WaitFor"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
示例#14
0
 public QueryStringCreator(Type value)
 {
     _typeInfo = CreateQueryParams(value);
     _getters  = value.GetProperties()
                 .ToDictionary(x => x.Name, x => DelegateFactory.CreatePropertyGetter(x));
 }
    static int set_logMessageReceivedThreaded(IntPtr L)
    {
        try
        {
            EventObject arg0 = null;

            if (LuaDLL.lua_isuserdata(L, 2) != 0)
            {
                arg0 = (EventObject)ToLua.ToObject(L, 2);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "The event 'UnityEngine.Application.logMessageReceivedThreaded' can only appear on the left hand side of += or -= when used outside of the type 'UnityEngine.Application'"));
            }

            if (arg0.op == EventOp.Add)
            {
                UnityEngine.Application.LogCallback ev = (UnityEngine.Application.LogCallback)DelegateFactory.CreateDelegate(typeof(UnityEngine.Application.LogCallback), arg0.func);
                UnityEngine.Application.logMessageReceivedThreaded += ev;
            }
            else if (arg0.op == EventOp.Sub)
            {
                UnityEngine.Application.LogCallback ev = (UnityEngine.Application.LogCallback)LuaMisc.GetEventHandler(null, typeof(UnityEngine.Application), "logMessageReceivedThreaded");
                Delegate[] ds    = ev.GetInvocationList();
                LuaState   state = LuaState.Get(L);

                for (int i = 0; i < ds.Length; i++)
                {
                    ev = (UnityEngine.Application.LogCallback)ds[i];
                    LuaDelegate ld = ev.Target as LuaDelegate;

                    if (ld != null && ld.func == arg0.func)
                    {
                        UnityEngine.Application.logMessageReceivedThreaded -= ev;
                        state.DelayDispose(ld.func);
                        break;
                    }
                }

                arg0.func.Dispose();
            }

            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
        public void PrivateMethods()
        {
            BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;

            var  test = new TestClass();
            Type t    = typeof(TestClass);

            var m = t.GetMethod("PrivateOpen1", flags);

            Assert.IsNotNull(m);
            var d = DelegateFactory.CreateMethod(m);

            Assert.IsNotNull(d);
            var parameters = new object[] { "Test" };
            var r          = d.Invoke(test, parameters);

            Assert.IsNull(r);

            m = t.GetMethod("PrivateStaticOpen1", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);


            m = t.GetMethod("PrivateOpen2", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test", 2 };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);


            m = t.GetMethod("PrivateOpenReturn", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test", 2 };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);

#if !SILVERLIGHT
            m = t.GetMethod("PrivateOpenOut", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test", null };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);
            Assert.AreEqual("1234", parameters[1]);


            m = t.GetMethod("PrivateOpenOutReturn", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", null };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);
            Assert.AreEqual("1234", parameters[1]);


            m = t.GetMethod("PrivateOpenRef", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", "" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);
            Assert.AreEqual("1234", parameters[1]);


            m = t.GetMethod("PrivateOpenRefReturn", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", "" };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);
            Assert.AreEqual("1234", parameters[1]);
#endif

            m = t.GetMethod("PrivateOpenGeneric", flags);
            Assert.IsNotNull(m);
            m = m.MakeGenericMethod(typeof(string));
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);

            m = t.GetMethod("PrivateOpenReturnGeneric", flags);
            Assert.IsNotNull(m);
            m = m.MakeGenericMethod(typeof(string));
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", 1 };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);
        }
        public void PublicMethods()
        {
            var  test = new TestClass();
            Type t    = typeof(TestClass);

            var m = t.GetMethod("BaseOpen");

            Assert.IsNotNull(m);
            var d = DelegateFactory.CreateMethod(m);

            Assert.IsNotNull(d);
            var parameters = new object[] { "Test" };
            var r          = d.Invoke(test, parameters);

            Assert.IsNull(r);

            m = t.GetMethod("PublicOpen1");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);

            m = t.GetMethod("PublicStaticOpen1");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);


            m = t.GetMethod("PublicOpen2");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test", 2 };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);


            m = t.GetMethod("PublicOpenReturn");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test", 2 };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);

#if !SILVERLIGHT
            m = t.GetMethod("PublicOpenOut");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test", null };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);
            Assert.AreEqual("1234", parameters[1]);

            m = t.GetMethod("PublicOpenOutReturn");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", null };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);
            Assert.AreEqual("1234", parameters[1]);


            m = t.GetMethod("PublicOpenRef");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", "" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);
            Assert.AreEqual("1234", parameters[1]);


            m = t.GetMethod("PublicOpenRefReturn");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", "" };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);
            Assert.AreEqual("1234", parameters[1]);
#endif

            m = t.GetMethod("PublicOpenGeneric");
            Assert.IsNotNull(m);
            m = m.MakeGenericMethod(typeof(string));
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);

            m = t.GetMethod("PublicOpenReturnGeneric");
            Assert.IsNotNull(m);
            m = m.MakeGenericMethod(typeof(string));
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", 1 };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);
        }
        public void CreateSetProperty()
        {
            var       testClass  = new TestClass();
            var       properties = typeof(TestClass).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
            Stopwatch watch      = Stopwatch.StartNew();

            foreach (var propertyInfo in properties)
            {
                var d = DelegateFactory.CreateSet(propertyInfo);
                Assert.IsNotNull(d);

                object value = null;
                switch (propertyInfo.Name)
                {
                case "LastName":
                    value = "Doe";
                    break;

                case "Age":
                    value = 21;
                    break;

                case "PrivateSet":
                    value = "Private Set";
                    break;

                case "PrivateGet":
                    value = "Private Get";
                    break;

                case "Internal":
                    value = "test";
                    break;

                case "IsStatic":
                    value = true;
                    break;

                case "StaticName":
                    value = "CreateSetProperty";
                    break;

                case "FirstName":
                    value = "John";
                    break;
                }

                d(testClass, value);
                Console.WriteLine("Property: {0} Value: {1}", propertyInfo.Name, value);
            }
            watch.Stop();
            Console.WriteLine("Time: {0}ms", watch.ElapsedMilliseconds);

            Assert.AreEqual("Doe", testClass.LastName);
            Assert.AreEqual(21, testClass.Age);
            Assert.AreEqual("Private Set", testClass.PrivateSet);
            Assert.AreEqual("test", testClass.Internal);
            Assert.AreEqual(true, TestClass.IsStatic);
            Assert.AreEqual("CreateSetProperty", TestClass.StaticName);
            Assert.AreEqual("John", testClass.FirstName);
        }
示例#19
0
        public void FieldGet_ByExtensionAndReturnType_NonExisting()
        {
            var fg = DelegateFactory.FieldGet <TestClass, string>("NonExisting");

            Assert.IsNull(fg);
        }
    static int LoadPrefab(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(LuaFramework.ResourceManager), typeof(string), typeof(string[]), typeof(LuaInterface.LuaFunction)))
            {
                LuaFramework.ResourceManager obj = (LuaFramework.ResourceManager)ToLua.ToObject(L, 1);
                string      arg0 = ToLua.ToString(L, 2);
                string[]    arg1 = ToLua.CheckStringArray(L, 3);
                LuaFunction arg2 = ToLua.ToLuaFunction(L, 4);
                obj.LoadPrefab(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(LuaFramework.ResourceManager), typeof(string), typeof(string[]), typeof(System.Action <UnityEngine.Object[]>)))
            {
                LuaFramework.ResourceManager obj = (LuaFramework.ResourceManager)ToLua.ToObject(L, 1);
                string   arg0 = ToLua.ToString(L, 2);
                string[] arg1 = ToLua.CheckStringArray(L, 3);
                System.Action <UnityEngine.Object[]> arg2 = null;
                LuaTypes funcType4 = LuaDLL.lua_type(L, 4);

                if (funcType4 != LuaTypes.LUA_TFUNCTION)
                {
                    arg2 = (System.Action <UnityEngine.Object[]>)ToLua.ToObject(L, 4);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 4);
                    arg2 = DelegateFactory.CreateDelegate(typeof(System.Action <UnityEngine.Object[]>), func) as System.Action <UnityEngine.Object[]>;
                }

                obj.LoadPrefab(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(LuaFramework.ResourceManager), typeof(string), typeof(string), typeof(System.Action <UnityEngine.Object[]>)))
            {
                LuaFramework.ResourceManager obj = (LuaFramework.ResourceManager)ToLua.ToObject(L, 1);
                string arg0 = ToLua.ToString(L, 2);
                string arg1 = ToLua.ToString(L, 3);
                System.Action <UnityEngine.Object[]> arg2 = null;
                LuaTypes funcType4 = LuaDLL.lua_type(L, 4);

                if (funcType4 != LuaTypes.LUA_TFUNCTION)
                {
                    arg2 = (System.Action <UnityEngine.Object[]>)ToLua.ToObject(L, 4);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 4);
                    arg2 = DelegateFactory.CreateDelegate(typeof(System.Action <UnityEngine.Object[]>), func) as System.Action <UnityEngine.Object[]>;
                }

                obj.LoadPrefab(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 5 && TypeChecker.CheckTypes(L, 1, typeof(LuaFramework.ResourceManager), typeof(string), typeof(string[]), typeof(LuaInterface.LuaFunction), typeof(int)))
            {
                LuaFramework.ResourceManager obj = (LuaFramework.ResourceManager)ToLua.ToObject(L, 1);
                string      arg0 = ToLua.ToString(L, 2);
                string[]    arg1 = ToLua.CheckStringArray(L, 3);
                LuaFunction arg2 = ToLua.ToLuaFunction(L, 4);
                int         arg3 = (int)LuaDLL.lua_tonumber(L, 5);
                obj.LoadPrefab(arg0, arg1, arg2, arg3);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: LuaFramework.ResourceManager.LoadPrefab"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    static int set_reapplyDrivenProperties(IntPtr L)
    {
        try
        {
            EventObject arg0 = null;

            if (LuaDLL.lua_isuserdata(L, 2) != 0)
            {
                arg0 = (EventObject)ToLua.ToObject(L, 2);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "The event 'UnityEngine.RectTransform.reapplyDrivenProperties' can only appear on the left hand side of += or -= when used outside of the type 'UnityEngine.RectTransform'"));
            }

            if (arg0.op == EventOp.Add)
            {
                UnityEngine.RectTransform.ReapplyDrivenProperties ev = (UnityEngine.RectTransform.ReapplyDrivenProperties)DelegateFactory.CreateDelegate(typeof(UnityEngine.RectTransform.ReapplyDrivenProperties), arg0.func);
                UnityEngine.RectTransform.reapplyDrivenProperties += ev;
            }
            else if (arg0.op == EventOp.Sub)
            {
                UnityEngine.RectTransform.ReapplyDrivenProperties ev = (UnityEngine.RectTransform.ReapplyDrivenProperties)LuaMisc.GetEventHandler(null, typeof(UnityEngine.RectTransform), "reapplyDrivenProperties");
                Delegate[] ds    = ev.GetInvocationList();
                LuaState   state = LuaState.Get(L);

                for (int i = 0; i < ds.Length; i++)
                {
                    ev = (UnityEngine.RectTransform.ReapplyDrivenProperties)ds[i];
                    LuaDelegate ld = ev.Target as LuaDelegate;

                    if (ld != null && ld.func == arg0.func)
                    {
                        UnityEngine.RectTransform.reapplyDrivenProperties -= ev;
                        state.DelayDispose(ld.func);
                        break;
                    }
                }

                arg0.func.Dispose();
            }

            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    static int ShowMessageBox(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && ToLua.CheckTypes(L, 1, typeof(MyFrameWork.UIMgr), typeof(string)))
            {
                MyFrameWork.UIMgr obj  = (MyFrameWork.UIMgr)ToLua.ToObject(L, 1);
                string            arg0 = ToLua.ToString(L, 2);
                obj.ShowMessageBox(arg0);
                return(0);
            }
            else if (count == 4 && ToLua.CheckTypes(L, 1, typeof(MyFrameWork.UIMgr), typeof(string), typeof(string), typeof(UIEventListener.VoidDelegate)))
            {
                MyFrameWork.UIMgr            obj       = (MyFrameWork.UIMgr)ToLua.ToObject(L, 1);
                string                       arg0      = ToLua.ToString(L, 2);
                string                       arg1      = ToLua.ToString(L, 3);
                UIEventListener.VoidDelegate arg2      = null;
                LuaTypes                     funcType4 = LuaDLL.lua_type(L, 4);

                if (funcType4 != LuaTypes.LUA_TFUNCTION)
                {
                    arg2 = (UIEventListener.VoidDelegate)ToLua.ToObject(L, 4);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 4);
                    arg2 = DelegateFactory.CreateDelegate(typeof(UIEventListener.VoidDelegate), func) as UIEventListener.VoidDelegate;
                }

                obj.ShowMessageBox(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 6 && ToLua.CheckTypes(L, 1, typeof(MyFrameWork.UIMgr), typeof(string), typeof(string), typeof(UIEventListener.VoidDelegate), typeof(string), typeof(UIEventListener.VoidDelegate)))
            {
                MyFrameWork.UIMgr            obj       = (MyFrameWork.UIMgr)ToLua.ToObject(L, 1);
                string                       arg0      = ToLua.ToString(L, 2);
                string                       arg1      = ToLua.ToString(L, 3);
                UIEventListener.VoidDelegate arg2      = null;
                LuaTypes                     funcType4 = LuaDLL.lua_type(L, 4);

                if (funcType4 != LuaTypes.LUA_TFUNCTION)
                {
                    arg2 = (UIEventListener.VoidDelegate)ToLua.ToObject(L, 4);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 4);
                    arg2 = DelegateFactory.CreateDelegate(typeof(UIEventListener.VoidDelegate), func) as UIEventListener.VoidDelegate;
                }

                string arg3 = ToLua.ToString(L, 5);
                UIEventListener.VoidDelegate arg4 = null;
                LuaTypes funcType6 = LuaDLL.lua_type(L, 6);

                if (funcType6 != LuaTypes.LUA_TFUNCTION)
                {
                    arg4 = (UIEventListener.VoidDelegate)ToLua.ToObject(L, 6);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 6);
                    arg4 = DelegateFactory.CreateDelegate(typeof(UIEventListener.VoidDelegate), func) as UIEventListener.VoidDelegate;
                }

                obj.ShowMessageBox(arg0, arg1, arg2, arg3, arg4);
                return(0);
            }
            else
            {
                return(LuaDLL.tolua_error(L, "invalid arguments to method: MyFrameWork.UIMgr.ShowMessageBox"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
示例#23
0
        public void PropertyGet_ByObjects_NonExisting()
        {
            var spg = DelegateFactory.StaticPropertyGet <TestClass, string>("NonExisting");

            Assert.IsNull(spg);
        }
示例#24
0
 internal static Delegate Constructor(Type type)
 {
     return Lambda(ToType(DelegateFactory.GenerateConstructorExpression(type), type)).Compile();
 }
示例#25
0
        public void PropertyGet_ByTypes_OnlyWrite()
        {
            var spg = DelegateFactory.StaticPropertyGet <TestClass, string>("StaticOnlySetProperty");

            Assert.IsNull(spg);
        }
示例#26
0
 void OnGUI()
 {
     if (GUI.Button(new Rect(10, 10, 120, 40), " = OnClick1"))
     {
         CallLuaFunction(SetClick1);
     }
     else if (GUI.Button(new Rect(10, 60, 120, 40), " + Click1"))
     {
         CallLuaFunction(AddClick1);
     }
     else if (GUI.Button(new Rect(10, 110, 120, 40), " + Click2"))
     {
         CallLuaFunction(AddClick2);
     }
     else if (GUI.Button(new Rect(10, 160, 120, 40), " - Click1"))
     {
         CallLuaFunction(RemoveClick1);
     }
     else if (GUI.Button(new Rect(10, 210, 120, 40), " - Click2"))
     {
         CallLuaFunction(RemoveClick2);
     }
     else if (GUI.Button(new Rect(10, 260, 120, 40), "+ Click1 in C#"))
     {
         LuaFunction func = state.GetFunction("DoClick1");
         TestEventListener.OnClick onClick = (TestEventListener.OnClick)DelegateFactory.CreateDelegate(typeof(TestEventListener.OnClick), func);
         listener.onClick += onClick;
     }
     else if (GUI.Button(new Rect(10, 310, 120, 40), " - Click1 in C#"))
     {
         LuaFunction func = state.GetFunction("DoClick1");
         listener.onClick = (TestEventListener.OnClick)DelegateFactory.RemoveDelegate(listener.onClick, func);
         func.Dispose();
         func = null;
     }
     else if (GUI.Button(new Rect(10, 360, 120, 40), "OnClick"))
     {
         if (listener.onClick != null)
         {
             listener.onClick(gameObject);
         }
         else
         {
             Debug.Log("empty delegate!!");
         }
     }
     else if (GUI.Button(new Rect(10, 410, 120, 40), "Override"))
     {
         CallLuaFunction(TestOverride);
     }
     else if (GUI.Button(new Rect(10, 460, 120, 40), "Force GC"))
     {
         //自动gc log: collect lua reference name , id xxx in thread
         state.LuaGC(LuaGCOptions.LUA_GCCOLLECT, 0);
         GC.Collect();
     }
     else if (GUI.Button(new Rect(10, 510, 120, 40), "event +"))
     {
         CallLuaFunction(AddEvent);
     }
     else if (GUI.Button(new Rect(10, 560, 120, 40), "event -"))
     {
         CallLuaFunction(RemoveEvent);
     }
     else if (GUI.Button(new Rect(10, 610, 120, 40), "event call"))
     {
         listener.OnClickEvent(gameObject);
     }
 }
示例#27
0
        public void PropertyGet_StaticByNonStaticName_ByTypes()
        {
            var pg = DelegateFactory.StaticPropertyGet <TestClass, string>("PublicProperty");

            Assert.IsNull(pg);
        }
示例#28
0
 protected virtual void Bind()
 {
     LuaBinder.Bind(luaState);
     DelegateFactory.Init();
     LuaCoroutine.Register(luaState, this);
 }
示例#29
0
 public void RemoveListener(GameEventCall call)
 {
     this.call -= call;
     DelegateFactory.RemoveDelegate(call);
 }
    void OnGUI()
    {
        if (GUI.Button(new Rect(10, 10, 120, 40), " = OnClick1"))
        {
            CallLuaFunction(SetClick1);
        }
        else if (GUI.Button(new Rect(10, 60, 120, 40), " + Click1"))
        {
            CallLuaFunction(AddClick1);
        }
        else if (GUI.Button(new Rect(10, 160, 120, 40), " - Click1"))
        {
            CallLuaFunction(RemoveClick1);
        }
        else if (GUI.Button(new Rect(10, 260, 120, 40), "+ Click1 in C#"))
        {
            LuaFunction func = state.GetFunction("DoClick1");
            TestEventListener.OnClick onClick = (TestEventListener.OnClick) DelegateTraits <TestEventListener.OnClick> .Create(func);

            listener.onClick += onClick;
        }
        else if (GUI.Button(new Rect(10, 310, 120, 40), " - Click1 in C#"))
        {
            LuaFunction func = state.GetFunction("DoClick1");
            listener.onClick = (TestEventListener.OnClick)DelegateFactory.RemoveDelegate(listener.onClick, func);
            func.Dispose();
            func = null;
        }
        else if (GUI.Button(new Rect(10, 360, 120, 40), "OnClick"))
        {
            if (listener.onClick != null)
            {
                listener.onClick(gameObject);
            }
            else
            {
                Debug.Log("empty delegate!!");
            }
        }
        else if (GUI.Button(new Rect(10, 410, 120, 40), "Override"))
        {
            CallLuaFunction(TestOverride);
        }
        else if (GUI.Button(new Rect(10, 510, 120, 40), "event +"))
        {
            CallLuaFunction(AddEvent);
        }
        else if (GUI.Button(new Rect(10, 560, 120, 40), "event -"))
        {
            CallLuaFunction(RemoveEvent);
        }
        else if (GUI.Button(new Rect(10, 610, 120, 40), "event call"))
        {
            listener.OnClickEvent(gameObject);
        }
        else if (GUI.Button(new Rect(200, 10, 120, 40), "+self call"))
        {
            CallLuaFunction(AddSelfClick);
        }
        else if (GUI.Button(new Rect(200, 60, 120, 40), "-self call"))
        {
            CallLuaFunction(RemoveSelfClick);
        }
    }
示例#31
0
        public void EventInvoke_ByTypes_NoEvent()
        {
            var call = DelegateFactory.EventInvoke <TestStruct, TestClass.PublicEventArgs>("PublicEvent");

            Assert.IsNull(call);
        }
    static int Create(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 5 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(int), typeof(int), typeof(int), typeof(bool)))
            {
                string arg0             = ToLua.ToString(L, 1);
                int    arg1             = (int)LuaDLL.lua_tonumber(L, 2);
                int    arg2             = (int)LuaDLL.lua_tonumber(L, 3);
                int    arg3             = (int)LuaDLL.lua_tonumber(L, 4);
                bool   arg4             = LuaDLL.lua_toboolean(L, 5);
                UnityEngine.AudioClip o = UnityEngine.AudioClip.Create(arg0, arg1, arg2, arg3, arg4);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 6 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(int), typeof(int), typeof(int), typeof(bool), typeof(UnityEngine.AudioClip.PCMReaderCallback)))
            {
                string arg0 = ToLua.ToString(L, 1);
                int    arg1 = (int)LuaDLL.lua_tonumber(L, 2);
                int    arg2 = (int)LuaDLL.lua_tonumber(L, 3);
                int    arg3 = (int)LuaDLL.lua_tonumber(L, 4);
                bool   arg4 = LuaDLL.lua_toboolean(L, 5);
                UnityEngine.AudioClip.PCMReaderCallback arg5 = null;
                LuaTypes funcType6 = LuaDLL.lua_type(L, 6);

                if (funcType6 != LuaTypes.LUA_TFUNCTION)
                {
                    arg5 = (UnityEngine.AudioClip.PCMReaderCallback)ToLua.ToObject(L, 6);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 6);
                    arg5 = DelegateFactory.CreateDelegate(typeof(UnityEngine.AudioClip.PCMReaderCallback), func) as UnityEngine.AudioClip.PCMReaderCallback;
                }

                UnityEngine.AudioClip o = UnityEngine.AudioClip.Create(arg0, arg1, arg2, arg3, arg4, arg5);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 7 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(int), typeof(int), typeof(int), typeof(bool), typeof(UnityEngine.AudioClip.PCMReaderCallback), typeof(UnityEngine.AudioClip.PCMSetPositionCallback)))
            {
                string arg0 = ToLua.ToString(L, 1);
                int    arg1 = (int)LuaDLL.lua_tonumber(L, 2);
                int    arg2 = (int)LuaDLL.lua_tonumber(L, 3);
                int    arg3 = (int)LuaDLL.lua_tonumber(L, 4);
                bool   arg4 = LuaDLL.lua_toboolean(L, 5);
                UnityEngine.AudioClip.PCMReaderCallback arg5 = null;
                LuaTypes funcType6 = LuaDLL.lua_type(L, 6);

                if (funcType6 != LuaTypes.LUA_TFUNCTION)
                {
                    arg5 = (UnityEngine.AudioClip.PCMReaderCallback)ToLua.ToObject(L, 6);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 6);
                    arg5 = DelegateFactory.CreateDelegate(typeof(UnityEngine.AudioClip.PCMReaderCallback), func) as UnityEngine.AudioClip.PCMReaderCallback;
                }

                UnityEngine.AudioClip.PCMSetPositionCallback arg6 = null;
                LuaTypes funcType7 = LuaDLL.lua_type(L, 7);

                if (funcType7 != LuaTypes.LUA_TFUNCTION)
                {
                    arg6 = (UnityEngine.AudioClip.PCMSetPositionCallback)ToLua.ToObject(L, 7);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 7);
                    arg6 = DelegateFactory.CreateDelegate(typeof(UnityEngine.AudioClip.PCMSetPositionCallback), func) as UnityEngine.AudioClip.PCMSetPositionCallback;
                }

                UnityEngine.AudioClip o = UnityEngine.AudioClip.Create(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
                ToLua.Push(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.AudioClip.Create"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
示例#33
0
        public void EventInvoke_ByTypes_WrongName()
        {
            var call = DelegateFactory.EventInvoke <TestClass, TestClass.PublicEventArgs>("WrongName");

            Assert.IsNull(call);
        }
示例#34
0
        public void PropertyGet_ByExtensionAndReturnType_NonExisting()
        {
            var spg = DelegateFactory.StaticPropertyGet <TestClass, string>("NonExisting");

            Assert.IsNull(spg);
        }
    static int _RepeatEveryFrame(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(Lit.Unity.LitBehaviour), typeof(int), typeof(Lit.Unity._D_Void)))
            {
                Lit.Unity.LitBehaviour obj = (Lit.Unity.LitBehaviour)ToLua.ToObject(L, 1);
                int arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                Lit.Unity._D_Void arg1      = null;
                LuaTypes          funcType3 = LuaDLL.lua_type(L, 3);

                if (funcType3 != LuaTypes.LUA_TFUNCTION)
                {
                    arg1 = (Lit.Unity._D_Void)ToLua.ToObject(L, 3);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 3);
                    arg1 = DelegateFactory.CreateDelegate(typeof(Lit.Unity._D_Void), func) as Lit.Unity._D_Void;
                }

                System.Collections.IEnumerator o = obj._RepeatEveryFrame(arg0, arg1);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(Lit.Unity.LitBehaviour), typeof(int), typeof(System.Action <int>), typeof(int)))
            {
                Lit.Unity.LitBehaviour obj = (Lit.Unity.LitBehaviour)ToLua.ToObject(L, 1);
                int arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                System.Action <int> arg1      = null;
                LuaTypes            funcType3 = LuaDLL.lua_type(L, 3);

                if (funcType3 != LuaTypes.LUA_TFUNCTION)
                {
                    arg1 = (System.Action <int>)ToLua.ToObject(L, 3);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 3);
                    arg1 = DelegateFactory.CreateDelegate(typeof(System.Action <int>), func) as System.Action <int>;
                }

                int arg2 = (int)LuaDLL.lua_tonumber(L, 4);
                System.Collections.IEnumerator o = obj._RepeatEveryFrame(arg0, arg1, arg2);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(Lit.Unity.LitBehaviour), typeof(int), typeof(System.Action), typeof(int)))
            {
                Lit.Unity.LitBehaviour obj = (Lit.Unity.LitBehaviour)ToLua.ToObject(L, 1);
                int           arg0         = (int)LuaDLL.lua_tonumber(L, 2);
                System.Action arg1         = null;
                LuaTypes      funcType3    = LuaDLL.lua_type(L, 3);

                if (funcType3 != LuaTypes.LUA_TFUNCTION)
                {
                    arg1 = (System.Action)ToLua.ToObject(L, 3);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 3);
                    arg1 = DelegateFactory.CreateDelegate(typeof(System.Action), func) as System.Action;
                }

                int arg2 = (int)LuaDLL.lua_tonumber(L, 4);
                System.Collections.IEnumerator o = obj._RepeatEveryFrame(arg0, arg1, arg2);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(Lit.Unity.LitBehaviour), typeof(int), typeof(Lit.Unity._D_Void), typeof(Lit.Unity._D_OuterBool)))
            {
                Lit.Unity.LitBehaviour obj = (Lit.Unity.LitBehaviour)ToLua.ToObject(L, 1);
                int arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                Lit.Unity._D_Void arg1      = null;
                LuaTypes          funcType3 = LuaDLL.lua_type(L, 3);

                if (funcType3 != LuaTypes.LUA_TFUNCTION)
                {
                    arg1 = (Lit.Unity._D_Void)ToLua.ToObject(L, 3);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 3);
                    arg1 = DelegateFactory.CreateDelegate(typeof(Lit.Unity._D_Void), func) as Lit.Unity._D_Void;
                }

                Lit.Unity._D_OuterBool arg2 = null;
                LuaTypes funcType4          = LuaDLL.lua_type(L, 4);

                if (funcType4 != LuaTypes.LUA_TFUNCTION)
                {
                    arg2 = (Lit.Unity._D_OuterBool)ToLua.ToObject(L, 4);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 4);
                    arg2 = DelegateFactory.CreateDelegate(typeof(Lit.Unity._D_OuterBool), func) as Lit.Unity._D_OuterBool;
                }

                System.Collections.IEnumerator o = obj._RepeatEveryFrame(arg0, arg1, arg2);
                ToLua.Push(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Lit.Unity.LitBehaviour._RepeatEveryFrame"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }