Exemple #1
0
        public Object Call5(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
        {
            if (numArgs != 5)
            {
                throw new InvalidOperationException();
            }

            CSHandleScope scope  = CSHandleScope.Create();
            Call5Delegate cfunc  = (Call5Delegate)func;
            GCHandle      gch1   = GCHandle.Alloc(arg1);
            GCHandle      gch2   = GCHandle.Alloc(arg2);
            GCHandle      gch3   = GCHandle.Alloc(arg3);
            GCHandle      gch4   = GCHandle.Alloc(arg4);
            GCHandle      gch5   = GCHandle.Alloc(arg5);
            object        result = HandleUtils.GetObjectFromIntPtr(cfunc(GCHandle.ToIntPtr(gch1),
                                                                         GCHandle.ToIntPtr(gch2), GCHandle.ToIntPtr(gch3), GCHandle.ToIntPtr(gch4), GCHandle.ToIntPtr(gch5)));

            scope.Destroy();
            gch1.Free();
            gch2.Free();
            gch3.Free();
            gch4.Free();
            gch5.Free();
            return(result);
        }
Exemple #2
0
        public object CallMult(Array args)
        {
            if (numArgs != -1)
            {
                throw new InvalidOperationException();
            }

            Array <object> hxArray = (Array <object>)args;
            CSHandleScope  scope   = CSHandleScope.Create();

            GCHandle[] handles = new GCHandle[hxArray.length];
            for (int i = 0; i < hxArray.length; ++i)
            {
                handles[i] = GCHandle.Alloc(hxArray[i]);
            }
            IntPtr[] pointers = new IntPtr[hxArray.length];
            for (int i = 0; i < hxArray.length; ++i)
            {
                pointers[i] = GCHandle.ToIntPtr(handles[i]);
            }
            GCHandle pinnedArray = GCHandle.Alloc(pointers, GCHandleType.Pinned);

            CallMultDelegate cfunc  = (CallMultDelegate)func;
            object           result = HandleUtils.GetObjectFromIntPtr(cfunc(pinnedArray.AddrOfPinnedObject()));

            scope.Destroy();
            for (int i = 0; i < hxArray.length; ++i)
            {
                handles[i].Free();
            }
            pinnedArray.Free();
            return(result);
        }
Exemple #3
0
        private static IntPtr cs_create_root(IntPtr inValue)
        {
            object   value  = HandleUtils.GetObjectFromIntPtr(inValue);
            GCHandle handle = GCHandle.Alloc(new CSPersistent(value));

            return(GCHandle.ToIntPtr(handle));
        }
Exemple #4
0
 private static void cs_buffer_set_size(IntPtr inBuffer, int inLen)
 {
     byte[] buffer = (byte[])HandleUtils.GetObjectFromIntPtr(inBuffer);
     if (buffer != null)
     {
         System.Array.Resize <byte>(ref buffer, inLen);
     }
 }
Exemple #5
0
        private static int cs_val_int(IntPtr inArg1)
        {
            object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1);

            if (arg1 == null)
            {
                return(0);
            }

            if (arg1 is sbyte)
            {
                return((sbyte)arg1);
            }
            else if (arg1 is byte)
            {
                return((byte)arg1);
            }
            else if (arg1 is short)
            {
                return((short)arg1);
            }
            else if (arg1 is ushort)
            {
                return((ushort)arg1);
            }
            else if (arg1 is int)
            {
                return((int)arg1);
            }
            else if (arg1 is uint)
            {
                return((int)(uint)arg1);
            }
            else if (arg1 is long)
            {
                return((int)(long)arg1);
            }
            else if (arg1 is ulong)
            {
                return((int)(ulong)arg1);
            }
            else if (arg1 is float)
            {
                return((int)(float)arg1);
            }
            else if (arg1 is double)
            {
                return((int)(double)arg1);
            }
            else if (arg1 is decimal)
            {
                decimal d = (decimal)arg1;
                return(decimal.ToInt32(d));
            }

            return(0);
        }
Exemple #6
0
        private static IntPtr cs_buffer_data(IntPtr inBuffer)
        {
            byte[] buffer = (byte[])HandleUtils.GetObjectFromIntPtr(inBuffer);
            if (buffer == null)
            {
                return(IntPtr.Zero);
            }

            return(CSHandleContainer.GetCurrent().GetAddrOfBlittableObject(buffer));
        }
Exemple #7
0
        private static int cs_buffer_size(IntPtr inBuffer)
        {
            byte[] buffer = (byte[])HandleUtils.GetObjectFromIntPtr(inBuffer);
            if (buffer == null)
            {
                return(0);
            }

            return(buffer.Length);
        }
Exemple #8
0
        private static IntPtr cs_val_data(IntPtr inArg1)
        {
            CSAbstract arg1 = (CSAbstract)HandleUtils.GetObjectFromIntPtr(inArg1);

            if (arg1 == null)
            {
                return(IntPtr.Zero);
            }

            return(arg1.Pointer);
        }
