示例#1
0
        /// <summary>
        /// Creates a static userdata DynValue from the specified IUserDataDescriptor
        /// </summary>
        /// <param name="descr">The IUserDataDescriptor</param>
        /// <returns></returns>
        public static DynValue CreateStatic(IUserDataDescriptor descr)
        {
            if (descr == null)
            {
                return(DynValue.Invalid);
            }

            var userData = UserDataRef.Request();

            userData.Descriptor = descr;
            return(DynValue.NewUserData(userData));
        }
示例#2
0
        static UserData()
        {
            RegistrationPolicy = InteropRegistrationPolicy.Default;

            RegisterType <EventFacade>(InteropAccessMode.NoReflectionAllowed);
            RegisterType <AnonWrapper>(InteropAccessMode.HideMembers);
            RegisterType <EnumerableWrapper>(InteropAccessMode.NoReflectionAllowed);
            RegisterType <JsonNull>(InteropAccessMode.Reflection);

            DefaultAccessMode = InteropAccessMode.LazyOptimized;

            new System.Threading.Thread(() => UserDataRef.WarnDynValueCache()).Start();
        }
示例#3
0
        /// <summary>
        /// Creates a userdata DynValue from the specified object, using a specific descriptor
        /// </summary>
        /// <param name="o">The object</param>
        /// <param name="descr">The descriptor.</param>
        /// <returns></returns>
        public static DynValue CreateWithDescriptor <T>(T o, IUserDataDescriptor descr)
        {
            IUserData userData;

            if (typeof(T).IsValueType)
            {
                userData = UserDataStruct <T> .Request();
            }
            else
            {
                userData = UserDataRef.Request();
            }
            userData.Descriptor = descr;
            userData.TrySet(o);

            return(DynValue.NewUserData(userData));
        }
示例#4
0
        public static UserDataRef Request()
        {
            UserDataRef ud;

            lock (_pool)
            {
                if (_pool.Count > 0)
                {
                    ud = _pool.Pop();
                    GC.ReRegisterForFinalize(ud);
                }
                else
                {
                    ud = new UserDataRef();
                    INSTANCE_AMOUNT++;
                }
            }
            return(ud);
        }