/// <summary>Gets an event handler for the event type that delegates to the eventHandler Lua function. Caches the generated type.</summary>
        public LuaEventHandler GetEvent(Type eventHandlerType, LuaFunction eventHandler)
        {
            Type eventConsumerType;

            if (!eventHandlerCollection.TryGetValue(eventHandlerType, out eventConsumerType))
            {
                eventConsumerType = GenerateEvent(eventHandlerType);
                eventHandlerCollection[eventHandlerType] = eventConsumerType;
            }
            LuaEventHandler luaEventHandler = (LuaEventHandler)Activator.CreateInstance(eventConsumerType);

            luaEventHandler.handler = eventHandler;
            return(luaEventHandler);
        }
예제 #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);
        }
        /*
         * Gets an event handler for the event type that delegates to the eventHandler Lua function.
         * Caches the generated type.
         */
        public LuaEventHandler GetEvent(Type eventHandlerType, LuaFunction eventHandler)
        {
            Type eventConsumerType;

            if (eventHandlerCollection.ContainsKey(eventHandlerType))
            {
                eventConsumerType = eventHandlerCollection[eventHandlerType];
            }
            else
            {
                eventConsumerType = GenerateEvent(eventHandlerType);
                eventHandlerCollection[eventHandlerType] = eventConsumerType;
            }
            LuaEventHandler luaEventHandler = (LuaEventHandler)Activator.CreateInstance(eventConsumerType);

            luaEventHandler.handler = eventHandler;
            return(luaEventHandler);
        }
예제 #4
0
        public LuaEventHandler GetEvent(Type eventHandlerType, LuaFunction eventHandler)
        {
            Type type;

            if (this.eventHandlerCollection.ContainsKey(eventHandlerType))
            {
                type = this.eventHandlerCollection[eventHandlerType];
            }
            else
            {
                type = this.GenerateEvent(eventHandlerType);
                this.eventHandlerCollection[eventHandlerType] = type;
            }
            LuaEventHandler luaEventHandler = (LuaEventHandler)Activator.CreateInstance(type);

            luaEventHandler.handler = eventHandler;
            return(luaEventHandler);
        }
예제 #5
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);
        }