Exemplo n.º 1
0
        private static void RegisterLuaCallFunc()
        {
            var  reader     = ScutReader.GetIntance();
            Type readerType = reader.GetType();

            _luaContext.RegisterFunc("ScutReader_getResult", reader, readerType.GetMethod("getResult"));
            _luaContext.RegisterFunc("ScutReader_readAction", reader, readerType.GetMethod("readAction"));
            _luaContext.RegisterFunc("ScutReader_readErrorCode", reader, readerType.GetMethod("readErrorCode"));
            _luaContext.RegisterFunc("ScutReader_readErrorMsg", reader, readerType.GetMethod("readErrorMsg"));
            _luaContext.RegisterFunc("ScutReader_getWORD", reader, readerType.GetMethod("getWORD"));
            _luaContext.RegisterFunc("ScutReader_getInt", reader, readerType.GetMethod("getInt"));
            _luaContext.RegisterFunc("ScutReader_getByte", reader, readerType.GetMethod("getByte"));
            _luaContext.RegisterFunc("ScutReader_getLong", reader, readerType.GetMethod("getLong"));
            _luaContext.RegisterFunc("ScutReader_getDouble", reader, readerType.GetMethod("getDouble"));
            _luaContext.RegisterFunc("ScutReader_readString", reader, readerType.GetMethod("readString"));
            _luaContext.RegisterFunc("ScutReader_recordBegin", reader, readerType.GetMethod("recordBegin"));
            _luaContext.RegisterFunc("ScutReader_recordEnd", reader, readerType.GetMethod("recordEnd"));

            var  writer     = ScutWriter.getInstance();
            Type writerType = writer.GetType();

            _luaContext.RegisterFunc("ScutWriter_writeString", writer, writerType.GetMethod("writeString"));
            _luaContext.RegisterFunc("ScutWriter_writeInt32", writer, writerType.GetMethod("writeInt32"));
            _luaContext.RegisterFunc("ScutWriter_writeWord", writer, writerType.GetMethod("writeWord"));
            _luaContext.RegisterFunc("ScutWriter_writeHead", writer, writerType.GetMethod("writeHead"));
        }
Exemplo n.º 2
0
        private void OnReceiveCompleted(SocketClient sender, byte[] data)
        {
            try
            {
                ScutReader.GetIntance().Reader = new MessageStructure(data);
                bool     result   = ScutReader.GetIntance().getResult();
                int      actionId = ScutReader.GetIntance().readAction();
                string   funName  = string.Format("_{0}Callback", actionId);
                LuaTable table;
                if (!LuaRuntime.GetContext().TryCall <Func <UserToken, LuaTable>, LuaTable>(funName, out table, _token))
                {
                    _responseLog.WriteFormatLine("接收出错:The {0} function is not exist in lua file.", funName);
                }
                else if (result)
                {
                    _responseLog.WriteTable("接收Action:" + actionId + "成功!Error:" + ScutReader.GetIntance().readErrorCode(), table);
                }
            }
            catch (Exception ex)
            {
                _responseLog.WriteFormatLine("接收出错:{0}", ex);
            }
            finally
            {
#if DEBUG
#else
                ResponseReflesh();
#endif
            }
        }