请教,初学LUA,使用protobuf时出现找不到pb.lua文件问题
写了个.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)
最后运行结果
做过的操作如下:
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)
最后运行结果

...全文
相关推荐
lua-pb解析
lua解析protobuf的文件。适合纯lua的protobuf协议的解析和使用
Unity之protobuf-lua的使用详解
protoc-gen-lua Protobuf 官方并没有 Lua版本,然后网易的程序猿开发出了 protoc-gen-lua ,可以让我们将 Proto 文件转成 lua 脚本在 Lua中使用,下面是详细的编译、安装、使用教程。文中用到的代码 1.下载protoc-gen-lua 可以通过HG从服务器(hg clone https://code.google.com/p/protoc-...
protobuf生成lua和go文件
protobuf-gen-lua的安装与使用 有部分图文教程, 解压包基本有需要用到软件及下载地址,并附安装流程
protobuf转为lua代码
protobuf配置文件转化为lua脚本;游戏开发很好用的工具
lua-protobuf:与Google protobuf一起使用的Lua模块
lua-protobuf:与Google protobuf一起使用的Lua模块


Google技术社区
