Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bfbs_gen_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions tests/LuaTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}"
Expand Down
11 changes: 11 additions & 0 deletions tests/lua_nested_table_test.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
table Customer {
name:string;
age:int;
}

table Sale {
amount:int;
customer:Customer;
}

root_type Sale;
24 changes: 24 additions & 0 deletions tests/luatest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
{
{
Expand Down Expand Up @@ -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 =
Expand Down