Skip to content

Commit

Permalink
Merge pull request #1048 from trace-andreason/master
Browse files Browse the repository at this point in the history
Changes to support generating the sokol-fetch bindings in zig
  • Loading branch information
floooh committed May 15, 2024
2 parents f70cc07 + 91cb0f9 commit 8b747dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
6 changes: 5 additions & 1 deletion bindgen/gen_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
gen_nim.gen(c_header_path, main_prefix, dep_prefixes)

# Zig
zig_tasks = [
*tasks,
[ '../sokol_fetch.h', 'sfetch_', [] ],
]
gen_zig.prepare()
for task in tasks:
for task in zig_tasks:
[c_header_path, main_prefix, dep_prefixes] = task
gen_zig.gen(c_header_path, main_prefix, dep_prefixes)

Expand Down
4 changes: 4 additions & 0 deletions bindgen/gen_zig.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'sdtx_': 'debugtext',
'sshape_': 'shape',
'sglue_': 'glue',
'sfetch_': 'sfetch',
}

c_source_paths = {
Expand All @@ -33,6 +34,7 @@
'sdtx_': 'sokol-zig/src/sokol/c/sokol_debugtext.c',
'sshape_': 'sokol-zig/src/sokol/c/sokol_shape.c',
'sglue_': 'sokol-zig/src/sokol/c/sokol_glue.c',
'sfetch_': 'sokol-zig/src/sokol/c/sokol_fetch.c'
}

ignores = [
Expand Down Expand Up @@ -60,6 +62,8 @@
'sshape_element_range_t.num_elements': 'uint32_t',
'sdtx_font.font_index': 'uint32_t',
'SGL_NO_ERROR': 'SGL_ERROR_NO_ERROR',
'sfetch_continue': 'continue_fetching', # 'continue' is reserved in Zig
'sfetch_desc': 'sfetch_get_desc' # 'desc' shadowed by earlier definiton
}

prim_types = {
Expand Down
17 changes: 7 additions & 10 deletions sokol_fetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -1071,17 +1071,14 @@ typedef struct sfetch_response_t {
sfetch_range_t buffer; // the user-provided buffer which holds the fetched data
} sfetch_response_t;

/* response callback function signature */
typedef void(*sfetch_callback_t)(const sfetch_response_t*);

/* request parameters passed to sfetch_send() */
typedef struct sfetch_request_t {
uint32_t channel; // index of channel this request is assigned to (default: 0)
const char* path; // filesystem path or HTTP URL (required)
sfetch_callback_t callback; // response callback function pointer (required)
uint32_t chunk_size; // number of bytes to load per stream-block (optional)
sfetch_range_t buffer; // a memory buffer where the data will be loaded into (optional)
sfetch_range_t user_data; // ptr/size of a POD user data block which will be memcpy'd (optional)
uint32_t channel; // index of channel this request is assigned to (default: 0)
const char* path; // filesystem path or HTTP URL (required)
void (*callback) (const sfetch_response_t*); // response callback function pointer (required)
uint32_t chunk_size; // number of bytes to load per stream-block (optional)
sfetch_range_t buffer; // a memory buffer where the data will be loaded into (optional)
sfetch_range_t user_data; // ptr/size of a POD user data block which will be memcpy'd (optional)
} sfetch_request_t;

/* setup sokol-fetch (can be called on multiple threads) */
Expand Down Expand Up @@ -1302,7 +1299,7 @@ typedef struct {
uint32_t channel;
uint32_t lane;
uint32_t chunk_size;
sfetch_callback_t callback;
void (*callback) (const sfetch_response_t*);
sfetch_range_t buffer;

/* updated by IO-thread, off-limits to user thread */
Expand Down

0 comments on commit 8b747dd

Please sign in to comment.