From ac8b1244965f33254c348578b95a6953c6faf0a6 Mon Sep 17 00:00:00 2001 From: Justin Davis Date: Mon, 17 Nov 2025 17:31:32 -0500 Subject: [PATCH] don't crash on a lua file with no root table (#8770) Co-authored-by: Wouter van Oortmerssen --- src/bfbs_gen_lua.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bfbs_gen_lua.cpp b/src/bfbs_gen_lua.cpp index 7e1e372b4..01cd2d992 100644 --- a/src/bfbs_gen_lua.cpp +++ b/src/bfbs_gen_lua.cpp @@ -658,9 +658,6 @@ class LuaBfbsGenerator : public BaseBfbsGenerator { void EmitCodeBlock(const std::string& code_block, const std::string& name, const std::string& ns, const std::string& declaring_file) const { - const std::string root_type = schema_->root_table()->name()->str(); - const std::string root_file = - schema_->root_table()->declaration_file()->str(); const std::string full_qualified_name = ns.empty() ? name : ns + "." + name; std::string code = "--[[ " + full_qualified_name + "\n\n"; @@ -672,7 +669,15 @@ class LuaBfbsGenerator : public BaseBfbsGenerator { code += " flatc version: " + flatc_version_ + "\n"; code += "\n"; code += " Declared by : " + declaring_file + "\n"; - code += " Rooting type : " + root_type + " (" + root_file + ")\n"; + + const r::Object* root_table = schema_->root_table(); + if (root_table) { + const std::string root_type = root_table->name()->str(); + const std::string root_file = root_table->declaration_file()->str(); + + code += " Rooting type : " + root_type + " (" + root_file + ")\n"; + } + code += "\n--]]\n\n"; if (!requires_.empty()) {