Esempio n. 1
0
        public EventProxyCodeGen(CodeGenerator cg, EventBindingInfo eventBindingInfo)
        {
            this.cg = cg;
            this.eventBindingInfo = eventBindingInfo;

            var eventInfo     = this.eventBindingInfo.eventInfo;
            var declaringType = eventInfo.DeclaringType;
            var tsFieldVar    = BindingManager.GetTSVariable(eventBindingInfo.regName);

            // this.cg.cs.AppendLine("DuktapeDLL.duk_push_this(ctx);");
            this.cg.cs.AppendLine($"duk_add_event_instanced(ctx, \"{tsFieldVar}\", {this.eventBindingInfo.adderName}, {this.eventBindingInfo.removerName}, -1);");
            this.cg.cs.AppendLine("DuktapeDLL.duk_remove(ctx, -2);");
            this.cg.cs.AppendLine("return 1;");
        }
Esempio n. 2
0
        public string AppendGetThisCS(EventBindingInfo bindingInfo)
        {
            var isStatic      = bindingInfo.isStatic;
            var declaringType = bindingInfo.declaringType;
            var caller        = "";

            if (isStatic)
            {
                caller = this.bindingManager.GetCSTypeFullName(declaringType, false);
            }
            else
            {
                caller = "self";
                this.cs.AppendLine($"{this.bindingManager.GetCSTypeFullName(declaringType)} {caller};");
                // this.cs.AppendLine($"DuktapeDLL.duk_push_this(ctx);");
                var getter = this.bindingManager.GetScriptObjectGetter(declaringType, "ctx", "this_obj", caller);
                this.cs.AppendLine("{0};", getter);
                // this.cs.AppendLine($"DuktapeDLL.duk_pop(ctx);");
            }
            return(caller);
        }
Esempio n. 3
0
        public EventRemoverCodeGen(CodeGenerator cg, EventBindingInfo bindingInfo)
        {
            this.cg          = cg;
            this.bindingInfo = bindingInfo;

            var eventInfo     = this.bindingInfo.eventInfo;
            var declaringType = eventInfo.DeclaringType;

            var caller = this.cg.AppendGetThisCS(bindingInfo);

            this.cg.cs.AppendLine("{0} value;", this.cg.bindingManager.GetCSTypeFullName(eventInfo.EventHandlerType));
            var getter = this.cg.bindingManager.GetScriptObjectGetter(eventInfo.EventHandlerType, "ctx", "argv[0]", "value");

            this.cg.cs.AppendLine("{0};", getter);
            this.cg.cs.AppendLine("{0}.{1} -= value;", caller, eventInfo.Name);
            if (declaringType.IsValueType && !eventInfo.GetAddMethod().IsStatic)
            {
                // 非静态结构体属性修改, 尝试替换实例
                this.cg.cs.AppendLine($"js_rebind_this(ctx, this_obj, {caller});");
            }
            this.cg.cs.AppendLine("return 0;");
        }