/apps/twnlua: add returns in docgen.py
This commit is contained in:
parent
2120f6876c
commit
11ec35bc8a
@ -7,9 +7,11 @@ with open(sys.argv[1], 'r') if sys.argv[1] != "-" else sys.stdin as f:
|
|||||||
|
|
||||||
api = json.loads(api_source)
|
api = json.loads(api_source)
|
||||||
|
|
||||||
def to_lua_type_annot(typename):
|
def to_lua_type_annot(typedesc):
|
||||||
basetype = typename.rsplit(' *', 1)[0]
|
if type(typedesc) is dict:
|
||||||
if typename == "char *":
|
return r'{ %s }' % ','.join('%s: %s' % (f["name"], to_lua_type_annot(f["type"])) for f in typedesc["fields"])
|
||||||
|
basetype = typedesc.rsplit(' *', 1)[0]
|
||||||
|
if typedesc == "char *":
|
||||||
return "string"
|
return "string"
|
||||||
elif basetype == "float":
|
elif basetype == "float":
|
||||||
return "number"
|
return "number"
|
||||||
@ -27,7 +29,7 @@ def to_lua_type_annot(typename):
|
|||||||
return r"{ x: number, y: number, w: number, h: number }"
|
return r"{ x: number, y: number, w: number, h: number }"
|
||||||
else:
|
else:
|
||||||
return "unknown"
|
return "unknown"
|
||||||
# raise BaseException("Unhandled type for annotation: %s" % typename)
|
# raise BaseException("Unhandled type for annotation: %s" % typedesc)
|
||||||
|
|
||||||
type_annotations, enum_annotations = {}, {}
|
type_annotations, enum_annotations = {}, {}
|
||||||
type_annotations["ctx"] = r"{ %s, udata: table }" % \
|
type_annotations["ctx"] = r"{ %s, udata: table }" % \
|
||||||
@ -45,9 +47,14 @@ for annot in enum_annotations:
|
|||||||
|
|
||||||
procedure_annotations = {}
|
procedure_annotations = {}
|
||||||
for procedure, procedure_desc in api["procedures"].items():
|
for procedure, procedure_desc in api["procedures"].items():
|
||||||
procedure_annotations[procedure] = r"{ %s }" % \
|
procedure_annotations[procedure] = {}
|
||||||
|
procedure_annotations[procedure]["params"] = r"{ %s }" % \
|
||||||
', '.join("%s: %s" % (p["name"], to_lua_type_annot(p["type"]) + '?' * ("default" in p)) for p in procedure_desc["params"])
|
', '.join("%s: %s" % (p["name"], to_lua_type_annot(p["type"]) + '?' * ("default" in p)) for p in procedure_desc["params"])
|
||||||
|
if "return" in procedure_desc:
|
||||||
|
procedure_annotations[procedure]["return"] = to_lua_type_annot(procedure_desc["return"])
|
||||||
|
|
||||||
for annot in procedure_annotations:
|
for annot in procedure_annotations:
|
||||||
print("---@param args " + procedure_annotations[annot])
|
print("---@param args " + procedure_annotations[annot]["params"])
|
||||||
|
if "return" in procedure_annotations[annot]:
|
||||||
|
print("---@return " + procedure_annotations[annot]["return"])
|
||||||
print("function %s(args) end" % annot)
|
print("function %s(args) end" % annot)
|
||||||
|
Loading…
Reference in New Issue
Block a user