From 8de4a1f09b54ad0a38fbc1481ee42b46df54f121 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Tue, 28 Jan 2025 23:48:49 +0300 Subject: [PATCH] /apps/twnlua: optimize default boolean and convertrer pops --- apps/twnlua/bindgen.py | 8 ++++---- include/twn_draw.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/twnlua/bindgen.py b/apps/twnlua/bindgen.py index 2bb7b7a..50130a5 100755 --- a/apps/twnlua/bindgen.py +++ b/apps/twnlua/bindgen.py @@ -84,7 +84,7 @@ for procedure, procedure_desc in api["procedures"].items(): binding += " %s %s;\n" % (parameter["type"] if not parameter["type"].endswith("*") else 'const ' + parameter["type"], parameter["name"]) binding += " lua_getfield(L, 1, \"%s\");\n" % parameter["name"] - if "default" in parameter and parameter["type"] != "float": + if "default" in parameter and not parameter["type"] in ("float", "bool"): binding += " if (lua_isnoneornil(L, -1))\n" binding += " %s = %s;\n" % (parameter["name"], default(parameter)) binding += " else\n " @@ -141,15 +141,15 @@ for typename, typedesc in used_converters.items(): converter += " %s %s;\n" % (typename, typename.lower()); if "fields" in typedesc: - for field in typedesc["fields"]: - converter += " lua_getfield(L, -1, \"%s\");\n" % (field["name"]); + for idx, field in enumerate(typedesc["fields"]): + converter += " lua_getfield(L, -%i, \"%s\");\n" % (idx + 1, field["name"]); if field["type"] == "float": converter += " %s.%s = (float)lua_tonumber(L, -1);\n" % (typename.lower(), field["name"]); elif field["type"] == "uint8_t": converter += " %s.%s = (uint8_t)lua_tointeger(L, -1);\n" % (typename.lower(), field["name"]); else: raise BaseException("Unhandled converter field type '%s'" % (field["type"])) - converter += " lua_pop(L, 1);\n"; + converter += " lua_pop(L, %i);\n" % len(typedesc["fields"]); # TODO: wild idea: use compile time built hash table elif "enums" in typedesc: diff --git a/include/twn_draw.h b/include/twn_draw.h index 137c406..f237eed 100644 --- a/include/twn_draw.h +++ b/include/twn_draw.h @@ -8,6 +8,7 @@ #include /* pushes a sprite onto the sprite render queue */ +/* TODO: combine flip_x and flip_y into a flip_mask with enum */ TWN_API void draw_sprite(char const *texture, Rect rect, Rect const *texture_region, /* optional, default: NULL */