diff options
Diffstat (limited to '')
-rwxr-xr-x | luatablegen.py | 46 | ||||
-rwxr-xr-x | run.sh | 2 |
2 files changed, 24 insertions, 24 deletions
diff --git a/luatablegen.py b/luatablegen.py index 868afc0..d172939 100755 --- a/luatablegen.py +++ b/luatablegen.py @@ -122,7 +122,7 @@ LUA_PUSH_TABLE_SIMPLE_TYPE_SIG = 'int pushluatable_YYY(lua_State* ls, XXX array, LUA_PUSH_TABLE_SIG = "int pushluatable_YYY(lua_State* ls, XXX array, uint64_t count);\n" LUA_PUSH_TABLE_CALL = "pushluatable_YYY(lua_State* ls, WWW, XXX array, ZZZ);\n" -LUA_LIB = ["local wasm = {}\n\n", "return wasm\n"] +LUA_LIB = ["local XXX = {}\n\n", "return XXX\n"] LUA_SETMETA_NEW = ["setmetatable(XXX, {__call =\n", "\tfunction(selfAAA)\n", "\t\tlocal t = self.new(AAA)\n", "\t\treturn t\n\tend\n\t}\n)\n"] LUA_TO_GENERIC = "lua_to_YYY(__ls, ZZZ);\n" @@ -343,6 +343,7 @@ class Argparser(object): parser.add_argument("--outfile", type=str, help="name of the output file if signlefile is set, ignored otherwise") parser.add_argument("--headeraggr", type=str, help="header aggregate file name") parser.add_argument("--lualibpath", type=str, help="where the lua module file will be placed") + parser.add_argument("--lualibname", type=str, help="the name for the table") parser.add_argument("--docpath", type=str, help="where the doc file will be placed") parser.add_argument("--xml", type=str, help="same as --tbg but use an xml file instead") parser.add_argument("--tbldefs", type=str, help="path to the definitions tablegen creates") @@ -833,7 +834,7 @@ class TbgParser(object): d_source.write("\n") d_source.write("### " + "_" + "setter fields" + "_" + ":\n") for field_name,lua_type in zip(field_names, lua_types): - d_source.write("set_" + struct_name + ":" + field_name + "()" + " -- ") + d_source.write(struct_name + ":set_" + field_name + "()" + " -- ") if lua_type == "lightuserdata": d_source.write("arg type: " + field_name + "_t" + "<br/>" + "\n") else: @@ -845,27 +846,16 @@ class TbgParser(object): d_source.write("\n") d_source.write("\n") - def luagen(self): - l_source = open(self.argparser.args.lualibpath, "w") - l_source.write("-- automatically generated by luatablegen\n") - l_source.write("-- " + self.time + "\n") - l_source.write(LUA_LIB[0]) - for k, v in self.tbg_file.items(): - struct_name = k - field_names = v['field_name'] - field_types = v['field_type'] - lua_types = v['lua_type'] - l_source.write(LUA_SETMETA_NEW[0].replace("XXX", struct_name)) - arg_list_str = str() - for i in range(0, len(field_names)): - arg_list_str += ", arg" + repr(i) - l_source.write(LUA_SETMETA_NEW[1].replace("AAA", arg_list_str)) - l_source.write(LUA_SETMETA_NEW[2].replace("AAA", arg_list_str[2:])) - l_source.write(LUA_SETMETA_NEW[3]) - arg_list_str = str() - l_source.write("\n") - - l_source.write(LUA_LIB[1]) + def luagen(self, l_source, struct_name, field_names, field_types, lua_types): + l_source.write(LUA_SETMETA_NEW[0].replace("XXX", struct_name)) + arg_list_str = str() + for i in range(0, len(field_names)): + arg_list_str += ", arg" + repr(i) + l_source.write(LUA_SETMETA_NEW[1].replace("AAA", arg_list_str)) + l_source.write(LUA_SETMETA_NEW[2].replace("AAA", arg_list_str[2:])) + l_source.write(LUA_SETMETA_NEW[3]) + arg_list_str = str() + l_source.write("\n") def gen_table_def(self): tbl_source = open(self.argparser.args.tbldefs + "/tabledefs.c", "w") @@ -941,6 +931,11 @@ class TbgParser(object): d_source = open(self.argparser.args.docpath, "w") d_source.write("The lazy constructors are inside wasm.lua.\n") d_source.write("```lua\nlocal wasm = require(\"wasm\")\n```\n") + if self.argparser.args.lualibpath: + l_source = open(self.argparser.args.lualibpath, "w") + l_source.write("-- automatically generated by luatablegen\n") + l_source.write("-- " + self.time + "\n") + l_source.write(LUA_LIB[0].replace("XXX", self.argparser.args.lualibname)) #for k, v in self.tbg_file.items(): for struct_name, field_names, field_types, lua_types in zip(self.struct_names, self.field_names, self.field_types, self.lua_types): if not self.argparser.args.singlefile: @@ -985,6 +980,8 @@ class TbgParser(object): # docs if self.argparser.args.docpath: self.docgen_md(d_source, struct_name, field_names, field_types, lua_types) + if self.argparser.args.lualibpath: + self.luagen(l_source, struct_name, field_names, field_types, lua_types) # header aggregate if self.argparser.args.headeraggr: name = self.argparser.args.headeraggr @@ -1025,6 +1022,9 @@ class TbgParser(object): if self.argparser.args.docpath: d_source.write("_automatically generated by luatablegen._<br/>\n") d_source.write("_" + self.time + "_") + if self.argparser.args.lualibpath: + #l_source = open(self.argparser.args.lualibpath, "w") + l_source.write(LUA_LIB[0].replace("XXX", self.argparser.args.lualibname)) # write code here def premain(argparser): @@ -1,7 +1,7 @@ #!/usr/bin/bash cd $(dirname $0) if [[ -d ./out ]]; then :;else mkdir ./out;fi -./luatablegen.py --tbg ./test/wasmtablegen.json --out ./out --luaheader /home/bloodstalker/devi/hell2/bruiser/lua-5.3.4/src --pre ./test/wasmheader.txt --headeraggr ./out/wasm_tables.h --lualibpath ./out/wasm.lua --docpath ./out/wasm.md --xml ./test/luwasm.xml --tbldefs ./out/ --anon --name wasm +./luatablegen.py --tbg ./test/wasmtablegen.json --out ./out --luaheader /home/bloodstalker/devi/hell2/bruiser/lua-5.3.4/src --pre ./test/wasmheader.txt --headeraggr ./out/wasm_tables.h --lualibpath ./out/wasm.lua --docpath ./out/wasm.md --xml ./test/luwasm.xml --tbldefs ./out/ --anon --name wasm --lualibname wasmextra clang-format ./out/*.c ./out/*.h -i for filename in ./out/*.c; do gcc -c $filename > /dev/null 2>&1 |