/// <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)); }
public static UserDataStruct <T> Request() { UserDataStruct <T> ud; lock (_pool) { if (_pool.Count > 0) { ud = _pool.Pop(); GC.ReRegisterForFinalize(ud); } else { ud = new UserDataStruct <T>(); INSTANCE_AMOUNT++; } } return(ud); }
static UserDataStruct() { new System.Threading.Thread(() => UserDataStruct <T> .WarnDynValueCache()).Start(); }