Exemple #9
0
        private static IntPtr cs_val_to_kind(IntPtr inArg1, int arg2)
        {
            CSAbstract arg1 = (CSAbstract)HandleUtils.GetObjectFromIntPtr(inArg1);

            if (arg1 == null)
            {
                return(IntPtr.Zero);
            }

            return(arg1.Kind == arg2 ? arg1.Pointer : IntPtr.Zero);
        }
Exemple #10
0
        private static bool cs_val_bool(IntPtr inArg1)
        {
            object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1);

            if (arg1 == null)
            {
                return(false);
            }

            return((bool)arg1);
        }
Exemple #11
0
        private static IntPtr cs_val_call0(IntPtr inArg1)
        {
            Function arg1 = (Function)HandleUtils.GetObjectFromIntPtr(inArg1);

            if (arg1 == null)
            {
                throw new ArgumentNullException("Null function call");
            }

            return(CSHandleContainer.GetCurrent().CreateGCHandle(arg1.__hx_invoke0_o()));
        }
Exemple #12
0
        private static int cs_val_strlen(IntPtr inArg1)
        {
            String arg1 = (String)HandleUtils.GetObjectFromIntPtr(inArg1);

            if (arg1 == null)
            {
                return(0);
            }

            return(Encoding.UTF8.GetByteCount(arg1));
        }
Exemple #13
0
        private static IntPtr cs_val_array_i(IntPtr inArg1, int arg2)
        {
            Array arg1 = (Array)HandleUtils.GetObjectFromIntPtr(inArg1);

            if (arg1 == null)
            {
                return(IntPtr.Zero);
            }

            return(CSHandleContainer.GetCurrent().CreateGCHandle(arg1[arg2]));
        }
Exemple #14
0
        private static void cs_val_gc(IntPtr inArg1, CSAbstract.FinalizerDelegate arg2)
        {
            CSAbstract arg1 = (CSAbstract)HandleUtils.GetObjectFromIntPtr(inArg1);

            if (arg1 == null)
            {
                return;
            }

            arg1.Finalizer = arg2;
        }
Exemple #15
0
        private static void cs_val_array_push(IntPtr inArg1, IntPtr inArg2)
        {
            Array <object> arg1 = (Array <object>)HandleUtils.GetObjectFromIntPtr(inArg1);
            object         arg2 = HandleUtils.GetObjectFromIntPtr(inArg2);

            if (arg1 == null)
            {
                return;
            }

            arg1.push(arg2);
        }
Exemple #16
0
        private static void cs_val_array_set_i(IntPtr inArg1, int arg2, IntPtr inArg3)
        {
            Array  arg1 = (Array)HandleUtils.GetObjectFromIntPtr(inArg1);
            object arg3 = HandleUtils.GetObjectFromIntPtr(inArg3);

            if (arg1 == null)
            {
                return;
            }

            arg1[arg2] = arg3;
        }
Exemple #17
0
        private static IntPtr cs_val_field(IntPtr inArg1, int arg2)
        {
            object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1);

            if (arg1 == null)
            {
                throw new ArgumentNullException("Null object get");
            }

            CSHandleContainer container = CSHandleContainer.GetCurrent();
            String            field     = container.GetStringFromId(arg2);

            return(container.CreateGCHandle(Reflect.field(arg1, field)));
        }
Exemple #18
0
        private static void cs_alloc_field(IntPtr inArg1, int arg2, IntPtr inArg3)
        {
            object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1);
            object arg3 = HandleUtils.GetObjectFromIntPtr(inArg3);

            if (arg1 == null)
            {
                throw new ArgumentNullException("Null object set");
            }

            String field = CSHandleContainer.GetCurrent().GetStringFromId(arg2);

            Reflect.setField(arg1, field, arg3);
        }
Exemple #19
0
        public object Call0()
        {
            if (numArgs != 0)
            {
                throw new InvalidOperationException();
            }

            CSHandleScope scope  = CSHandleScope.Create();
            Call0Delegate cfunc  = (Call0Delegate)func;
            object        result = HandleUtils.GetObjectFromIntPtr(cfunc());

            scope.Destroy();
            return(result);
        }
Exemple #20
0
        public object Call1(object arg1)
        {
            if (numArgs != 1)
            {
                throw new InvalidOperationException();
            }

            CSHandleScope scope  = CSHandleScope.Create();
            Call1Delegate cfunc  = (Call1Delegate)func;
            GCHandle      gch1   = GCHandle.Alloc(arg1);
            object        result = HandleUtils.GetObjectFromIntPtr(cfunc(GCHandle.ToIntPtr(gch1)));

            scope.Destroy();
            gch1.Free();
            return(result);
        }
