lua-pb icon indicating copy to clipboard operation
lua-pb copied to clipboard

Doesn't support 'false' value of boolean type

Open youlanhai opened this issue 8 years ago • 0 comments

I'm sorry, i'm not good at English.

For example:

// protobuf
message MyProto
{
  required bool boolField = 1;
}
-- lua codes
local p = MyProto()
p.boolField = false
print(p:HasField("boolField")) -- the result is: false
print(p:Serialize()) -- the result is: false, Missing require field

The false value of boolean type was not supported.

The following is source code of lua-pb/message.lua

function methods:HasField(name)
	local data = rawget(self, '.data') -- field data.
	return not not data[name]
end

I think the code return not not data[name] may be replaced with return data[name] ~= nil. The same problem for Serialize and some other methods.

youlanhai avatar Jan 03 '17 08:01 youlanhai