Example #1
0
    static int _CreateFramework_NetModule_LuaBuffer(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("Framework.NetModule.LuaBuffer.ctor");
#endif
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                Framework.NetModule.LuaBuffer obj = new Framework.NetModule.LuaBuffer();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 1)
            {
                byte[] arg0 = ToLua.CheckByteBuffer(L, 1);
                Framework.NetModule.LuaBuffer obj = new Framework.NetModule.LuaBuffer(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: Framework.NetModule.LuaBuffer.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #2
0
 public void Send(int id, LuaBuffer buffer)
 {
     try
     {
         _session.Send(id, buffer);
     }
     catch (Exception e)
     {
         LogHelper.PrintError($"[NetMgr]Send {e} error.");
         _session.Dispose();
     }
 }
Example #3
0
        public void Send(int id, LuaBuffer buffer)
        {
            if (_socket == null)
            {
                var errorMessage = "session not initialize.";
                if (ErrorHandler != null)
                {
                    ErrorHandler(this, SessionErrorCode.StateError, errorMessage);
                    return;
                }
                throw new Exception(errorMessage);
            }
            var bufferBytes = buffer.ToBytes();

            if (bufferBytes == null)
            {
                var errorMessage = "luaBuff is null.";
                if (ErrorHandler != null)
                {
                    ErrorHandler(this, SessionErrorCode.StateError, errorMessage);
                    return;
                }
                throw new Exception(errorMessage);
            }
            try
            {
                var length       = 0;
                var packetLength = 0;
                var packetBuffer = new byte[_defaultMaxPacketLength];//TODO:内存池;
                using (var memoryStream = new MemoryStream(packetBuffer, true))
                {
                    memoryStream.Seek(_defaultPacketLength, SeekOrigin.Begin);
                    var idBytes = ConvertHelper.GetBytes(id);
                    memoryStream.Write(idBytes, 0, idBytes.Length);
                    memoryStream.Write(bufferBytes, 0, bufferBytes.Length);
                    length = (int)memoryStream.Position;
                }
                packetLength = length - _defaultPacketLength;
                ConvertHelper.GetBytes(packetLength).CopyTo(packetBuffer, 0);
                Send(packetBuffer, 0, length);
            }
            catch (Exception exception)
            {
                Active = false;
                if (ErrorHandler != null)
                {
                    ErrorHandler(this, SessionErrorCode.SerializeError, exception.ToString());
                    return;
                }
                throw;
            }
        }
Example #4
0
    static int Close(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("Framework.NetModule.LuaBuffer.Close");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 1);
            Framework.NetModule.LuaBuffer obj = (Framework.NetModule.LuaBuffer)ToLua.CheckObject <Framework.NetModule.LuaBuffer>(L, 1);
            obj.Close();
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    static int SendLuaReq(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("Framework.NetModule.LuaNetHelper.SendLuaReq");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 2);
            int arg0 = (int)LuaDLL.luaL_checknumber(L, 1);
            Framework.NetModule.LuaBuffer arg1 = (Framework.NetModule.LuaBuffer)ToLua.CheckObject <Framework.NetModule.LuaBuffer>(L, 2);
            Framework.NetModule.LuaNetHelper.SendLuaReq(arg0, arg1);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #6
0
    static int WriteByte(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("Framework.NetModule.LuaBuffer.WriteByte");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 2);
            Framework.NetModule.LuaBuffer obj = (Framework.NetModule.LuaBuffer)ToLua.CheckObject <Framework.NetModule.LuaBuffer>(L, 1);
            byte arg0 = (byte)LuaDLL.luaL_checknumber(L, 2);
            obj.WriteByte(arg0);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #7
0
    static int ToBytes(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("Framework.NetModule.LuaBuffer.ToBytes");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 1);
            Framework.NetModule.LuaBuffer obj = (Framework.NetModule.LuaBuffer)ToLua.CheckObject <Framework.NetModule.LuaBuffer>(L, 1);
            byte[] o = obj.ToBytes();
            ToLua.Push(L, o);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #8
0
    static int ReadString(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("Framework.NetModule.LuaBuffer.ReadString");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 1);
            Framework.NetModule.LuaBuffer obj = (Framework.NetModule.LuaBuffer)ToLua.CheckObject <Framework.NetModule.LuaBuffer>(L, 1);
            string o = obj.ReadString();
            LuaDLL.lua_pushstring(L, o);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
 public static void SendLuaReq(int id, LuaBuffer buffer)
 {
     NetMgr.singleton.Send(id, buffer);
 }