MCPcopy Create free account
hub / github.com/defold/defold / to_lua_annotation

Function to_lua_annotation

engine/docs/script_doc.py:703–742  ·  view source on GitHub ↗
(s, output_file)

Source from the content-addressed store, hash-verified

701
702
703def to_lua_annotation(s, output_file):
704 def fixdoc(s):
705 lines = s.splitlines(keepends = True)
706 for i,line in enumerate(lines):
707 line = re.sub(r'\[icon:.*?\]', r'', line)
708 line = re.sub(r'\[type:(.*)\]', r'\1', line)
709 line = re.sub(r'^- (.*)', r'\1', line)
710 line = re.sub(r'^: (.*)', r'\1', line)
711 line = re.sub(r'`(.*?)`', r'\1', line)
712 lines[i] = line
713 return "---".join(lines)
714
715 msg = parse_document(s, output_file)
716 if msg.info.language == "Lua":
717 dct = message_to_dict(msg)
718 dct["info"]["name"] = dct["info"]["name"].replace("-", "_").lower()
719 dct["info"]["description"] = re.sub(r'\[icon:.*?\]', r'', dct["info"]["description"])
720 for element in dct["elements"]:
721 element["is_" + element["type"].lower()] = True
722 element["description"] = fixdoc(element["description"])
723 element["params_string"] = ", ".join([parameter["name"] for parameter in element["parameters"]])
724 element["members_string"] = ", ".join([member["name"] for member in element["members"]])
725 for member in element["members"]:
726 member["doc"] = fixdoc(member["doc"])
727 for parameter in element["parameters"]:
728 parameter["types_string"] = "|".join([t for t in parameter["types"]])
729 parameter["doc"] = fixdoc(parameter["doc"])
730 if parameter["is_optional"] != True:
731 parameter["is_optional"] = None
732 for rv in element["returnvalues"]:
733 rv["types_string"] = "|".join([t for t in rv["types"]])
734 rv["doc"] = fixdoc(rv["doc"])
735
736 result = pystache.render(LUA_MTL, dct)
737 result = html.unescape(result)
738 with codecs.open(output_file, "wb", encoding="utf-8") as f:
739 f.write(result)
740 else:
741 f = open(output_file, "w")
742 f.close()
743
744if __name__ == '__main__':
745 usage = "usage: %prog [options] INFILE(s) OUTFILE"

Callers 1

script_doc.pyFile · 0.85

Calls 11

parse_documentFunction · 0.85
message_to_dictFunction · 0.85
fixdocFunction · 0.85
lowerMethod · 0.80
replaceMethod · 0.80
subMethod · 0.80
renderMethod · 0.80
unescapeMethod · 0.80
openMethod · 0.80
closeMethod · 0.65
writeMethod · 0.45

Tested by

no test coverage detected