Skip to content

Commit

Permalink
protoc.lua support boolean constant
Browse files Browse the repository at this point in the history
  • Loading branch information
starwing committed Jun 2, 2023
1 parent ed58909 commit 08344d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
21 changes: 12 additions & 9 deletions protoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,18 @@ function Lexer:array(opt)
end

function Lexer:constant(opt)
local c = self:full_ident('constant', 'opt') or
self:number('opt') or
self:quote('opt') or
self:structure('opt') or
self:array('opt')
if not c and not opt then
local c = self:full_ident('constant', 'opt')
if c == "true" then
c = true
elseif c == "false" then
c = false
elseif c == nil then
c = self:number('opt') or
self:quote('opt') or
self:structure('opt') or
self:array('opt')
end
if c == nil and not opt then
return self:error "constant expected"
end
return c
Expand Down Expand Up @@ -459,9 +465,6 @@ local function field(self, lex, ident)
if options then
info.default_value, options.default = tostring(options.default), nil
info.json_name, options.json_name = options.json_name, nil
if options.packed and options.packed == "false" then
options.packed = false
end
info.options = options
end
if info.number <= 0 then
Expand Down
3 changes: 3 additions & 0 deletions test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,12 @@ function _G.test_packed()
message MyMessage
{
repeated int32 intList = 1;
repeated int32 nopacks = 2 [packed=false];
} ]]
local b = pb.encode("MyMessage", { intList = { 1,2,3 } })
eq(pb.tohex(b), "0A 03 01 02 03")
local b = pb.encode("MyMessage", { nopacks = { 1,2,3 } })
eq(pb.tohex(b), "10 01 10 02 10 03")

check_load [[
syntax="proto3";
Expand Down

0 comments on commit 08344d6

Please sign in to comment.