Esempio n. 1
0
        /// <summary>
        /// Lua reader to invoke the reader
        /// </summary>
        IntPtr InvokeManagementReader(IntPtr state, IntPtr ud, ref UInt32 sz)
        {
            if (_LastReadBuffer != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(_LastReadBuffer);
                _LastReadBuffer     = IntPtr.Zero;
                _LastReadBufferSize = 0;
            }
            LuaState ls = LuaState.FindState(state);

            if (ManagedReader != null && ls != null)
            {
                var res = ManagedReader(ls, UserDataRef.GetData(ud));
                if (res != null && res.Length > 0)
                {
                    sz = (UInt32)res.Length;
                    _LastReadBuffer     = Marshal.AllocHGlobal((int)sz);
                    _LastReadBufferSize = sz;
                    Marshal.Copy(res, 0, _LastReadBuffer, (int)sz);
                    return(_LastReadBuffer);
                }
            }
            sz = 0;
            return(IntPtr.Zero);
        }
Esempio n. 2
0
        /// <summary>
        /// Lua writer to invoke the Writer
        /// </summary>
        int InvokeManagementWriter(IntPtr state, IntPtr ptr, UInt32 sz, IntPtr ud)
        {
            LuaState ls = LuaState.FindState(state);

            if (ManagedWriter != null && ls != null)
            {
                Byte[] buffer = ptr != IntPtr.Zero ? new Byte[sz] : null;
                if (ptr != IntPtr.Zero)
                {
                    Marshal.Copy(ptr, buffer, 0, (int)sz);
                }
                var res = ManagedWriter(ls, buffer, UserDataRef.GetData(ud));
                buffer = null;
                return(res);
            }
            return(0);
        }
Esempio n. 3
0
        /// <summary>
        /// Readder to invoke the lua reader
        /// </summary>
        Byte[] InvokeUnmanagedReader(ILuaState state, Object ud)
        {
            LuaState ls = state as LuaState;

            if (UnmanagedReader != null && ls != null)
            {
                UInt32 sz  = 0;
                var    res = UnmanagedReader(ls.NativeState, UserDataRef.GetRef(ud), ref sz);
                if (sz <= 0 || res == IntPtr.Zero)
                {
                    return(null);
                }
                Byte[] buffer = new Byte[sz];
                Marshal.Copy(res, buffer, 0, (int)sz);
                return(buffer);
            }
            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Reader to invoke the lua Writer
        /// </summary>
        int InvokeUnmanagedWriter(ILuaState state, Byte[] p, Object ud)
        {
            LuaState ls = state as LuaState;

            if (UnmanagedWriter != null && ls != null)
            {
                int res = 0;
                if (p != null)
                {
                    var ptr = Marshal.AllocHGlobal(p.Length);
                    Marshal.Copy(p, 0, ptr, p.Length);
                    res = UnmanagedWriter(ls.NativeState, ptr, (UInt32)p.Length, UserDataRef.GetRef(ud));
                    Marshal.FreeHGlobal(ptr);
                }
                else
                {
                    res = UnmanagedWriter(ls.NativeState, IntPtr.Zero, 0, UserDataRef.GetRef(ud));
                }
                return(res);
            }
            return(0);
        }