Implement PROTOBUF serialization in Lua, deserialization

Source: Internet
Author: User
Tags lua serialization

Protobuf officially does not have a LUA version, and then NetEase's program ape developed Protoc-gen-lua, allowing us to turn Proto files into Lua scripts for use in Lua, with detailed compilation, installation, and usage tutorials. The text used in the code, tools have Baidu network disk download.

Network disk download Address: http://pan.baidu.com/s/1bo8Ufd9

1, first we need to install Python2.7, download the address:

[HTML] view plain Co install to C disk by default


Add the installation directory to the environment variable, and then open the command line console and enter the command

[HTML] view plain copy python
If the prompt command does not exist, the environment variable is not set correctly, and if it is the following figure, the setting is successful

ame.com.cn

2, download and compile Luajit 2.0.4 , download after decompression, find LUAJIT-2.0.4/SRC directory, which has a batch file Msvcbuild.bat, which is the compilation tool in Windows System.

In Start menu-Find Visual Studio Tools in all applications in Visual Studio 201x, open vs201x Developer command prompt, switch to luajit-2.0.4/src directory, execute command

[HTML] view plain copy Msvcbuild.bat
Start compiling Luajit 2.0.4


Like the following figure appears successfully built Luajit for windows/x86 instructions compilation success


This paper turns from Http://blog.csdn.net/huutu http://www.thisisgame.com.cn

Search the LUAJIT-2.0.4\SRC directory for Lua51.dll Lua51.lib Luajit.exe Whether these three files exist, if the above compilation succeeds, then these three files are certain.


3, download and compile protobuf-2.4.1

Open Protobuf.sln in the Protobuf-2.4.1\vsprojects directory, as shown in the following figure



It is useless to remove the test item from the project in the red box in the following figure in Visual Studio.


After deletion the following figure


The project is compiled one at a time, not compiled together.

To compile the LIBPROTOBUF project first, there must be an error. Prompt for the following error


The reason is that the corresponding header file is not added in the Protobuf, search in the project to open Common.h, add the corresponding header file, the following figure:


If you compile again, you can compile successfully.


Then compile the second project Libprotobuf-lite. There is no error.


Then compile a third project Libprotoc. There must be a mistake, as shown below



Double-click the locate error, or open command_line_interface.cc, to line 913, and modify it to the following figure



Compile again and you can succeed.


Finally compile the fourth project Protoc. Compilation successful

Then go to the Protobuf-2.4.1\vsprojects\debug directory to find the generated 4 files, the following figure in the red box



These 4 files will be used when compiling the Protoc-gen-lua.


After the compilation succeeds, execute the command in the Protobuf-2.4.1\python folder [HTML] view plain copy Python setup.py install

4, download and compile the installation Protoc-gen-lua ,

After the decompression, open the directory, the following figure has three folders


Create batch file Protoc-gen-lua.bat in the plugin directory, as follows

[CSharp] view plain copy @python "%~dp0protoc-gen-lua"
Then copy the Protoc.exe generated in the previous compilation protobuf-2.4.1 to the Protoc-gen-lua-master directory, as shown in the following figure


The batch file Buildproto.bat is then created in the Protoc-gen-lua-master directory, as follows

[CSharp] view plain copy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.