A little refactoring to avoid all the sprintf and too many string
comparaisons. Completely untested
This commit is contained in:
+10
-13
@@ -42,15 +42,13 @@ def LEXP_TELEMETRY(name, description):
|
||||
checkName(name)
|
||||
exports.append( ("MIXSRC_FIRST_TELEM-1+"+CONSTANT_VALUE, name, description) )
|
||||
|
||||
def LEXP_MULTIPLE(nameFormat, descriptionFormat, firstValue, numOfValues):
|
||||
# print "LEXP_MULTIPLE %s, %s, %s, %s" % (nameFormat, descriptionFormat, firstValue, numOfValues)
|
||||
first = int(firstValue)
|
||||
last = first + int(numOfValues) - 1
|
||||
for v in range(first, last+1):
|
||||
name = nameFormat % v
|
||||
def LEXP_MULTIPLE(nameFormat, descriptionFormat, valuesCount):
|
||||
# print "LEXP_MULTIPLE %s, %s, %s" % (nameFormat, descriptionFormat, valuesCount)
|
||||
for v in range(valuesCount):
|
||||
name = nameFormat + str(v)
|
||||
# print name
|
||||
checkName(name)
|
||||
exports_multiple.append( (CONSTANT_VALUE, nameFormat, descriptionFormat, first, last) )
|
||||
exports_multiple.append( (CONSTANT_VALUE, nameFormat, descriptionFormat, valuesCount) )
|
||||
|
||||
def LEXP_EXTRA(name, description, value, condition = "true"):
|
||||
# print "LEXP_EXTRA %s, %s, %s, %s" % (name, description, value, condition)
|
||||
@@ -93,6 +91,7 @@ while True:
|
||||
# warning = True
|
||||
# continue
|
||||
# dups_cnst.append(CONSTANT_VALUE)
|
||||
# print cmd
|
||||
eval(cmd)
|
||||
except:
|
||||
print "ERROR: problem with the definition: %s" % line
|
||||
@@ -106,19 +105,17 @@ out = open(outputFile, "w")
|
||||
out.write("//This file was generated by luaexport.py script on %s\n\n\n" % time.asctime())
|
||||
|
||||
header = """
|
||||
struct LuaField {
|
||||
struct LuaSingleField {
|
||||
uint16_t id;
|
||||
const char * name;
|
||||
const char * desc;
|
||||
//const uint8_t attr;
|
||||
};
|
||||
|
||||
struct LuaMultipleField {
|
||||
uint16_t id;
|
||||
const char * name;
|
||||
const char * desc;
|
||||
uint8_t start;
|
||||
uint8_t end;
|
||||
uint8_t count;
|
||||
};
|
||||
|
||||
"""
|
||||
@@ -127,7 +124,7 @@ out.write(header)
|
||||
out.write("""
|
||||
// The list of Lua fields
|
||||
// this aray is alphabetically sorted by the second field (name)
|
||||
const LuaField luaFields[] = {
|
||||
const LuaSingleField luaSingleFields[] = {
|
||||
""")
|
||||
exports.sort(key = lambda x: x[1]) #sort by name
|
||||
data = [" {%s, \"%s\", \"%s\"}" % export for export in exports]
|
||||
@@ -139,7 +136,7 @@ out.write("""
|
||||
// The list of Lua fields that have a range of values
|
||||
const LuaMultipleField luaMultipleFields[] = {
|
||||
""")
|
||||
data = [" {%s, \"%s\", \"%s\", %d, %d}" % export for export in exports_multiple]
|
||||
data = [" {%s, \"%s\", \"%s\", %d}" % export for export in exports_multiple]
|
||||
out.write(",\n".join(data))
|
||||
out.write("\n};\n\n")
|
||||
print "Generated %d items in luaMultipleFields[]" % len(exports_multiple)
|
||||
|
||||
Reference in New Issue
Block a user