Exemple #21
0
        private static int cs_val_array_size(IntPtr inArg1)
        {
            object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1);

            if (arg1 is Array <object> )
            {
                return(((Array <object>)arg1).length);
            }
            else if (arg1 is Array <bool> )
            {
                return(((Array <bool>)arg1).length);
            }
            else if (arg1 is Array <byte> )
            {
                return(((Array <byte>)arg1).length);
            }
            else if (arg1 is Array <sbyte> )
            {
                return(((Array <sbyte>)arg1).length);
            }
            else if (arg1 is Array <uint> )
            {
                return(((Array <uint>)arg1).length);
            }
            else if (arg1 is Array <int> )
            {
                return(((Array <int>)arg1).length);
            }
            else if (arg1 is Array <ulong> )
            {
                return(((Array <ulong>)arg1).length);
            }
            else if (arg1 is Array <long> )
            {
                return(((Array <long>)arg1).length);
            }
            else if (arg1 is Array <float> )
            {
                return(((Array <float>)arg1).length);
            }
            else if (arg1 is Array <double> )
            {
                return(((Array <double>)arg1).length);
            }

            return(0);
        }
Exemple #22
0
        private static IntPtr cs_val_string(IntPtr inArg1)
        {
            String arg1 = (String)HandleUtils.GetObjectFromIntPtr(inArg1);

            if (arg1 == null)
            {
                return(IntPtr.Zero);
            }

            CSHandleContainer container = CSHandleContainer.GetCurrent();

            byte[] bytes  = System.Text.Encoding.UTF8.GetBytes(arg1);
            IntPtr memory = container.AllocateMemory(sizeof(byte) * (bytes.Length + 1));

            Marshal.Copy(bytes, 0, memory, bytes.Length);
            Marshal.WriteByte(memory, bytes.Length, 0);
            return(memory);
        }
Exemple #23
0
        private static IntPtr cs_val_array_int(IntPtr inArg1)
        {
            Array arg1 = (Array)HandleUtils.GetObjectFromIntPtr(inArg1);

            if (arg1 == null)
            {
                return(IntPtr.Zero);
            }

            Array <int> intHxArray = arg1 as Array <int>;

            if (intHxArray != null)
            {
                return(CSHandleContainer.GetCurrent().GetAddrOfBlittableObject(intHxArray.__a));
            }

            return(IntPtr.Zero);
        }
Exemple #24
0
        private static void cs_val_gc(IntPtr inArg1, CSAbstract.FinalizerDelegate arg2)
        {
            object value = HandleUtils.GetObjectFromIntPtr(inArg1);

            if (value == null)
            {
                return;
            }

            if (value is CSAbstract)
            {
                CSAbstract arg1 = (CSAbstract)value;
                arg1.Finalizer = arg2;
            }
            else
            {
                // TODO
            }
        }
Exemple #25
0
        private static void cs_val_throw(IntPtr inArg1)
        {
            object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1);

            throw new Exception(arg1.ToString());
        }
Exemple #26
0
        private static void cs_free_abstract(IntPtr inArg1)
        {
            CSAbstract arg1 = (CSAbstract)HandleUtils.GetObjectFromIntPtr(inArg1);

            arg1.Free();
        }
Exemple #27
0
        private static int cs_val_type(IntPtr inArg1)
        {
            object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1);

            if (arg1 == null)
            {
                return((int)hxValueType.valtNull);
            }

            if (arg1 is Boolean)
            {
                return((int)hxValueType.valtBool);
            }
            else if (arg1 is sbyte ||
                     arg1 is byte ||
                     arg1 is short ||
                     arg1 is ushort ||
                     arg1 is int ||
                     arg1 is uint ||
                     arg1 is long ||
                     arg1 is ulong)
            {
                return((int)hxValueType.valtInt);
            }
            else if (arg1 is float ||
                     arg1 is double ||
                     arg1 is decimal)
            {
                return((int)hxValueType.valtFloat);
            }
            else if (arg1 is String)
            {
                return((int)hxValueType.valtString);
            }
            else if (arg1 is Array)
            {
                return((int)hxValueType.valtArray);
            }
            else if (arg1 is Function)
            {
                return((int)hxValueType.valtFunction);
            }
            else if (arg1.GetType().IsEnum)
            {
                return((int)hxValueType.valtEnum);
            }
            else if (arg1.GetType().IsClass)
            {
                return((int)hxValueType.valtClass);
            }
            else if (arg1 is DynamicObject)
            {
                return((int)hxValueType.valtObject);
            }
            else if (arg1 is CSAbstract)
            {
                return(((CSAbstract)arg1).Kind);
            }

            return((int)hxValueType.valtUnknown);
        }
Exemple #28
0
        private static IntPtr cs_query_root(IntPtr inValue)
        {
            CSPersistent persistent = (CSPersistent)HandleUtils.GetObjectFromIntPtr(inValue);

            return(CSHandleContainer.GetCurrent().CreateGCHandle(persistent.Value));
        }