예제 #1
0
        public override JSValue Invoke(JSContext ctx, JSValue this_obj, int argc, JSValue[] argv)
        {
            if (!_ctor.IsPublic && !_type.privateAccess)
            {
                return(JSApi.JS_ThrowInternalError(ctx, "constructor is inaccessible due to its protection level"));
            }

            var parameters = _ctor.GetParameters();
            var nArgs      = argc;
            var args       = new object[nArgs];

            for (var i = 0; i < nArgs; i++)
            {
                if (!Values.js_get_var(ctx, argv[i], parameters[i].ParameterType, out args[i]))
                {
                    return(JSApi.JS_ThrowInternalError(ctx, "failed to cast val"));
                }
            }

            if (_crossbind)
            {
                UnityEngine.Debug.LogFormat($"_js_crossbind_constructor {_type}");
                return(Values._js_crossbind_constructor(ctx, this_obj));
            }

            var inst = _ctor.Invoke(args);
            var val  = Values.NewBridgeClassObject(ctx, this_obj, inst, _type.id, false);

            return(val);
        }
예제 #2
0
        public override JSValue Invoke(JSContext ctx, JSValue this_obj, int argc, JSValue[] argv)
        {
            var inst = Activator.CreateInstance(_type.type);
            var val  = Values.NewBridgeClassObject(ctx, this_obj, inst, _type.id, false);

            return(val);
        }