Exposes the functionality of asIObjectType implementation.
Ejemplo n.º 1
0
 public static ScriptObjectType GetObjectTypeById(int tid)
 {
     ScriptObjectType ot = null;
     if(!ObjectTypes.TryGetValue(tid, out ot))
     {
         var ptr = ScriptEngine_GetObjectTypeById(tid);
         if(ptr != IntPtr.Zero)
             ObjectTypes[tid] = ot = new ScriptObjectType(ptr);
     }
     return ot;
 }
Ejemplo n.º 2
0
 public ScriptObject(IntPtr ptr, ScriptObjectType ot, bool valuetype = false)
 {
     //if(valuetype)
     //   throw new NotImplementedException("Value type wrappers are not implemented.");
     this.thisptr    = ptr;
     this.objectType = ot;
     this.valuetype  = valuetype;
     if (!valuetype)
     {
         AddRef();
     }
 }
        public static ScriptObjectType GetObjectTypeById(int tid)
        {
            ScriptObjectType ot = null;

            if (!ObjectTypes.TryGetValue(tid, out ot))
            {
                var ptr = ScriptEngine_GetObjectTypeById(tid);
                if (ptr != IntPtr.Zero)
                {
                    ObjectTypes[tid] = ot = new ScriptObjectType(ptr);
                }
            }
            return(ot);
        }
Ejemplo n.º 4
0
 // only wrapper
 public ScriptObjectHandleArray(IntPtr ptr, ScriptObjectType sub_type)
     : base(ptr, true)
 {
     this.subType = sub_type;
 }
Ejemplo n.º 5
0
 public ScriptObject(ScriptObjectType ot)
 {
     this.thisptr    = ScriptEngine.CreateScriptObject(ot);
     this.objectType = ot;
 }
Ejemplo n.º 6
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);
         }
     }
 }
 public static ScriptObject CreateScriptObjectCopy(IntPtr ptr, ScriptObjectType ot)
 {
     return(new ScriptObject(ScriptEngine_CreateScriptObjectCopy(ptr, ot.TypeId), ot));
 }
 public static IntPtr CreateScriptObject(ScriptObjectType ot)
 {
     return(ScriptEngine_CreateScriptObject(ot.TypeId));
 }
Ejemplo n.º 9
0
 public static ScriptObject CreateScriptObjectCopy(IntPtr ptr, ScriptObjectType ot)
 {
     return new ScriptObject(ScriptEngine_CreateScriptObjectCopy(ptr, ot.TypeId), ot);
 }
Ejemplo n.º 10
0
 public static IntPtr CreateScriptObject(ScriptObjectType ot)
 {
     return ScriptEngine_CreateScriptObject(ot.TypeId);
 }
Ejemplo n.º 11
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
            }
        }