Compare commits
2 Commits
ac93d114c9
...
458b44d0b0
Author | SHA1 | Date | |
---|---|---|---|
|
458b44d0b0 | ||
|
8de4a1f09b |
@ -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:
|
||||
|
@ -5,6 +5,7 @@ for that certain considerations are taken:
|
||||
* number of public api calls is kept at the minimum
|
||||
* procedure parameters can only use basic types, no aggregates, with exception of Vec/Matrix types and alike,
|
||||
with no new additions, ever (see [/include/twn_types.h](../include/twn_types.h))
|
||||
* enum types are allowed, as they decay to numeric type (but language-specific api can decide to provide simple ways to use them)
|
||||
* optionals can be expressed via pointer passage of value primitives, assumed immutable, with the NULL expressing default value
|
||||
* no opaque types, only keys if needed
|
||||
* pointers to pointers aren't allowed
|
||||
@ -15,3 +16,4 @@ for that certain considerations are taken:
|
||||
* 32 bit floating point is the only numeric type
|
||||
* [/include/twn_api.json](../share/twn_api.json) file is hand-kept with a schema to aid automatic binding generation and tooling
|
||||
* parameter names should not collide with keywords of any language that is targetted; if so happens, parameter alias could be added
|
||||
* any procedure can't have more than 8 parameters
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
/* 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 */
|
||||
|
Loading…
Reference in New Issue
Block a user