/// <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); }
/// <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); }