aboutsummaryrefslogtreecommitdiff
path: root/bindgen
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2022-07-26 20:39:02 +0200
committerAndre Weissflog <floooh@gmail.com>2022-07-26 20:39:02 +0200
commit808d23133caffc91febd3ac36c6b0a1db31ad144 (patch)
treea810d1dec3011aad801bfcb26e386b736204e721 /bindgen
parent14f7a07124000facfc83f3c653ad90a76eee6ef3 (diff)
gen_odin.py: inject sdtx.printf() wrapper function
Diffstat (limited to 'bindgen')
-rw-r--r--bindgen/gen_odin.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/bindgen/gen_odin.py b/bindgen/gen_odin.py
index 8b479557..34f9ed4c 100644
--- a/bindgen/gen_odin.py
+++ b/bindgen/gen_odin.py
@@ -487,18 +487,28 @@ def gen_func(decl, prefix):
l(s)
l('}')
-def gen_imports(inp, dep_prefixes):
+def gen_imports(dep_prefixes):
for dep_prefix in dep_prefixes:
dep_module_name = module_names[dep_prefix]
l(f'import {dep_prefix[:-1]} "../{dep_module_name}"')
l('')
+def gen_helpers(inp):
+ if inp['prefix'] == 'sdtx_':
+ l('import "core:fmt"')
+ l('import "core:strings"')
+ l('printf :: proc(s: string, args: ..any) {')
+ l(' fstr := fmt.tprintf(s, ..args)')
+ l(' putr(strings.unsafe_string_to_cstring(fstr), len(fstr))')
+ l('}')
+
def gen_module(inp, dep_prefixes):
pre_parse(inp)
l('// machine generated, do not edit')
l('')
l(f"package sokol_{inp['module']}")
- gen_imports(inp, dep_prefixes)
+ gen_imports(dep_prefixes)
+ gen_helpers(inp)
prefix = inp['prefix']
gen_c_imports(inp, prefix)
for decl in inp['decls']: