コード例 #1
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);
        }
コード例 #2
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);
        }