aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xluatablegen.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/luatablegen.py b/luatablegen.py
index ce5e9c8..099417e 100755
--- a/luatablegen.py
+++ b/luatablegen.py
@@ -248,6 +248,10 @@ def type_resolver(elem, elem_list):
return node.attrib["name"]
else: return type_str
+def get_full_path(path, name):
+ if path[-1] == "/": return path + name
+ else: return path + "/" + name
+
def get_def_node(type_str, elem_list):
for node in elem_list:
if type_str == node.attrib["name"]:
@@ -329,6 +333,58 @@ class TbgParser(object):
pre_file.close()
c_source.write("\n")
+ def gen_struct_header_xml(self):
+ self.struct_source_h = self.argparser.args.out + "/structs.h"
+ self.struct_source_c = self.argparser.args.out + "/structs.c"
+ struct_source = open(self.struct_source_h, "w")
+ struct_source_c = open(get_full_path(self.argparser.args.out, "structs.c"), "w")
+ struct_source.write("// automatically generated by luatablegen\n")
+ struct_source_c.write("// automatically generated by luatablegen\n")
+ struct_source.write("// " + self.time + "\n")
+ struct_source_c.write("// " + self.time + "\n")
+ struct_source.write("#ifndef FT_STRUCTS_H\n#define FT_STRUCTS_H\n")
+ struct_source.write('#ifdef __cplusplus__\nextern "C" {\n#endif\n')
+ struct_source_c.write('#include "structs.h"\n')
+ struct_source_c.write('#include "stdlib.h"\n')
+ struct_source_c.write('#include "stdio.h"\n')
+ struct_source.write('#include <unistd.h>\n')
+ struct_source.write('#include <inttypes.h>\n')
+ """
+ if self.argparser.args.structsinclude:
+ copy(self.argparser.args.structsinclude, self.argparser.args.outdir)
+ pos = self.argparser.args.structsinclude.rfind("/")
+ sub = self.argparser.args.structsinclude[pos+1:]
+ struct_source.write('#include "' + sub + '"\n\n')
+ """
+ for child in self.def_elems + self.read_elems:
+ struct_source.write("typedef struct {\n")
+ if not "isaggregate" in child.attrib:
+ ref_type = type_resolver(child, self.def_elems + self.read_elems)
+ def_node = get_def_node(ref_type, self.def_elems + self.read_elems)
+ pointer = str()
+ if "count" in child.attrib:
+ if child.attrib["count"] != "1":
+ pointer = "*"
+ if def_node:
+ struct_source.write(ref_type + pointer + "* " + child.attrib["name"] + ";\n")
+ else:
+ struct_source.write(ref_type + pointer + " " + child.attrib["name"] + ";\n")
+ for childer in child:
+ ref_type = type_resolver(childer, self.def_elems + self.read_elems)
+ def_node = get_def_node(ref_type, self.def_elems + self.read_elems)
+ pointer = str()
+ if "count" in childer.attrib:
+ if childer.attrib["count"] != "1":
+ pointer = "*"
+ if def_node:
+ struct_source.write(ref_type + pointer + "* " + childer.attrib["name"] + ";\n")
+ else:
+ struct_source.write(ref_type + pointer + " " + childer.attrib["name"] + ";\n")
+ struct_source.write("}" + child.attrib["name"] + ";\n\n")
+ struct_source.write('#ifdef __cplusplus__\n}\n#endif\n')
+ struct_source.write("#endif\n")
+ #struct_source.write(text.last_comment)
+
def gen_lua_table_push_def(self, node, struct_name):
type_name = type_resolver(child, self.def_elems+self.read_elems)
type_ref_node = get_def_node(type_name, self.def_elems+self.read_elems)
@@ -717,6 +773,7 @@ class TbgParser(object):
self.read_xml()
self.gen_table_def()
+ self.gen_struct_header_xml()
if self.argparser.args.singlefile:
c_source = open(self.argparser.args.outfile, "w")
if self.argparser.args.docpath: