AP_Scripting: docs: allow overload of manual bindings to allow documentation of optional arguments

This commit is contained in:
Iampete1 2024-06-02 21:25:48 +02:00 committed by Andrew Tridgell
parent f54ca766df
commit 364419be81
4 changed files with 33 additions and 14 deletions

View File

@ -129,9 +129,9 @@ if __name__ == '__main__':
p = subprocess.Popen(command, shell=True, text=True, stdout=subprocess.PIPE) p = subprocess.Popen(command, shell=True, text=True, stdout=subprocess.PIPE)
result = [] result = []
while p.poll() is None: while p.poll() is None:
l = p.stdout.readline() line = p.stdout.readline()
result.append(l) result.append(line)
print(l, end="") print(line, end="")
# Make sure we checked at least one file # Make sure we checked at least one file
file_count_re = re.compile(r"^>*=* \d+/(\d+)") file_count_re = re.compile(r"^>*=* \d+/(\d+)")

View File

@ -69,14 +69,21 @@ function print(text) end
-- data flash logging to SD card -- data flash logging to SD card
logger = {} logger = {}
-- write value to data flash log with given types and names, optional units and multipliers, timestamp will be automatically added -- write value to data flash log with given types and names with units and multipliers, timestamp will be automatically added
---@param name string -- up to 4 characters ---@param name string -- up to 4 characters
---@param labels string -- comma separated value labels, up to 58 characters ---@param labels string -- comma separated value labels, up to 58 characters
---@param format string -- type format string, see https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Logger/README.md ---@param format string -- type format string, see https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Logger/README.md
---@param units? string -- optional units string ---@param units string -- units string
---@param multipliers? string -- optional multipliers string ---@param multipliers string -- multipliers string
---@param data1 integer|number|uint32_t_ud|string -- data to be logged, type to match format string ---@param ... integer|number|uint32_t_ud|string -- data to be logged, type to match format string
function logger:write(name, labels, format, units, multipliers, data1, ...) end function logger:write(name, labels, format, units, multipliers, ...) end
-- write value to data flash log with given types and names, timestamp will be automatically added
---@param name string -- up to 4 characters
---@param labels string -- comma separated value labels, up to 58 characters
---@param format string -- type format string, see https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Logger/README.md
---@param ... integer|number|uint32_t_ud|string -- data to be logged, type to match format string
function logger:write(name, labels, format, ...) end
-- log a files content to onboard log -- log a files content to onboard log
---@param filename string -- file name ---@param filename string -- file name

View File

@ -843,7 +843,7 @@ singleton AP_EFI method get_state void EFI_State'Ref
include AP_Logger/AP_Logger.h include AP_Logger/AP_Logger.h
singleton AP_Logger depends HAL_LOGGING_ENABLED singleton AP_Logger depends HAL_LOGGING_ENABLED
singleton AP_Logger rename logger singleton AP_Logger rename logger
singleton AP_Logger manual write AP_Logger_Write 7 0 singleton AP_Logger manual write AP_Logger_Write 6 0
singleton AP_Logger method log_file_content void string singleton AP_Logger method log_file_content void string
singleton AP_Logger method log_file_content depends HAL_LOGGER_FILE_CONTENTS_ENABLED singleton AP_Logger method log_file_content depends HAL_LOGGER_FILE_CONTENTS_ENABLED

View File

@ -1,3 +1,5 @@
#!/usr/bin/env python3
''' '''
Reads two lua docs files and checks for differences Reads two lua docs files and checks for differences
@ -16,6 +18,14 @@ class method(object):
self.full_line = full_line self.full_line = full_line
self.returns = returns self.returns = returns
self.params = params self.params = params
self.manual = False
for i in range(len(self.returns)):
if self.returns[i][0] == 'UNKNOWN':
self.manual = True
for i in range(len(self.params)):
if self.params[i][0] == 'UNKNOWN':
self.manual = True
def __str__(self): def __str__(self):
ret_str = "%s\n" % (self.full_line) ret_str = "%s\n" % (self.full_line)
@ -74,6 +84,11 @@ class method(object):
def __eq__(self, other): def __eq__(self, other):
return (self.global_name == other.global_name) and (self.local_name == other.local_name) and (self.num_args == other.num_args) return (self.global_name == other.global_name) and (self.local_name == other.local_name) and (self.num_args == other.num_args)
def is_overload(self, other):
# Allow manual bindings to have fewer arguments
# this allows multiple function definitions with different params
return other.manual and (self.global_name == other.global_name) and (self.local_name == other.local_name) and (self.num_args < other.num_args)
def get_return_type(line): def get_return_type(line):
try: try:
match = re.findall("^---@return (\w+(\|(\w+))*)", line) match = re.findall("^---@return (\w+(\|(\w+))*)", line)
@ -85,7 +100,7 @@ def get_return_type(line):
def get_param_type(line): def get_param_type(line):
try: try:
match = re.findall("^---@param \w+\?? (\w+(\|(\w+))*)", line) match = re.findall("^---@param (?:\w+\??|...) (\w+(\|(\w+))*)", line)
all_types = match[0][0] all_types = match[0][0]
return all_types.split("|") return all_types.split("|")
@ -136,9 +151,6 @@ def parse_file(file_name):
num_args = 0 num_args = 0
else: else:
num_args = args.count(",") + 1 num_args = args.count(",") + 1
# ... shows up in arg list but not @param, add a unknown param
if args.endswith("..."):
params.append(["UNKNOWN"])
if num_args != len(params): if num_args != len(params):
raise Exception("Missing \"---@param\" for function: %s", line) raise Exception("Missing \"---@param\" for function: %s", line)
@ -194,7 +206,7 @@ def compare(expected_file_name, got_file_name):
for got in got_methods: for got in got_methods:
found = False found = False
for meth in expected_methods: for meth in expected_methods:
if got == meth: if (got == meth) or got.is_overload(meth):
found = True found = True
break break
if not found: if not found: