Lua: quote member and constant names that are Lua keywords - #2
Merged
Conversation
The Lua backend emitted every member and constant with dot notation, so a type with a field named after a Lua keyword produced a file that does not parse. ROS's geographic_msgs.RouteSegment has fields named "start" and "end"; the generated RouteSegment.lua contained `obj.end = nil` and was rejected by luac. Emit `t["end"]` instead of `t.end` when the name is a reserved word. This covers member access in _encode_one/_decode_one/new, the array length references used in loop bounds and string.format widths, and constants. Output is unchanged for every name that is not a Lua keyword: of the 190 types in dimos-lcm, RouteSegment.lua is the only file whose generated Lua differs, and it now round-trips through encode/decode with the "end" field intact. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Lua backend emits every member and constant with dot notation, so a type with a field named after a Lua keyword produces a file that does not parse.
ROS's
geographic_msgs/RouteSegmenthas fields namedstartandend. The generatedRouteSegment.luacontained:luac -prejects all three. Every other backend is fine —endis not reserved in Python, C++, Java, C#, TypeScript or Rust.Needed by dimensionalOS/dimos-lcm#24, which adds
geographic_msgs.Fix
Emit
t["end"]instead oft.endwhen the name is a Lua reserved word. One helper,lua_member_ref(), applied at every site that turns an LCM name into a Lua identifier:new(),_encode_one(),_decode_one(), and the array-element accessorsfor i0 = 1, self["end"] do) andstring.formatwidths /data:read()arguments, since a length field can itself be keyword-namedStruct["end"] = 1)Verification
Against the 190 types in dimos-lcm, generated with the patched and unpatched binary using an identical invocation:
geographic_msgs/RouteSegment.luais the only file whose output differs — every other byte is identical, so this cannot regress existing consumersluac -p(before: 189)RouteSegmentround-trips throughencode/decodewith theendfield intact — a nestedUniqueIDinenddecodes back to the value it was encoded with, alongsidestartand a variable-lengthpropsarraygit clang-formatreports no changes on the diff.🤖 Generated with Claude Code