Ejemplo n.º 1
0
        public static bool duk_get_classvalue(IntPtr ctx, int idx, out IO.ByteBuffer o)
        {
            object obj;

            if (duk_get_cached_object(ctx, idx, out obj))
            {
                if (obj is IO.ByteBuffer)
                {
                    o = (IO.ByteBuffer)obj;
                    return(true);
                }
            }
            if (DuktapeDLL.duk_is_buffer_data(ctx, idx))
            {
                var allocator = DuktapeVM.GetVM(ctx).GetByteBufferAllocator();
                if (allocator != null)
                {
                    uint length;
                    var  pointer = DuktapeDLL.duk_unity_get_buffer_data(ctx, idx, out length);
                    o = allocator.Alloc((int)length);
                    allocator.AutoRelease(o);
                    o.WriteBytes(pointer, (int)length);
                    return(true);
                }
            }
            o = null;
            return(false);
        }
Ejemplo n.º 2
0
 public static bool duk_get_primitive_array(IntPtr ctx, int idx, out byte[] o)
 {
     if (DuktapeDLL.duk_is_array(ctx, idx))
     {
         var length = DuktapeDLL.duk_unity_get_length(ctx, idx);
         var nidx   = DuktapeDLL.duk_normalize_index(ctx, idx);
         o = new byte[length];
         for (var i = 0U; i < length; i++)
         {
             DuktapeDLL.duk_get_prop_index(ctx, idx, i);
             byte e;
             e    = (byte)DuktapeDLL.duk_get_int(ctx, -1); // duk_get_primitive(ctx, -1, out e);
             o[i] = e;
             DuktapeDLL.duk_pop(ctx);
         }
         return(true);
     }
     if (DuktapeDLL.duk_is_buffer_data(ctx, idx))
     {
         uint length;
         var  pointer = DuktapeDLL.duk_unity_get_buffer_data(ctx, idx, out length);
         o = new byte[length];
         Marshal.Copy(pointer, o, 0, (int)length);
         return(true);
     }
     duk_get_classvalue <byte[]>(ctx, idx, out o);
     return(true);
 }