public static bool duk_get_type(IntPtr ctx, int idx, out Type o) { if (DuktapeDLL.duk_is_string(ctx, idx)) { var name = DuktapeDLL.duk_get_string(ctx, idx); o = DuktapeAux.GetType(name); return(o != null); } else { //TODO: 增加一个隐藏属性记录jsobject对应类型 (constructor, object) if (DuktapeDLL.duk_get_prop_string(ctx, idx, DuktapeVM.OBJ_PROP_EXPORTED_REFID)) { var vm = DuktapeVM.GetVM(ctx); var refid = DuktapeDLL.duk_get_uint(ctx, -1); DuktapeDLL.duk_pop(ctx); o = vm.GetExportedType(refid); // Debug.Log($"get type from exported registry {o}:{refid}"); return(o != null); } else if (DuktapeDLL.duk_get_prop_string(ctx, idx, DuktapeVM.OBJ_PROP_NATIVE)) { var cache = DuktapeVM.GetObjectCache(ctx); var refid = DuktapeDLL.duk_get_int(ctx, -1); DuktapeDLL.duk_pop(ctx); cache.TryGetTypedObject(refid, out o); // Debug.Log($"get type from objectcache registry {o}:{refid}"); return(o != null); } } o = null; return(false); }
public static bool duk_get_type(IntPtr ctx, int idx, out Type o) { if (DuktapeDLL.duk_is_string(ctx, idx)) { var name = DuktapeDLL.duk_get_string(ctx, idx); o = DuktapeAux.GetType(name); return(o != null); } else { uint refid_t; //TODO: 增加一个隐藏属性记录jsobject对应类型 (constructor, object) if (DuktapeDLL.duk_unity_get_type_refid(ctx, idx, out refid_t)) { var vm = DuktapeVM.GetVM(ctx); o = vm.GetExportedType(refid_t); // Debug.Log($"get type from exported registry {o}:{refid}"); return(o != null); } else { int refid; if (DuktapeDLL.duk_unity_get_refid(ctx, idx, out refid)) { var cache = DuktapeVM.GetObjectCache(ctx); cache.TryGetTypedObject(refid, out o); // Debug.Log($"get type from objectcache registry {o}:{refid}"); return(o != null); } } } o = null; return(false); }
public static int GetType(IntPtr ctx) { string name; duk_get_primitive(ctx, 0, out name); //TODO: type 缓存; 从 jsobject hidden property 中读 refid var type = DuktapeAux.GetType(name); duk_push_classvalue(ctx, type); return(1); }