Skip to content

Commit

Permalink
Lobster: Support required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
aardappel committed Mar 9, 2024
1 parent 6ff9e90 commit 960cd4d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/idl_gen_lobster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,17 @@ class LobsterGenerator : public BaseGenerator {
code += def + "() -> " + name + ":\n ";
code += "return " + name + "{ buf_, pos_ + " + offsets + " }\n";
} else {
code += def + "() -> " + name + "?:\n ";
code += def + "() -> " + name;
if (!field.IsRequired()) code += "?";
code += ":\n ";
code += std::string("let o = flatbuffers.field_") +
(field.value.type.struct_def->fixed ? "struct" : "table") +
"(buf_, pos_, " + offsets + ")\n return if o: " + name +
" { buf_, o } else: nil\n";
"(buf_, pos_, " + offsets + ")\n return ";
if (field.IsRequired()) {
code += name + " { buf_, assert o }\n";
} else {
code += "if o: " + name + " { buf_, o } else: nil\n";
}
}
break;
}
Expand Down

0 comments on commit 960cd4d

Please sign in to comment.