/apps/twnlua: optimize default boolean and convertrer pops

This commit is contained in:
veclavtalica 2025-01-28 23:48:49 +03:00
parent ac93d114c9
commit 8de4a1f09b
2 changed files with 5 additions and 4 deletions

View File

@ -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 += " %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"] 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 += " if (lua_isnoneornil(L, -1))\n"
binding += " %s = %s;\n" % (parameter["name"], default(parameter)) binding += " %s = %s;\n" % (parameter["name"], default(parameter))
binding += " else\n " binding += " else\n "
@ -141,15 +141,15 @@ for typename, typedesc in used_converters.items():
converter += " %s %s;\n" % (typename, typename.lower()); converter += " %s %s;\n" % (typename, typename.lower());
if "fields" in typedesc: if "fields" in typedesc:
for field in typedesc["fields"]: for idx, field in enumerate(typedesc["fields"]):
converter += " lua_getfield(L, -1, \"%s\");\n" % (field["name"]); converter += " lua_getfield(L, -%i, \"%s\");\n" % (idx + 1, field["name"]);
if field["type"] == "float": if field["type"] == "float":
converter += " %s.%s = (float)lua_tonumber(L, -1);\n" % (typename.lower(), field["name"]); converter += " %s.%s = (float)lua_tonumber(L, -1);\n" % (typename.lower(), field["name"]);
elif field["type"] == "uint8_t": elif field["type"] == "uint8_t":
converter += " %s.%s = (uint8_t)lua_tointeger(L, -1);\n" % (typename.lower(), field["name"]); converter += " %s.%s = (uint8_t)lua_tointeger(L, -1);\n" % (typename.lower(), field["name"]);
else: else:
raise BaseException("Unhandled converter field type '%s'" % (field["type"])) 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 # TODO: wild idea: use compile time built hash table
elif "enums" in typedesc: elif "enums" in typedesc:

View File

@ -8,6 +8,7 @@
#include <stdbool.h> #include <stdbool.h>
/* pushes a sprite onto the sprite render queue */ /* 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, TWN_API void draw_sprite(char const *texture,
Rect rect, Rect rect,
Rect const *texture_region, /* optional, default: NULL */ Rect const *texture_region, /* optional, default: NULL */