-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(wasm-api): update/extract C types & core API
- Loading branch information
1 parent
c435caa
commit 9eb827e
Showing
2 changed files
with
81 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <stddef.h> | ||
|
||
typedef char* WASM_StringPtr; | ||
typedef const char* WASM_ConstStringPtr; | ||
|
||
typedef void* WASM_OpaquePtr; | ||
typedef const void* WASM_ConstOpaquePtr; | ||
|
||
// slice-based string | ||
typedef struct { WASM_StringPtr ptr; size_t len; } WASM_String; | ||
typedef struct { WASM_ConstStringPtr ptr; size_t len; } WASM_ConstString; | ||
|
||
// defines slice wrapper structs for given pointer types | ||
#define WASMAPI_SLICE(PREFIX, NAME, PTR, CONSTPTR) \ | ||
typedef struct { PTR* ptr; size_t len; } PREFIX##NAME##Slice; \ | ||
typedef struct { CONSTPTR* ptr; size_t len; } PREFIX##Const##NAME##Slice; | ||
|
||
// slice of string slices | ||
WASMAPI_SLICE(WASM_, String, WASM_String, WASM_ConstString) | ||
|
||
// slice of string pointers | ||
WASMAPI_SLICE(WASM_, StringPtr, WASM_StringPtr, WASM_ConstStringPtr) | ||
|
||
// slice of opaque pointers | ||
WASMAPI_SLICE(WASM_, OpaquePtr, WASM_OpaquePtr, WASM_ConstOpaquePtr) | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |