From 045e4e775c5d0ee2e7fd489cc3c236861fa5f004 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 24 Jun 2018 10:46:22 +0430 Subject: fixes 42, fixes 44 --- extra-tools/luatablegen.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'extra-tools') diff --git a/extra-tools/luatablegen.py b/extra-tools/luatablegen.py index dbf7435..aca41d3 100755 --- a/extra-tools/luatablegen.py +++ b/extra-tools/luatablegen.py @@ -205,7 +205,7 @@ class TbgParser(object): c_source.write(SETTER_GEN[0].replace("XXX", struct_name).replace("YYY", field_name)) c_source.write(SETTER_GEN[1].replace("XXX", struct_name)) if lua_type == "integer": dummy = "\tdummy->" + field_name + " = " + "luaL_checkinteger(__ls, 2);\n" - elif lua_type == "lightuserdata": dummy ="\tdummy->" + field_name + " = " + "luaL_checkudata(__ls, 2, "+'"'+struct_name+'"'+");\n" + elif lua_type == "lightuserdata": dummy ="\tdummy->" + field_name + " = " + "luaL_checkudata(__ls, 2, "+'"'+field_name+"_t"+'"'+");\n" elif lua_type == "number": dummy ="\tdummy->" + field_name + " = " + "luaL_checknumber(__ls, 2);\n" elif lua_type == "string": dummy ="\tdummy->" + field_name + " = " + "luaL_checkstring(__ls, 2);\n" elif lua_type == "boolean": pass @@ -255,13 +255,28 @@ class TbgParser(object): c_source.write("\n") def docgen_md(self, d_source, struct_name, field_names, field_types, lua_types): - d_source.write("## wasm tables method list:\n") + d_source.write("## " + "__" + struct_name + "__" + ":\n") + d_source.write("\n") + d_source.write("### " + "_" + "getter fields" + "_" + ":\n") for field_name,lua_type in zip(field_names, lua_types): d_source.write(struct_name + ":" + field_name + "()" + " -- ") - d_source.write(lua_type + "
" + "\n") + if lua_type == "lightuserdata": + d_source.write("return type: " + field_name + "_t" + "
" + "\n") + else: + d_source.write("return type: " + lua_type + "
" + "\n") + 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(lua_type + "
" + "\n") + if lua_type == "lightuserdata": + d_source.write("arg type: " + field_name + "_t" + "
" + "\n") + else: + d_source.write("arg type: " + lua_type + "
" + "\n") + d_source.write("\n") + d_source.write("### " + "_" + "constructors" + "_" + ":\n") + d_source.write(struct_name + ":new() -- needs all the args
\n") + d_source.write(struct_name + "() -- lazy constructor
\n") + d_source.write("\n") d_source.write("\n") def luagen(self): @@ -293,6 +308,8 @@ class TbgParser(object): c_source = open(self.argparser.args.outfile, "w") if self.argparser.args.docpath: 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") for k, v in self.tbg_file.items(): struct_name = k field_names = v['field_name'] @@ -373,6 +390,8 @@ class TbgParser(object): m_source = open(self.argparser.args.out + "/" + "tablegen.mk", "w") # generate lua module self.luagen() + if self.argparser.args.docpath: + d_source.write("_automatically generated by luatablegen._
\n") # write code here def premain(argparser): -- cgit v1.2.3