Skip to content

Conversation

@jtdavis777
Copy link
Collaborator

@jtdavis777 jtdavis777 commented Dec 14, 2025

Lua builder code and generated code now handles file_ident properly.

Fixes #8641

@jtdavis777 jtdavis777 requested a review from aardappel December 14, 2025 20:35
@github-actions github-actions bot added c++ codegen Involving generating code from schema lua labels Dec 14, 2025
@jtdavis777 jtdavis777 added the ready-for-merge This PR has been approved by a maintainer and is ready for merge by a code owner label Dec 20, 2025
self:PrependUOffsetTRelative(rootTable)
local hasFid = fileIdentifier ~= nil
if hasFid then
assert(#fileIdentifier == 4, "File identifier must be exactly 4 bytes")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is checked by flatc, so doesn't need to be checked here again if this function is typically called by generated code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is technically accessible by the low level public API -- I have added a convenience function to call it from the generated code but that function is brand new. Most lua users will be interating with the Finish calls below and could pass a bad value in here. The below code will only add the first 4 bytes, so it wouldn't break, but I figure its better to tell the user of the problem than let it silently succeed.

self.minalign,
(sizePrefix and 4 or 0) +
4 +
(hasFid and 4 or 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a slow language that likely does not do common subexpression elimination, so wouldn't do (hasFid and 4 or 0) twice. In fact, maybe instead of hasFid use sizeFid which can have values 0 or 4 and can function both as bool and as value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileid and sizeprefix are orthogonal concerns, but I can break the subexpression out. Lua also treats 0 as truthy...

@jtdavis777 jtdavis777 requested a review from aardappel December 24, 2025 15:37
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 ready-for-merge This PR has been approved by a maintainer and is ready for merge by a code owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Lua] Generated lua does not use "file_identifier"

2 participants