写了个.proto文件,通过protoc-gen-lua将.proto转换成了.lua,但是在lua提供的demo程序的main最后面加了一段序列化和反序列化的小程序时,提示找不到pb.lua文件,不知道哪里出问题了。
做过的操作如下:
1.
写了个.proto文件,通过protoc-gen-lua将.proto转换成了.lua
2.
在mian.lua的最前面加了这两行代码
package.path = package.path .. ';../protobuf/?.lua'
package.cpath = package.cpath .. ';../protobuf/?.so'
3.
在main函数后面加了
local function main()
collectgarbage("collect")
-- avoid memory leak
collectgarbage("setpause", 100)
collectgarbage("setstepmul", 5000)
cc.FileUtils:getInstance():addSearchResolutionsOrder("src");
cc.FileUtils:getInstance():addSearchResolutionsOrder("res");
cc.FileUtils:getInstance():addSearchResolutionsOrder("protobuf"); // 加的
require "testprobuf_pb" // 加的
4.
在main.lua最后面加了
-- 测试protocol buffer
local a = package.loadlib("pb.dll", "luaopen_pb")
a()
local testmod = testprobuf_pb.testmsg()
testmod.id = 8
testmod.name = "joney"
testmod.nvalue = 9
local data = testmod:SerializeToString()
local testrecv = testprobuf_pb.testmsg()
testrecv:ParseFromString(data)
print(testrecv)
最后运行结果