mirror of
https://github.com/EdgeTX/edgetx.git
synced 2025-07-24 00:35:14 +03:00
Added generation of Lua fields documentation file: lua_fields.txt
This commit is contained in:
parent
4d84ba4c19
commit
b5c63e339f
3 changed files with 251 additions and 10 deletions
|
@ -6,6 +6,7 @@ import sys
|
|||
import os
|
||||
import traceback
|
||||
import time
|
||||
import re
|
||||
|
||||
PREC1 = 10
|
||||
PREC2 = 100
|
||||
|
@ -57,11 +58,22 @@ def LEXP_EXTRA(name, description, value, condition = "true"):
|
|||
# extra also added to normal items to enable searching
|
||||
exports.append( (CONSTANT_VALUE, name, description) )
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print "Error: not enough arguments!"
|
||||
print "Usage:"
|
||||
print " luaexport.py <version> <input txt> <output cpp> [<doc output>]"
|
||||
|
||||
inputFile = sys.argv[1]
|
||||
outputFile = sys.argv[2]
|
||||
version = sys.argv[1]
|
||||
inputFile = sys.argv[2]
|
||||
outputFile = sys.argv[3]
|
||||
docFile = None
|
||||
if len(sys.argv) >= 4:
|
||||
docFile = sys.argv[4]
|
||||
print "Version %s" % version
|
||||
print "Input file %s" % inputFile
|
||||
print "Output file %s" % outputFile
|
||||
if docFile:
|
||||
print "Documentation file %s" % docFile
|
||||
|
||||
inp = open(inputFile, "r")
|
||||
|
||||
|
@ -102,7 +114,8 @@ inp.close()
|
|||
|
||||
out = open(outputFile, "w")
|
||||
|
||||
out.write("//This file was generated by luaexport.py script on %s\n\n\n" % time.asctime())
|
||||
out.write("//This file was generated by luaexport.py script on %s for OpenTX version %s\n\n\n"
|
||||
% ( time.asctime(), version))
|
||||
|
||||
header = """
|
||||
struct LuaSingleField {
|
||||
|
@ -153,8 +166,8 @@ case_body = "\n".join(case_clauses)
|
|||
func_body = """
|
||||
extern lua_State *L;
|
||||
|
||||
// The handling of extra Lua fileds that are not
|
||||
// accesible by the getValue()
|
||||
// The handling of extra Lua fields that are not
|
||||
// accessible by the getValue()
|
||||
static int luaGetExtraValue(int src)
|
||||
{
|
||||
switch (src) {
|
||||
|
@ -165,11 +178,33 @@ static int luaGetExtraValue(int src)
|
|||
|
||||
""" % case_body
|
||||
out.write(func_body)
|
||||
print "Generated %d condtions in luaGetExtraValue()" % len(exports_extra)
|
||||
|
||||
|
||||
print "Generated %d conditions in luaGetExtraValue()" % len(exports_extra)
|
||||
out.close()
|
||||
|
||||
if docFile:
|
||||
#prepare fields
|
||||
all_exports = [(name, desc) for (id, name, desc) in exports]
|
||||
for (id, nameFormat, descriptionFormat, valuesCount) in exports_multiple:
|
||||
for v in range(valuesCount):
|
||||
name = nameFormat + str(v)
|
||||
desc = descriptionFormat % v
|
||||
all_exports.append( (name, desc) )
|
||||
#natural sort by field name
|
||||
convert = lambda text: int(text) if text.isdigit() else text
|
||||
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key[0]) ]
|
||||
all_exports.sort(key = alphanum_key)
|
||||
|
||||
out = open(docFile, "w")
|
||||
out.write("Alphabetical list of Lua fields for OpenTX version %s\n\n\n" % version)
|
||||
FIELD_NAME_WIDTH = 25
|
||||
out.write("Field name%sField description\n" % (' '*(FIELD_NAME_WIDTH-len('Field name'))))
|
||||
out.write("----------------------------------------------\n")
|
||||
data = ["%s%s%s" % (name, ' '*(FIELD_NAME_WIDTH-len(name)) , desc) for (name, desc) in all_exports]
|
||||
out.write("\n".join(data))
|
||||
out.write("\n")
|
||||
|
||||
out.close()
|
||||
|
||||
if warning:
|
||||
sys.exit(1)
|
||||
elif error:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue