Пример #1
0
        private static void GetEvent(Assembly a, ClassDescription result, ScriptableClass sc)
        {
            result.Events = new List<EventDescription>();
            foreach (ScriptableEvent se in sc.Event)
            {
                EventInfo ei = result.Class.GetEvent(se.Name);
                if (null != ei)
                {
                    EventDescription ed = new EventDescription();
                    ed.Ei = ei;
                    ed.RawType = ei.GetType();
                    ed.TypeName = GeneratorHelper.GetTypeName(ei.GetType());
                    ed.IsStatic = true;

                    if (ei.GetAddMethod() != null)
                    {
                        ed.IsStatic = false;
                        ed.AddMethod = new MethodDescription();
                        GetMethod(ed.AddMethod,ei.GetAddMethod(), string.Empty,ei.Name);
                    }
                    if (ei.GetRemoveMethod() != null)
                    {
                        ed.IsStatic = false;
                        ed.RemoveMethod = new MethodDescription();
                        GetMethod(ed.RemoveMethod, ei.GetRemoveMethod(), string.Empty, ei.Name);
                    }
                    result.Events.Add(ed);
                }
                else
                {
                    Console.WriteLine(string.Format("event {0} not found", se.Name));
                }
            }
        }
Пример #2
0
        private static void GenerateEvent(ClassDescription cd, EventDescription ed, Lua4NetSerializer serializer)
        {
            #region add
            {
                serializer.NewLine();
                string methodName = ed.Ei.GetAddMethod().Name;
                string funcdef = string.Format("private static int {0}({1} Instance,IntPtr l)", methodName, cd.ClassName);
                GeneratorHelper.GenerateCSFunction(funcdef, serializer, s =>
                {
                    string classOrInstance = ed.IsStatic ? cd.ClassName : "Instance";
                    serializer.NewLine(string.Format("{0}Delegate d = new {0}Delegate(3,l);", ed.Ei.Name));
                    serializer.NewLine(string.Format("{0}.{1} += d.Call;",classOrInstance,ed.Ei.Name));
                    serializer.NewLine("int id = LuaManager.Instance.PushStackObject(d);");
                    serializer.NewLine("LuaApi.lua_pushnumber(l,id);");
                    serializer.NewLine("return 1;");
                });
            }
            #endregion

            #region remove
            {
                serializer.NewLine();
                string methodName = ed.Ei.GetRemoveMethod().Name;
                string funcdef = string.Format("private static int {0}({1} Instance,IntPtr l)", methodName, cd.ClassName);
                GeneratorHelper.GenerateCSFunction(funcdef, serializer, s =>
                {
                    serializer.NewLine("int id = (int)LuaApi.lua_tonumber(l,3);");
                    serializer.NewLine(string.Format("{0}Delegate d = LuaManager.Instance.GetObjectT<{0}Delegate>(id);", ed.Ei.Name));
                    serializer.NewLine("if(null != d)");
                    serializer.BeginBlock("{");
                        serializer.NewLine(string.Format("Instance.{0} -= d.Call;", ed.Ei.Name));
                    serializer.EndBlock("}");
                    serializer.NewLine("return 0;");
                });
            }
            #endregion
        }
Пример #3
0
        private static void GetEvent(Assembly a, ClassDescription result, Type type)
        {
            result.Events = new List<EventDescription>();
            foreach (EventInfo ei in type.GetEvents())
            {
                ScriptableAttribute attr = GetAttribute(ei);
                if (null != attr)
                {
                    EventDescription ed = new EventDescription();
                    ed.Ei = ei;
                    ed.RawType = ei.GetType();
                    ed.TypeName = GeneratorHelper.GetTypeName(ei.GetType());
                    ed.IsStatic = true;

                    if (ei.GetAddMethod() != null)
                    {
                        ed.IsStatic = false;
                        ed.AddMethod = new MethodDescription();
                        GetMethod(ed.AddMethod, ei.GetAddMethod(), string.Empty, ei.Name);
                    }
                    if (ei.GetRemoveMethod() != null)
                    {
                        ed.IsStatic = false;
                        ed.RemoveMethod = new MethodDescription();
                        GetMethod(ed.RemoveMethod, ei.GetRemoveMethod(), string.Empty, ei.Name);
                    }
                    result.Events.Add(ed);
                }
            }
        }