Skip to content

Fix Lua table field builder slot generation#9014

Open
steadytao wants to merge 1 commit intogoogle:masterfrom
steadytao:fix-8611-lua-table-fields-use-uoffset-slots
Open

Fix Lua table field builder slot generation#9014
steadytao wants to merge 1 commit intogoogle:masterfrom
steadytao:fix-8611-lua-table-fields-use-uoffset-slots

Conversation

@steadytao
Copy link
Copy Markdown

Summary

Make the Lua generator use PrependUOffsetTRelativeSlot for table fields instead of PrependStructSlot.

Problem

The Lua generator treated both structs and tables as Struct when selecting the builder slot method for table fields.

For a schema like:

table Customer {
  name:string;
  age:int;
}

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

it generated:

function Sale.AddCustomer(builder, customer)
  builder:PrependStructSlot(1, customer, 0)
end

but customer is a table offset, not an inline struct. This causes packing to fail with:
Tried to write a Struct at an Offset that is different from the current Offset of the Builder.

Fix

  • only use Struct builder methods for actual struct fields
  • use UOffsetTRelative for table fields
  • add a focused Lua regression schema and test that packs a nested table successfully

Testing

  • rebuilt flatc
  • generated Lua for the nested Customer / Sale schema
  • verified the generated Sale.AddCustomer now uses PrependUOffsetTRelativeSlot
  • luatest.lua: 8 / 8 tests passed

Fixes #8611

Make the Lua generator use UOffset-relative slots for table fields instead of treating all object references as structs.

Add a Lua regression schema and runtime test for packing a nested table field.

Fixes google#8611
@steadytao steadytao requested a review from dbaileychess as a code owner April 3, 2026 05:52
@github-actions github-actions bot added c++ codegen Involving generating code from schema lua labels Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema lua

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Lua] Lua generator fails to generate correct code for simple singly nested table

1 participant