As a network game, it is inevitable to interact with the server, the data structure on the PROTOBUF is a good solution, the use of protobuf in Lua there are a variety of options, where the use of the cloud wind of the PBC.
First go to this web site to download the build tool http://repo1.maven.org/maven2/com/google/protobuf/protoc/, my side of the download of version 2.5. Put the Protoc.exe in the designated place, and then copy the proto file, for better tools in the game, place Protoc in the engineering Lua directory, then create a folder, put proto files in the folder, and then start cmd execution protoc.exe– Descriptor_set_out=./.. /GAME.PB./*.proto.
CMD Test OK, we can create a new bat file, one key processing, here will all the protocols packaged together, you can also file packaging.
CD%~dp0
CD proto
xcopy E:\*.proto%cd%/y
. \protoc.exe --descriptor_set_out=./. /GAME.PB./*.proto
Here to modify the next copy of the directory, all proto files are copied over, if you want to this command as a Unity menu, you can refer to my previous article
LUA uses the following to first read the file and register
Local Path = Luaconst.luadir.. /3RD/PBLUA/GAME.PB ";--note path local
addr = io.open (path," RB ") local
buffer = addr:read" *a "
addr:close ()
protobuf.register (buffer)
Message serialization and sending to the server
Local addressbook = {
name = "Alice",
id = 12345,
phone = {
{number = "1301234567"},
{number = 876 54321 ", type =" WORK "},
}
local
code = Protobuf.encode (" tutorial. Person ", addressbook);
--Send a message to the server
Receive server-side messages and deserialize
Local decode = Protobuf.decode ("tutorial.") Person ", data)