コード例 #1
0
        public ReflectBindingCallback(ScriptRuntime runtime)
        {
            _runtime = runtime;

            ReflectBindValueOp.Register <string>(Binding.Values.js_push_primitive, Binding.Values.js_get_primitive);
            ReflectBindValueOp.Register <bool>(Binding.Values.js_push_primitive, Binding.Values.js_get_primitive);
            ReflectBindValueOp.Register <char>(Binding.Values.js_push_primitive, Binding.Values.js_get_primitive);
            ReflectBindValueOp.Register <byte>(Binding.Values.js_push_primitive, Binding.Values.js_get_primitive);
            ReflectBindValueOp.Register <sbyte>(Binding.Values.js_push_primitive, Binding.Values.js_get_primitive);
            ReflectBindValueOp.Register <double>(Binding.Values.js_push_primitive, Binding.Values.js_get_primitive);
            ReflectBindValueOp.Register <float>(Binding.Values.js_push_primitive, Binding.Values.js_get_primitive);
            ReflectBindValueOp.Register <short>(Binding.Values.js_push_primitive, Binding.Values.js_get_primitive);
            ReflectBindValueOp.Register <ushort>(Binding.Values.js_push_primitive, Binding.Values.js_get_primitive);
            ReflectBindValueOp.Register <int>(Binding.Values.js_push_primitive, Binding.Values.js_get_primitive);
            ReflectBindValueOp.Register <uint>(Binding.Values.js_push_primitive, Binding.Values.js_get_primitive);
            ReflectBindValueOp.Register <long>(Binding.Values.js_push_primitive, Binding.Values.js_get_primitive);
            ReflectBindValueOp.Register <ulong>(Binding.Values.js_push_primitive, Binding.Values.js_get_primitive);
            ReflectBindValueOp.Register <DateTime>(Binding.Values.js_push_structvalue, Binding.Values.js_get_structvalue);

#if !JSB_UNITYLESS
            ReflectBindValueOp.Register <UnityEngine.Vector2>(Binding.Values.js_push_structvalue, Binding.Values.js_get_structvalue);
            ReflectBindValueOp.Register <UnityEngine.Vector2Int>(Binding.Values.js_push_structvalue, Binding.Values.js_get_structvalue);
            ReflectBindValueOp.Register <UnityEngine.Vector3>(Binding.Values.js_push_structvalue, Binding.Values.js_get_structvalue);
            ReflectBindValueOp.Register <UnityEngine.Vector3Int>(Binding.Values.js_push_structvalue, Binding.Values.js_get_structvalue);
            ReflectBindValueOp.Register <UnityEngine.Vector4>(Binding.Values.js_push_structvalue, Binding.Values.js_get_structvalue);
            ReflectBindValueOp.Register <UnityEngine.Rect>(Binding.Values.js_push_structvalue, Binding.Values.js_get_structvalue);
            ReflectBindValueOp.Register <UnityEngine.Quaternion>(Binding.Values.js_push_structvalue, Binding.Values.js_get_structvalue);
            ReflectBindValueOp.Register <UnityEngine.LayerMask>(Binding.Values.js_push_structvalue, Binding.Values.js_get_structvalue);
            ReflectBindValueOp.Register <UnityEngine.Ray>(Binding.Values.js_push_structvalue, Binding.Values.js_get_structvalue);
            ReflectBindValueOp.Register <UnityEngine.Color>(Binding.Values.js_push_structvalue, Binding.Values.js_get_structvalue);
            ReflectBindValueOp.Register <UnityEngine.Color32>(Binding.Values.js_push_structvalue, Binding.Values.js_get_structvalue);
            ReflectBindValueOp.Register <UnityEngine.Matrix4x4>(Binding.Values.js_push_structvalue, Binding.Values.js_get_structvalue);
#endif
        }
コード例 #2
0
        public static RT FuncCall <T1, RT>(ScriptDelegate fn, T1 a1)
        {
            if (!fn.isValid)
            {
                return(default(RT));
            }
            var ctx  = fn.ctx;
            var argv = stackalloc JSValue[1];

            argv[0] = ReflectBindValueOp.js_push_tvar <T1>(ctx, a1);
            if (argv[0].IsException())
            {
                throw new Exception(ctx.GetExceptionString());
            }
            var rval = fn.Invoke(ctx, 1, argv);

            if (rval.IsException())
            {
                JSApi.JS_FreeValue(ctx, argv[0]);
                throw new Exception(ctx.GetExceptionString());
            }
            RT  ret0;
            var succ = ReflectBindValueOp.js_get_tvar <RT>(ctx, rval, out ret0);

            JSApi.JS_FreeValue(ctx, rval);
            JSApi.JS_FreeValue(ctx, argv[0]);
            if (succ)
            {
                return(ret0);
            }
            else
            {
                throw new Exception("js exception caught");
            }
        }
コード例 #3
0
        public static void ActionCall <T1, T2>(ScriptDelegate fn, T1 a1, T2 a2)
        {
            if (!fn.isValid)
            {
                return;
            }
            var ctx  = fn.ctx;
            var argv = stackalloc JSValue[2];

            argv[0] = ReflectBindValueOp.js_push_tvar <T1>(ctx, a1);
            if (argv[0].IsException())
            {
                throw new Exception(ctx.GetExceptionString());
            }
            argv[1] = ReflectBindValueOp.js_push_tvar <T2>(ctx, a2);
            if (argv[1].IsException())
            {
                JSApi.JS_FreeValue(ctx, argv[0]);
                throw new Exception(ctx.GetExceptionString());
            }
            var rval = fn.Invoke(ctx, 2, argv);

            JSApi.JS_FreeValue(ctx, argv[0]);
            JSApi.JS_FreeValue(ctx, argv[1]);
            if (rval.IsException())
            {
                throw new Exception(ctx.GetExceptionString());
            }
            JSApi.JS_FreeValue(ctx, rval);
        }
コード例 #4
0
        public static RT FuncCall <RT>(ScriptDelegate fn)
        {
            if (!fn.isValid)
            {
                return(default(RT));
            }
            var ctx  = fn.ctx;
            var rval = fn.Invoke(ctx);

            if (rval.IsException())
            {
                throw new Exception(ctx.GetExceptionString());
            }
            RT  ret0;
            var succ = ReflectBindValueOp.js_get_tvar <RT>(ctx, rval, out ret0);

            JSApi.JS_FreeValue(ctx, rval);
            if (succ)
            {
                return(ret0);
            }
            else
            {
                throw new Exception("js exception caught");
            }
        }