Skip to content

Commit

Permalink
Generator: Lua: update to generate script that passes AP's luacheck
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPete1 authored and tridge committed Jun 26, 2023
1 parent f41a355 commit 45c4d35
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions generator/mavgen_lua.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def generate(basename, xml):
module_root_rel += '/'

# dump the actual symbol table
outf.write("local mavlink_msgs = {}\n")
for m in msgs:
# outf.write("mavlink_msg.msgs[%u] = \"%s\"\n" % (m.id, m.name))
mavlink_msg_file = open("%s/mavlink_msg_%s.lua" % (basename, m.name), "w")
mavlink_msg_file.write("local %s = {}\n" % m.name)
mavlink_msg_file.write("%s.id = %u\n" % (m.name, m.id))
Expand All @@ -66,7 +64,7 @@ def generate(basename, xml):
mavlink_msg_file.write("return %s\n" % m.name)
mavlink_msg_file.close()
outf.write(
"""
"""-- Auto generated MAVLink parsing script
local mavlink_msgs = {{}}
function mavlink_msgs.get_msgid(msgname)
Expand All @@ -93,7 +91,7 @@ def generate(basename, xml):
error("Invalid magic byte")
end
local payload_len, read_marker = string.unpack("<B", message, read_marker) -- payload is always the second byte
_, read_marker = string.unpack("<B", message, read_marker) -- payload is always the second byte
-- strip the incompat/compat flags
result.incompat_flags, result.compat_flags, read_marker = string.unpack("<BB", message, read_marker)
Expand All @@ -116,7 +114,7 @@ def generate(basename, xml):
end
-- map all the fields out
for i,v in ipairs(message_map.fields) do
for _,v in ipairs(message_map.fields) do
if v[3] then
result[v[1]] = {{}}
for j=1,v[3] do
Expand All @@ -134,13 +132,13 @@ def generate(basename, xml):
function mavlink_msgs.encode(msgname, message)
local message_map = require("{module_root_rel}mavlink_msg_" .. msgname)
if not message_map then
if not message_map then
-- we don't know how to encode this message, bail on it
error("Unknown MAVLink message " .. msgname)
end
local packString = "<"
local packedTable = {{}}
local packedTable = {{}}
local packedIndex = 1
for i,v in ipairs(message_map.fields) do
if v[3] then
Expand Down

0 comments on commit 45c4d35

Please sign in to comment.