From ccbd54f3b8906c0c017d9994f43a64c036d7dd63 Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Wed, 26 Jul 2023 23:54:58 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E7=94=9F=E6=88=90lua=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/writeLua/ByteArray.lua | 16 ++++++++-------- src/writeLua/gLuaField.erl | 16 ++++++++-------- src/writeLua/gLuaGen.erl | 37 +++++-------------------------------- 3 files changed, 21 insertions(+), 48 deletions(-) diff --git a/src/writeLua/ByteArray.lua b/src/writeLua/ByteArray.lua index a046587..201d720 100644 --- a/src/writeLua/ByteArray.lua +++ b/src/writeLua/ByteArray.lua @@ -133,22 +133,22 @@ function ByteArray(endian) writeBuf(buf) end -- 读32位整型 - ba.read_int = function() + ba.read_int32 = function() local tmp, value = string.unpack(readBuf(4), getLetterCode("i")) return value end -- 写32位整型 - ba.write_int = function(value) + ba.write_int32 = function(value) local buf = string.pack(getLetterCode("i"), value) writeBuf(buf) end -- 读32位无符号整型 - ba.read_uint = function() + ba.read_uint32 = function() local tmp, value = string.unpack(readBuf(4), getLetterCode("I")) return value end -- 写32位无符号整型 - ba.write_uint = function(value) + ba.write_uint32 = function(value) local buf = string.pack(getLetterCode("I"), value) writeBuf(buf) end @@ -231,16 +231,16 @@ function ByteArray(endian) end end -- 读字符型 - ba.read_char = function() + ba.read_int8 = function() local tmp, value = string.unpack(readRawByte(), "c") return value end -- 写字符型 - ba.write_char = function(value) + ba.write_int8 = function(value) writeRawByte(string.pack("c", value)) end -- 读单字节 - ba.read_uchar = function() + ba.read_uint8 = function() -- 方法1 -- return string.byte(readRawByte()) -- 方法2 @@ -248,7 +248,7 @@ function ByteArray(endian) return value end -- 写单字节 - ba.write_uchar = function(value) + ba.write_uint8 = function(value) -- 方法1 -- writeRawByte(string.char(value)) -- 方法2 diff --git a/src/writeLua/gLuaField.erl b/src/writeLua/gLuaField.erl index 3d883ad..91bbd4e 100644 --- a/src/writeLua/gLuaField.erl +++ b/src/writeLua/gLuaField.erl @@ -17,14 +17,14 @@ -define(TypeValue, [ {<<"bool">>, <<"bool">>} - , {<<"int8">>, <<"sbyte">>} - , {<<"uint8">>, <<"byte">>} - , {<<"int16">>, <<"short">>} - , {<<"uint16">>, <<"ushort">>} - , {<<"int32">>, <<"int">>} - , {<<"uint32">>, <<"uint">>} - , {<<"int64">>, <<"long">>} - , {<<"uint64">>, <<"ulong">>} + , {<<"int8">>, <<"int8">>} + , {<<"uint8">>, <<"uint8">>} + , {<<"int16">>, <<"int16">>} + , {<<"uint16">>, <<"uint16">>} + , {<<"int32">>, <<"int32">>} + , {<<"uint32">>, <<"uint32">>} + , {<<"int64">>, <<"int64">>} + , {<<"uint64">>, <<"uint64">>} , {<<"float">>, <<"float">>} , {<<"double">>, <<"double">>} , {<<"string">>, <<"string">>} diff --git a/src/writeLua/gLuaGen.erl b/src/writeLua/gLuaGen.erl index 75dbbab..24b91f1 100644 --- a/src/writeLua/gLuaGen.erl +++ b/src/writeLua/gLuaGen.erl @@ -1,15 +1,9 @@ -%% Author: NoteBook -%% Created: 2009-9-18 -%% Description: TODO: Add description to gen_protocal_charp -module(gLuaGen). -%% -%% Include files -%% +-export([ + genLua/4 +]). -%% -%% Exported Functions -%% -export([start/0]). -export([test/0]). %% @@ -20,35 +14,14 @@ start() -> StructList = protocol_def:get_struct_def(), TypeList = gen_common:get_type(), FileStr = make_protocal(StructList, "", TypeList), - %%根据前端需求更改 原:file:write_file("NetPacket.lua", FileStr), -%% file:write_file("NetPacket.lua", lists:concat(["return {", FileStr, "}"])), - file:write_file("NetPacket.lua", FileStr), + + file:write_file("NetPacket.lua", FileStr), EnumStr = make_protocal_enum(protocol_def:get_enum_def(), ""), ConstStr = make_protocal_const(protocol_def:get_version()), file:write_file("NetEnumDef.lua", EnumStr ++ "\n" ++ ConstStr), MsgTypeStr = make_protocal_msg_type(StructList, "", 1), file:write_file("NetMsgType.lua", MsgTypeStr). -%% -%% Local Functions -%% - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%生成包含文件%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%% make_include() -> -%% "using System; -%% using System.Collections;". - %% "#pragma once - %% #include\"ByteArray.h\" - %% #include\"BaseType.h\" - %% #include\"INetPacket.h\" - %% #include\"NetMsgType.h\" - %% #include - %% #include - %% ". -%%%%%%%%%%%%%%%%%%%%%%%%%%%%生成函数的方法%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - make_protocal([], StructStr, _TypeList) -> StructStr; make_protocal([Struct | Structs], StructStr, TypeList) ->