diff --git a/src/bfbs_gen_lua.cpp b/src/bfbs_gen_lua.cpp index 5e8def216..fbd2210e3 100644 --- a/src/bfbs_gen_lua.cpp +++ b/src/bfbs_gen_lua.cpp @@ -554,7 +554,7 @@ class LuaBfbsGenerator : public BaseBfbsGenerator { if (IsScalar(base_type)) { return namer_.Type(GenerateType(base_type)); } - if (IsStructOrTable(base_type)) { + if (base_type == r::Obj && GetObject(field->type())->is_struct()) { return "Struct"; } return "UOffsetTRelative"; diff --git a/tests/LuaTest.sh b/tests/LuaTest.sh index af34b697e..a13503941 100755 --- a/tests/LuaTest.sh +++ b/tests/LuaTest.sh @@ -17,6 +17,8 @@ pushd "$(dirname $0)" >/dev/null test_dir="$(pwd)" +${test_dir}/../flatc -l -o ${test_dir} lua_nested_table_test.fbs + declare -a versions=(luajit lua5.1 lua5.2 lua5.3 lua5.4) for i in "${versions[@]}" diff --git a/tests/lua_nested_table_test.fbs b/tests/lua_nested_table_test.fbs new file mode 100644 index 000000000..1c0a48bbf --- /dev/null +++ b/tests/lua_nested_table_test.fbs @@ -0,0 +1,11 @@ +table Customer { + name:string; + age:int; +} + +table Sale { + amount:int; + customer:Customer; +} + +root_type Sale; diff --git a/tests/luatest.lua b/tests/luatest.lua index 1a70f5ff4..29d83d500 100644 --- a/tests/luatest.lua +++ b/tests/luatest.lua @@ -317,6 +317,26 @@ local function testAccessByteVectorAsString() end end +local function testLuaNestedTablePack() + local sale = assert(require("Sale")) + local customer = assert(require("Customer")) + local builder = flatbuffers.Builder(0) + + local name = builder:CreateString("Alice") + customer.Start(builder) + customer.AddName(builder, name) + customer.AddAge(builder, 33) + local customerOffset = customer.End(builder) + + sale.Start(builder) + sale.AddAmount(builder, 125) + sale.AddCustomer(builder, customerOffset) + local saleOffset = sale.End(builder) + builder:Finish(saleOffset) + + assert(#builder:Output() > 0) +end + local tests = { { @@ -344,6 +364,10 @@ local tests = f = testAccessByteVectorAsString, d = "Access byte vector as string" }, + { + f = testLuaNestedTablePack, + d = "Lua nested table fields pack with UOffset slots" + }, } local benchmarks =