Ejemplo n.º 1
0
        /*
         * Adds a new event handler
         */
        public Delegate Add(LuaFunction function)
        {
#if __NOGEN__
            //translator.throwError(luaState,"Delegates not implemnented");
            return(null);
#else
            //CP: Fix by Ben Bryant for event handling with one parameter
            //link: http://luaforge.net/forum/message.php?msg_id=9266
            Delegate handlerDelegate = CodeGeneration.Instance.GetDelegate(eventInfo.EventHandlerType, function);
            eventInfo.AddEventHandler(target, handlerDelegate);
            pendingEvents.Add(handlerDelegate, this);

            return(handlerDelegate);
#endif


            //MethodInfo mi = eventInfo.EventHandlerType.GetMethod("Invoke");
            //ParameterInfo[] pi = mi.GetParameters();
            //LuaEventHandler handler=CodeGeneration.Instance.GetEvent(pi[1].ParameterType,function);

            //Delegate handlerDelegate=Delegate.CreateDelegate(eventInfo.EventHandlerType,handler,"HandleEvent");
            //eventInfo.AddEventHandler(target,handlerDelegate);
            //pendingEvents.Add(handlerDelegate, this);

            //return handlerDelegate;
        }
Ejemplo n.º 2
0
        /*
         * Adds a new event handler
         */
        public Delegate Add(LuaFunction function)
        {
            MethodInfo mi = eventInfo.EventHandlerType.GetMethod("Invoke");

            ParameterInfo[] pi      = mi.GetParameters();
            LuaEventHandler handler = CodeGeneration.Instance.GetEvent(pi[1].ParameterType, function);

            Delegate handlerDelegate = Delegate.CreateDelegate(eventInfo.EventHandlerType, handler, "HandleEvent");

            eventInfo.AddEventHandler(target, handlerDelegate);
            pendingEvents.Add(handlerDelegate, this);

            return(handlerDelegate);
        }
Ejemplo n.º 3
0
        /// <summary>Adds a new event handler</summary>
        public Delegate Add(LuaFunction function)
        {
#if __NOGEN__
            //throw new NotSupportedException(L,"Delegates not implemented");
            return(null);
#else
            //CP: Fix by Ben Bryant for event handling with one parameter
            //link: http://luaforge.net/forum/message.php?msg_id=9266
            Delegate handlerDelegate = CodeGeneration.Instance.GetDelegate(eventInfo.EventHandlerType, function);
            eventInfo.AddEventHandler(target, handlerDelegate);
            pendingEvents.Add(handlerDelegate, this);

            return(handlerDelegate);
#endif
        }
Ejemplo n.º 4
0
        /*
         * Adds a new event handler
         */
        public Delegate Add(LuaFunction function)
        {
            MethodInfo mi = eventInfo.EventHandlerType.GetMethod("Invoke");

            ParameterInfo[] pi = mi.GetParameters();

            Type[] paramTypes = new Type[pi.Length];
            for (int i = 0; i < paramTypes.Length; ++i)
            {
                paramTypes[i] = pi[i].ParameterType;
            }

            LuaEventHandler handler = CodeGeneration.Instance.GetEvent(paramTypes, function);

            Delegate handlerDelegate = Delegate.CreateDelegate(eventInfo.EventHandlerType, handler, "HandleEvent");

            eventInfo.AddEventHandler(target, handlerDelegate);
            pendingEvents.Add(handlerDelegate, this);

            return(handlerDelegate);
        }