Skip to content

Commit

Permalink
Generator: Lua: allow strings
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPete1 committed Oct 23, 2023
1 parent e51a7d4 commit d422f97
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion generator/mavgen_lua.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def generate(basename, xml):
mavlink_msg_file.write("%s.fields = {\n" % m.name)
for i in range(0, len(m.ordered_fields)):
field = m.ordered_fields[i]
if (field.array_length > 0):
if ((field.type == 'char') and (field.array_length > 0)):
# Convert char array to lua string
mavlink_msg_file.write(" { \"%s\", \"<c%s\" },\n" % (field.name, field.array_length))
elif (field.array_length > 0):
mavlink_msg_file.write(" { \"%s\", \"<%s\", %s },\n" % (field.name, unpack_types.get(field.type), field.array_length))
else:
mavlink_msg_file.write(" { \"%s\", \"<%s\" },\n" % (field.name, unpack_types.get(field.type)))
Expand Down Expand Up @@ -122,6 +125,11 @@ def generate(basename, xml):
end
else
result[v[1]], offset = string.unpack(v[2], message, offset)
if string.sub(v[2],2,2) == 'c'then
-- Got string, unpack includes 0 values to the set length
-- this is annoying, so remove them
result[v[1]] = string.gsub(result[v[1]], "\0", "")
end
end
end
Expand Down

0 comments on commit d422f97

Please sign in to comment.