示例#1
0
        public ClassDecl CreateClass(JSValue nsValue, string typename, Type type, IDynamicMethod dynamicMethod)
        {
            var       nameAtom = GetAtom(typename);
            JSContext ctx      = _context;
            var       protoVal = JSApi.JS_NewObject(ctx);
            var       type_id  = RegisterType(type, protoVal);
            var       ctorVal  = _db.NewDynamicMethod(nameAtom, dynamicMethod);
            var       decl     = new ClassDecl(this, ctorVal, protoVal, type);

            JSApi.JS_SetConstructor(ctx, ctorVal, protoVal);
            JSApi.JSB_SetBridgeType(ctx, ctorVal, type_id);
            if (!nsValue.IsNullish())
            {
                JSApi.JS_DefinePropertyValue(ctx, nsValue, nameAtom, ctorVal, JSPropFlags.JS_PROP_ENUMERABLE | JSPropFlags.JS_PROP_CONFIGURABLE);
            }
            else
            {
                JSApi.JS_FreeValue(ctx, ctorVal);
            }
            // UnityEngine.Debug.LogFormat("define class {0}: {1}", type, protoVal);
            JSApi.JS_FreeValue(ctx, protoVal);
            return(decl);
        }
示例#2
0
 public void RegisterOperator(Type type, string op, IDynamicMethod func)
 {
     RegisterOperator(type, op, _db.NewDynamicMethod(GetAtom(op), func));
 }