GetObjectTypeById() public static method

public static GetObjectTypeById ( int tid ) : ScriptObjectType
tid int
return ScriptObjectType
        public static object Instantiate(IntPtr ptr, int tid)
        {
            Func <IntPtr, object> activator = null;

            if (TypeActivators.TryGetValue(tid, out activator))
            {
                return(activator(ptr));
            }
            // other hardcoded cases
            var ot = ScriptEngine.GetObjectTypeById(tid);

            if (ot.Name == "array")
            {
                if ((ot.SubTypeId & (int)asETypeIdFlags.asTYPEID_OBJHANDLE) != 0)
                {
                    return(new ScriptObjectHandleArray(ptr, ot.SubType));
                }
                else
                {
                    return(new ScriptObjectArray(ptr, ot.SubType));
                }
            }
            return(null);
        }
Beispiel #2
0
 public static object GetVariable(IntPtr ptr, int tid, object cached = null)
 {
     unsafe
     {
         if (tid == (int)asETypeIdFlags.asTYPEID_BOOL)
         {
             return(*(bool *)ptr);
         }
         if (tid == (int)asETypeIdFlags.asTYPEID_INT8)
         {
             return(*(sbyte *)ptr);
         }
         if (tid == (int)asETypeIdFlags.asTYPEID_UINT8)
         {
             return(*(byte *)ptr);
         }
         if (tid == (int)asETypeIdFlags.asTYPEID_INT16)
         {
             return(*(short *)ptr);
         }
         if (tid == (int)asETypeIdFlags.asTYPEID_UINT16)
         {
             return(*(ushort *)ptr);
         }
         if (tid == (int)asETypeIdFlags.asTYPEID_INT32)
         {
             return(*(int *)ptr);
         }
         if (tid == (int)asETypeIdFlags.asTYPEID_UINT32)
         {
             return(*(uint *)ptr);
         }
         if (tid == (int)asETypeIdFlags.asTYPEID_INT64)
         {
             return(*(long *)ptr);
         }
         if (tid == (int)asETypeIdFlags.asTYPEID_UINT64)
         {
             return(*(ulong *)ptr);
         }
         if (tid == (int)asETypeIdFlags.asTYPEID_FLOAT)
         {
             return(*(float *)ptr);
         }
         if (tid == (int)asETypeIdFlags.asTYPEID_DOUBLE)
         {
             return(*(double *)ptr);
         }
         if ((tid & (int)asETypeIdFlags.asTYPEID_OBJHANDLE) != 0)
         {
             unsafe { return(GetVariable(*(IntPtr *)ptr.ToPointer(), tid ^ (int)asETypeIdFlags.asTYPEID_OBJHANDLE)); }
         }
         // once we handled value types, let's check if we've got an instance cached already
         if (cached != null)
         {
             return(cached);
         }
         // try some predefined types we can handle using our 'static' counterparts
         var obj = ScriptObjectType.Instantiate(ptr, tid);
         if (obj != null)
         {
             return(obj);
         }
         else if ((tid & (int)asETypeIdFlags.asTYPEID_SCRIPTOBJECT) != 0 ||
                  (tid & (int)asETypeIdFlags.asTYPEID_APPOBJECT) != 0)
         {
             return(new ScriptObject(ptr, ScriptEngine.GetObjectTypeById(tid)));                    // just handle it dynamically
         }
         else
         {
             throw new InvalidOperationException("Cannot handle type with id: " + tid);
         }
     }
 }
Beispiel #3
0
        public object GetResult(int ret_tid)
        {
            if (ret_tid == (int)asETypeIdFlags.asTYPEID_VOID)
            {
                return(null); // ?
            }
            if (ret_tid == (int)asETypeIdFlags.asTYPEID_BOOL)
            {
                return(GetReturnByte() != 0);
            }
            if (ret_tid == (int)asETypeIdFlags.asTYPEID_INT8 || ret_tid == (int)asETypeIdFlags.asTYPEID_UINT8)
            {
                return(GetReturnByte());
            }
            if (ret_tid == (int)asETypeIdFlags.asTYPEID_INT16 || ret_tid == (int)asETypeIdFlags.asTYPEID_UINT16)
            {
                return(GetReturnWord());
            }
            if (ret_tid == (int)asETypeIdFlags.asTYPEID_INT32 || ret_tid == (int)asETypeIdFlags.asTYPEID_UINT32)
            {
                return(GetReturnDWord());
            }
            if (ret_tid == (int)asETypeIdFlags.asTYPEID_INT64 || ret_tid == (int)asETypeIdFlags.asTYPEID_UINT64)
            {
                return(GetReturnQWord());
            }
            if (ret_tid == (int)asETypeIdFlags.asTYPEID_FLOAT)
            {
                return(GetReturnFloat());
            }
            if (ret_tid == (int)asETypeIdFlags.asTYPEID_DOUBLE)
            {
                return(GetReturnDouble());
            }
            // try some predefined types we can handle using our 'static' counterparts
            IntPtr ptr;

            if ((ret_tid & (int)asETypeIdFlags.asTYPEID_OBJHANDLE) != 0)
            {
                ptr = GetReturnObject();
            }
            else
            {
                ptr = GetReturnAddress();
            }
            if (ptr == IntPtr.Zero)
            {
                return(null);
            }
            try
            {
                var obj = ScriptObjectType.Instantiate(ptr, ret_tid);
                if (obj != null)
                {
                    return(obj);
                }
                else
                {
                    // just handle it dynamically
                    return(new ScriptObject(ptr, ScriptEngine.GetObjectTypeById(ret_tid)));
                }
            }
            finally
            {
                if ((ret_tid & (int)asETypeIdFlags.asTYPEID_OBJHANDLE) != 0)
                {
                    // decrease refcounter, we want only newly created wrapper to hold reference
                    ScriptEngine.ReleaseScriptObject(ptr, ret_tid);
                } // otherwise, it's reference
            }
        }