aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadek Micek <radek.micek@gmail.com>2025-09-14 22:15:38 +0200
committerRadek Micek <radek.micek@gmail.com>2025-09-16 11:56:19 +0200
commit5b5d5397d7c4d5084805f9c50db3509ad72e2d1f (patch)
tree55be568e20aeb9757ae2e686fa4495333329c6df
parentdd955ed18ee402e1ce660c021ed03f9d6bbf261e (diff)
Change C3 bindgen to generate more idiomatic types
-rw-r--r--.github/workflows/gen_bindings.yml2
-rw-r--r--bindgen/gen_c3.py21
2 files changed, 10 insertions, 13 deletions
diff --git a/.github/workflows/gen_bindings.yml b/.github/workflows/gen_bindings.yml
index 3006788b..0987aeff 100644
--- a/.github/workflows/gen_bindings.yml
+++ b/.github/workflows/gen_bindings.yml
@@ -374,7 +374,7 @@ jobs:
repository: floooh/sokol-c3
- uses: radekm/setup-c3@v2
with:
- version: v0.7.2
+ version: v0.7.5
- uses: actions/download-artifact@main
with:
name: ignore-me-c3
diff --git a/bindgen/gen_c3.py b/bindgen/gen_c3.py
index 91112778..1259e6d9 100644
--- a/bindgen/gen_c3.py
+++ b/bindgen/gen_c3.py
@@ -118,11 +118,11 @@ aliases = {
"void (*)(void)":
("Cb", "fn void()"),
"void (*)(const sapp_event *)":
- ("EventCb", "fn void(Event*)"),
+ ("EventCb", "fn void(SappEvent*)"),
"void (*)(const sapp_event *, void *)":
- ("EventDataCb", "fn void(Event*, void*)"),
+ ("EventDataCb", "fn void(SappEvent*, void*)"),
"void (*)(const sapp_html5_fetch_response *)":
- ("ResponseCb", "fn void(Html5FetchResponse*)"),
+ ("ResponseCb", "fn void(SappHtml5FetchResponse*)"),
"void (*)(float *, int, int)":
("StreamCb", "fn void(float*, CInt, CInt)"),
"void (*)(float *, int, int, void *)":
@@ -208,8 +208,8 @@ def as_parent_module_name_for_enum_type(enum_name, prefix):
# prefix_bla_blub(_t) => (dep::)BlaBlub
def as_struct_or_enum_type(s, prefix):
parts = s.lower().split('_')
- outp = '' if s.startswith(prefix) else f'sokol::{module_names[parts[0]+"_"]}::'
- for part in parts[1:]:
+ outp = ''
+ for part in parts:
# ignore '_t' type postfix
if part != 't':
outp += part.capitalize()
@@ -361,9 +361,8 @@ def gen_enum(decl, prefix):
tpe = "int"
if any(as_enum_item_name(check_override(item['name'])) == 'FORCE_U32' for item in decl['items']):
tpe = "uint"
- l(f'typedef {as_struct_or_enum_type(enum_name, prefix)} = {tpe};')
- # Constants are in submodule.
- l(f'module {as_module_name_for_enum_type(enum_name, prefix)};')
+ l(f'enum {as_struct_or_enum_type(enum_name, prefix)} : const {tpe}')
+ l('{')
value = "-1"
for item in decl['items']:
item_name = as_enum_item_name(check_override(item['name']))
@@ -372,10 +371,8 @@ def gen_enum(decl, prefix):
value = item['value']
else:
value = str(int(value) + 1)
- l(f"const {as_struct_or_enum_type(enum_name, prefix)} {item_name} = {value};")
- l(f'module {as_parent_module_name_for_enum_type(enum_name, prefix)};')
- # After reopening the original module all dependencies must be reimported.
- l(f'import sokol;')
+ l(f" {item_name} = {value},")
+ l('}')
l('')
def gen_imports(dep_prefixes):