-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Feature: lua now file_ident aware #8850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| self:PrependUOffsetTRelative(rootTable) | ||
| local hasFid = fileIdentifier ~= nil | ||
| if hasFid then | ||
| assert(#fileIdentifier == 4, "File identifier must be exactly 4 bytes") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
lua/flatbuffers/builder.lua
Outdated
| self.minalign, | ||
| (sizePrefix and 4 or 0) + | ||
| 4 + | ||
| (hasFid and 4 or 0) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
Lua builder code and generated code now handles file_ident properly.
Fixes #8641