Skip to content

Commit cfe483d

Browse files
committed
fix show packed in optional field
1 parent 89faac2 commit cfe483d

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

pb.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1181,8 +1181,8 @@ static int lpb_pushfield(lua_State *L, pb_Type *t, pb_Field *f) {
11811181
lua_pushstring(L, f->type ? (char*)f->type->name :
11821182
pb_typename(f->type_id, "<unknown>"));
11831183
lua_pushstring(L, (char*)f->default_value);
1184-
lua_pushstring(L, f->packed ? "packed" :
1185-
f->repeated ? "repeated" : "optional");
1184+
lua_pushstring(L, f->repeated ? f->packed ? "packed" : "repeated"
1185+
: "optional");
11861186
if (f->oneof_idx > 0) {
11871187
lua_pushstring(L, (const char*)pb_oneofname(t, f->oneof_idx));
11881188
lua_pushinteger(L, f->oneof_idx-1);

pb.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,7 @@ static void pbL_loadField(pb_State *S, pbL_FieldInfo *info, pb_Loader *L, pb_Typ
15791579
f->oneof_idx = info->oneof_index;
15801580
f->type_id = info->type;
15811581
f->repeated = info->label == 3; /* repeated */
1582-
f->packed = info->packed >= 0 ? info->packed : L->is_proto3;
1582+
f->packed = info->packed >= 0 ? info->packed : L->is_proto3 && f->repeated;
15831583
if (f->type_id >= 9 && f->type_id <= 12) f->packed = 0;
15841584
f->scalar = (f->type == NULL);
15851585
}

test.lua

+2
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ function _G.test_default()
374374
repeated int32 array = 18;
375375
} ]]
376376

377+
local _, _, _, _, rep = pb.field("TestDefault", "foo")
378+
eq(rep, "optional")
377379
table_eq(copy_no_meta(pb.defaults "TestDefault"), {
378380
defaulted_int = 0,
379381
defaulted_bool = false,

0 commit comments

Comments
 (0)