Skip to content

Commit ac8b124

Browse files
don't crash on a lua file with no root table (#8770)
Co-authored-by: Wouter van Oortmerssen <[email protected]>
1 parent 88b033b commit ac8b124

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/bfbs_gen_lua.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,6 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
658658
void EmitCodeBlock(const std::string& code_block, const std::string& name,
659659
const std::string& ns,
660660
const std::string& declaring_file) const {
661-
const std::string root_type = schema_->root_table()->name()->str();
662-
const std::string root_file =
663-
schema_->root_table()->declaration_file()->str();
664661
const std::string full_qualified_name = ns.empty() ? name : ns + "." + name;
665662

666663
std::string code = "--[[ " + full_qualified_name + "\n\n";
@@ -672,7 +669,15 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
672669
code += " flatc version: " + flatc_version_ + "\n";
673670
code += "\n";
674671
code += " Declared by : " + declaring_file + "\n";
675-
code += " Rooting type : " + root_type + " (" + root_file + ")\n";
672+
673+
const r::Object* root_table = schema_->root_table();
674+
if (root_table) {
675+
const std::string root_type = root_table->name()->str();
676+
const std::string root_file = root_table->declaration_file()->str();
677+
678+
code += " Rooting type : " + root_type + " (" + root_file + ")\n";
679+
}
680+
676681
code += "\n--]]\n\n";
677682

678683
if (!requires_.empty()) {

0 commit comments

Comments
 (0)