コード例 #1
0
ファイル: LuaReaderProxy.cs プロジェクト: weimingtom/LuaN
        /// <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);
        }
コード例 #2
0
ファイル: LuaWriterProxy.cs プロジェクト: weimingtom/LuaN
        /// <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);
        }
コード例 #3
0
ファイル: LuaReaderProxy.cs プロジェクト: weimingtom/LuaN
        /// <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);
        }
コード例 #4
0
ファイル: LuaWriterProxy.cs プロジェクト: weimingtom/LuaN
        /// <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);
        }