starwing / lua-protobuf

A Lua module to work with Google protobuf
MIT License
1.73k stars 387 forks source link

设置 default 值报错 #206

Closed yuanlairubi2016 closed 2 years ago

yuanlairubi2016 commented 2 years ago

设置 default 值报错 protoc.lua. inline_option 函数里面好像 报错了

LuaException: net/protoc:70: <input>:548:19: ',' expected
stack traceback:
    [C]: in function 'error'
    net/protoc:70: in function <net/protoc:68>
    (...tail calls...)
    net/protoc:375: in upvalue 'inline_option'
    net/protoc:396: in upvalue 'field'
    net/protoc:420: in upvalue 'label_field'
starwing commented 2 years ago

你是不是没打逗号?

yuanlairubi2016 commented 2 years ago

谢谢回复,可能是我使用的问题,只要 message 以数字结尾,好像会报这个错误,没有的话就正常 如下面的TestMode1 把这个改为TestMode 就正常,改为TestMode1就报上面的错误了 但是没设置 default 值也会正常

例子:

message Test {
    optional int32 defaulted_int = 1 [ default = 777 ];
}

message TestMode1 {
    optional int32 id = 1;
    optional string name = 2; 
    optional bool isGood = 3; 
}

message TestModeB {
    optional int32 id = 1; 
    optional string name = 2; 
    optional bool isGood = 3; 
    optional TestMode1 model = 4; 
}
starwing commented 2 years ago

你的例子在我这边没报错,你先看看是不是版本太旧:

local protoc = require "protoc"

protoc:load [[
message Test {
    optional int32 defaulted_int = 1 [ default = 777 ];
}

message TestMode1 {
    optional int32 id = 1;
    optional string name = 2; 
    optional bool isGood = 3; 
}

message TestModeB {
    optional int32 id = 1; 
    optional string name = 2; 
    optional bool isGood = 3; 
    optional TestMode1 model = 4; 
}
]]

local pb = require "pb"
local data = pb.encode("TestMode1", {id=1, name="foo", isGood=true})
print(require "serpent".block(pb.decode("TestMode1", data)))
yuanlairubi2016 commented 2 years ago

更新就可以了,太感谢了