Exemple #1
0
        static int _m_TryGetBuffer(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                System.IO.MemoryStream gen_to_be_invoked = (System.IO.MemoryStream)translator.FastGetCSObj(L, 1);



                {
                    System.ArraySegment <byte> _buffer;

                    bool gen_ret = gen_to_be_invoked.TryGetBuffer(out _buffer);
                    LuaAPI.lua_pushboolean(L, gen_ret);
                    translator.Push(L, _buffer);



                    return(2);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Exemple #2
0
 public static ArraySegment <Byte> ToArraySegment(this System.IO.MemoryStream m)
 {
     if (m.TryGetBuffer(out ArraySegment <Byte> data))
     {
         return(data);
     }
     return(new ArraySegment <byte>(m.ToArray()));
 }
Exemple #3
0
        public static Memory <Byte> ReadBytesToEnd(this System.IO.Stream s)
        {
            using (var m = new System.IO.MemoryStream())
            {
                s.CopyTo(m);

                if (m.TryGetBuffer(out ArraySegment <Byte> segment))
                {
                    return(segment);
                }

                return(m.ToArray());
            }
        }
Exemple #4
0
        private ArraySegment <Byte> _ReadAsset(string filePath)
        {
            System.IO.Compression.ZipArchiveEntry entry = _FindEntry(filePath);

            using (var s = entry.Open())
            {
                using (var m = new System.IO.MemoryStream())
                {
                    s.CopyTo(m);

                    if (m.TryGetBuffer(out ArraySegment <Byte> data))
                    {
                        return(data);
                    }
                    else
                    {
                        return(new ArraySegment <byte>(m.ToArray()));
                    }
                }
            }
        }
Exemple #5
0
        static StackObject *TryGetBuffer_6(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.ArraySegment <System.Byte> @buffer = (System.ArraySegment <System.Byte>) typeof(System.ArraySegment <System.Byte>).CheckCLRTypes(__intp.RetriveObject(ptr_of_this_method, __mStack));

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.IO.MemoryStream instance_of_this_method = (System.IO.MemoryStream) typeof(System.IO.MemoryStream).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));

            var result_of_this_method = instance_of_this_method.TryGetBuffer(out @buffer);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            switch (ptr_of_this_method->ObjectType)
            {
            case ObjectTypes.StackObjectReference:
            {
                var    ___dst = ILIntepreter.ResolveReference(ptr_of_this_method);
                object ___obj = @buffer;
                if (___dst->ObjectType >= ObjectTypes.Object)
                {
                    if (___obj is CrossBindingAdaptorType)
                    {
                        ___obj = ((CrossBindingAdaptorType)___obj).ILInstance;
                    }
                    __mStack[___dst->Value] = ___obj;
                }
                else
                {
                    ILIntepreter.UnboxObject(___dst, ___obj, __mStack, __domain);
                }
            }
            break;

            case ObjectTypes.FieldReference:
            {
                var ___obj = __mStack[ptr_of_this_method->Value];
                if (___obj is ILTypeInstance)
                {
                    ((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = @buffer;
                }
                else
                {
                    var ___type = __domain.GetType(___obj.GetType()) as CLRType;
                    ___type.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, @buffer);
                }
            }
            break;

            case ObjectTypes.StaticFieldReference:
            {
                var ___type = __domain.GetType(ptr_of_this_method->Value);
                if (___type is ILType)
                {
                    ((ILType)___type).StaticInstance[ptr_of_this_method->ValueLow] = @buffer;
                }
                else
                {
                    ((CLRType)___type).SetStaticFieldValue(ptr_of_this_method->ValueLow, @buffer);
                }
            }
            break;

            case ObjectTypes.ArrayReference:
            {
                var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as System.ArraySegment <System.Byte>[];
                instance_of_arrayReference[ptr_of_this_method->ValueLow] = @buffer;
            }
            break;
            }

            __intp.Free(ptr_of_this_method);
            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            __intp.Free(ptr_of_this_method);
            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method ? 1 : 0;
            return(__ret + 1);
        }