static int _CreateFramework_LuaBuffer(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                Framework.LuaBuffer obj = new Framework.LuaBuffer();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 1)
            {
                byte[] arg0             = ToLua.CheckByteBuffer(L, 1);
                Framework.LuaBuffer obj = new Framework.LuaBuffer(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: Framework.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(string.Format("[NetMgr]Send {0} error!", e.ToString()));
         _session.Dispose();
     }
 }
Example #3
0
 public void Send(int id, LuaBuffer buffer)
 {
     if (_socket == null)
     {
         string errorMessage = "session not initialize.";
         if (ErrorHandler != null)
         {
             ErrorHandler(this, SessionErrorCode.StateError, errorMessage);
             return;
         }
         throw new Exception(errorMessage);
     }
     byte[] bufferBytes = buffer.ToBytes();
     if (bufferBytes == null)
     {
         string errorMessage = "luaBuff is null.";
         if (ErrorHandler != null)
         {
             ErrorHandler(this, SessionErrorCode.StateError, errorMessage);
             return;
         }
         throw new Exception(errorMessage);
     }
     try
     {
         int    length       = 0;
         int    packetLength = 0;
         byte[] packetBuffer = new byte[_defaultMaxPacketLength];//TODO:内存池;
         using (MemoryStream memoryStream = new MemoryStream(packetBuffer, true))
         {
             memoryStream.Seek(_defaultPacketLength, SeekOrigin.Begin);
             byte[] 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;
     }
 }
 static int Close(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         Framework.LuaBuffer obj = (Framework.LuaBuffer)ToLua.CheckObject <Framework.LuaBuffer>(L, 1);
         obj.Close();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int ReadString(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         Framework.LuaBuffer obj = (Framework.LuaBuffer)ToLua.CheckObject <Framework.LuaBuffer>(L, 1);
         string o = obj.ReadString();
         LuaDLL.lua_pushstring(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int WriteByte(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Framework.LuaBuffer obj = (Framework.LuaBuffer)ToLua.CheckObject <Framework.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 SendLuaReq(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 1);
         Framework.LuaBuffer arg1 = (Framework.LuaBuffer)ToLua.CheckObject <Framework.LuaBuffer>(L, 2);
         Framework.LuaNetHelper.SendLuaReq(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int ToBytes(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         Framework.LuaBuffer obj = (Framework.LuaBuffer)ToLua.CheckObject <Framework.LuaBuffer>(L, 1);
         byte[] o = obj.ToBytes();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int WriteBuffer(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Framework.LuaBuffer obj  = (Framework.LuaBuffer)ToLua.CheckObject <Framework.LuaBuffer>(L, 1);
         LuaByteBuffer       arg0 = new LuaByteBuffer(ToLua.CheckByteBuffer(L, 2));
         obj.WriteBuffer(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int ReadBuffer(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         Framework.LuaBuffer        obj = (Framework.LuaBuffer)ToLua.CheckObject <Framework.LuaBuffer>(L, 1);
         LuaInterface.LuaByteBuffer o   = obj.ReadBuffer();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int WriteString(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Framework.LuaBuffer obj = (Framework.LuaBuffer)ToLua.CheckObject <Framework.LuaBuffer>(L, 1);
         string arg0             = ToLua.CheckString(L, 2);
         obj.WriteString(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #12
0
    static int Close(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("Framework.LuaBuffer.Close");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 1);
            Framework.LuaBuffer obj = (Framework.LuaBuffer)ToLua.CheckObject <Framework.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.LuaNetHelper.SendLuaReq");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 2);
            int arg0 = (int)LuaDLL.luaL_checknumber(L, 1);
            Framework.LuaBuffer arg1 = (Framework.LuaBuffer)ToLua.CheckObject <Framework.LuaBuffer>(L, 2);
            Framework.LuaNetHelper.SendLuaReq(arg0, arg1);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #14
0
    static int ReadString(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("Framework.LuaBuffer.ReadString");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 1);
            Framework.LuaBuffer obj = (Framework.LuaBuffer)ToLua.CheckObject <Framework.LuaBuffer>(L, 1);
            string o = obj.ReadString();
            LuaDLL.lua_pushstring(L, o);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #15
0
    static int ToBytes(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("Framework.LuaBuffer.ToBytes");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 1);
            Framework.LuaBuffer obj = (Framework.LuaBuffer)ToLua.CheckObject <Framework.LuaBuffer>(L, 1);
            byte[] o = obj.ToBytes();
            ToLua.Push(L, o);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #16
0
    static int WriteString(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("Framework.LuaBuffer.WriteString");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 2);
            Framework.LuaBuffer obj = (Framework.LuaBuffer)ToLua.CheckObject <Framework.LuaBuffer>(L, 1);
            string arg0             = ToLua.CheckString(L, 2);
            obj.WriteString(arg0);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #17
0
    static int WriteByte(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("Framework.LuaBuffer.WriteByte");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 2);
            Framework.LuaBuffer obj = (Framework.LuaBuffer)ToLua.CheckObject <Framework.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 #18
0
 public static void SendLuaReq(int id, LuaBuffer buffer)
 {
     NetMgr.singleton.Send(id, buffer);
 }
Example #19
0
 public static void SendLuaReq(int id, LuaBuffer buffer)
 {
     NetMgr.Instance.Send(id, buffer);
 }