@thi.ng/wasm-api 0.6.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -1
- package/README.md +336 -39
- package/api.d.ts +91 -14
- package/bin/wasm-api +12 -0
- package/bridge.d.ts +4 -3
- package/bridge.js +6 -3
- package/cli.d.ts +5 -0
- package/cli.js +142 -0
- package/codegen/typescript.d.ts +13 -0
- package/codegen/typescript.js +65 -22
- package/codegen/utils.d.ts +29 -4
- package/codegen/utils.js +27 -4
- package/codegen/zig.d.ts +3 -0
- package/codegen/zig.js +5 -6
- package/codegen.d.ts +38 -1
- package/codegen.js +48 -16
- package/include/wasmapi.h +6 -0
- package/include/wasmapi.zig +6 -0
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/package.json +15 -11
package/include/wasmapi.h
CHANGED
|
@@ -7,9 +7,13 @@ extern "C" {
|
|
|
7
7
|
#include <stddef.h>
|
|
8
8
|
#include <stdint.h>
|
|
9
9
|
|
|
10
|
+
// Declares an imported symbol from named import module
|
|
11
|
+
// The prefix is only used for the C side, NOT for exported name
|
|
10
12
|
#define WASM_IMPORT(MODULE, TYPE, NAME, PREFIX) \
|
|
11
13
|
extern __attribute__((import_module(MODULE), import_name(#NAME))) \
|
|
12
14
|
TYPE PREFIX##NAME
|
|
15
|
+
|
|
16
|
+
// Same as EMSCRIPTEN_KEEP_ALIVE, ensures symbol will be exported
|
|
13
17
|
#define WASM_KEEP __attribute__((used))
|
|
14
18
|
|
|
15
19
|
// Generate stubs only if explicitly disabled by defining this symbol
|
|
@@ -53,6 +57,8 @@ WASM_IMPORT("wasmapi", void, _printF64Array, wasm)(void* addr, size_t len);
|
|
|
53
57
|
WASM_IMPORT("wasmapi", void, _printStr0, wasm)(void* addr);
|
|
54
58
|
WASM_IMPORT("wasmapi", void, _printStr, wasm)(void* addr, size_t len);
|
|
55
59
|
|
|
60
|
+
WASM_IMPORT("wasmapi", void, debug, wasm_)(void);
|
|
61
|
+
|
|
56
62
|
void wasm_printPtr(void* ptr) { wasm_printU32Hex((size_t)ptr); }
|
|
57
63
|
|
|
58
64
|
#ifdef __cplusplus
|
package/include/wasmapi.zig
CHANGED
|
@@ -165,6 +165,9 @@ pub fn printStr(msg: []const u8) void {
|
|
|
165
165
|
_printStr(@ptrToInt(msg.ptr), msg.len);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
/// Calls std.fmt.allocPrint to format given string, then calls `printStr()`
|
|
169
|
+
/// to output it via JS, then frees string's memory again
|
|
170
|
+
/// (Only available if the allocator used by `_wasm_allocate()` hasn't been disabled.)
|
|
168
171
|
pub fn printFmt(comptime fmt: []const u8, args: anytype) void {
|
|
169
172
|
if (allocator) |alloc| {
|
|
170
173
|
const res = std.fmt.allocPrint(alloc, fmt, args) catch return;
|
|
@@ -172,3 +175,6 @@ pub fn printFmt(comptime fmt: []const u8, args: anytype) void {
|
|
|
172
175
|
printStr(res);
|
|
173
176
|
}
|
|
174
177
|
}
|
|
178
|
+
|
|
179
|
+
/// Triggers the JS/browser debugger
|
|
180
|
+
pub extern "wasmapi" fn debug() void;
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from "./api.js";
|
|
2
2
|
export * from "./bridge.js";
|
|
3
3
|
export * from "./codegen.js";
|
|
4
|
-
export * from "./object-index.js";
|
|
5
4
|
export * from "./codegen/typescript.js";
|
|
6
|
-
export * from "./codegen/zig.js";
|
|
7
5
|
export * from "./codegen/utils.js";
|
|
6
|
+
export * from "./codegen/zig.js";
|
|
7
|
+
export * from "./object-index.js";
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./api.js";
|
|
2
2
|
export * from "./bridge.js";
|
|
3
3
|
export * from "./codegen.js";
|
|
4
|
-
export * from "./object-index.js";
|
|
5
4
|
export * from "./codegen/typescript.js";
|
|
6
|
-
export * from "./codegen/zig.js";
|
|
7
5
|
export * from "./codegen/utils.js";
|
|
6
|
+
export * from "./codegen/zig.js";
|
|
7
|
+
export * from "./object-index.js";
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/wasm-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Generic, modular, extensible API bridge, glue code and bindings code generator for hybrid JS & WebAssembly projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
7
7
|
"typings": "./index.d.ts",
|
|
8
|
+
"bin": "bin/wasm-api",
|
|
8
9
|
"sideEffects": false,
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
@@ -35,19 +36,21 @@
|
|
|
35
36
|
"test:build-zig": "zig build-lib -O ReleaseSmall -target wasm32-freestanding -dynamic --strip --pkg-begin wasmapi include/wasmapi.zig --pkg-end test/custom.zig && wasm-dis -o custom.wast custom.wasm && cp custom.wasm test"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@thi.ng/api": "^8.4.
|
|
39
|
-
"@thi.ng/
|
|
39
|
+
"@thi.ng/api": "^8.4.1",
|
|
40
|
+
"@thi.ng/args": "^2.2.1",
|
|
41
|
+
"@thi.ng/binary": "^3.3.4",
|
|
40
42
|
"@thi.ng/checks": "^3.2.4",
|
|
41
|
-
"@thi.ng/compare": "^2.1.
|
|
42
|
-
"@thi.ng/defmulti": "^2.1.
|
|
43
|
+
"@thi.ng/compare": "^2.1.11",
|
|
44
|
+
"@thi.ng/defmulti": "^2.1.13",
|
|
43
45
|
"@thi.ng/errors": "^2.1.10",
|
|
46
|
+
"@thi.ng/file-io": "^0.3.10",
|
|
44
47
|
"@thi.ng/hex": "^2.1.9",
|
|
45
|
-
"@thi.ng/idgen": "^2.1.
|
|
46
|
-
"@thi.ng/logger": "^1.2.
|
|
48
|
+
"@thi.ng/idgen": "^2.1.12",
|
|
49
|
+
"@thi.ng/logger": "^1.2.1"
|
|
47
50
|
},
|
|
48
51
|
"devDependencies": {
|
|
49
52
|
"@microsoft/api-extractor": "^7.25.0",
|
|
50
|
-
"@thi.ng/testament": "^0.2.
|
|
53
|
+
"@thi.ng/testament": "^0.2.12",
|
|
51
54
|
"rimraf": "^3.0.2",
|
|
52
55
|
"tools": "^0.0.1",
|
|
53
56
|
"typedoc": "^0.22.17",
|
|
@@ -80,8 +83,9 @@
|
|
|
80
83
|
"files": [
|
|
81
84
|
"*.js",
|
|
82
85
|
"*.d.ts",
|
|
83
|
-
"
|
|
84
|
-
"include"
|
|
86
|
+
"bin",
|
|
87
|
+
"include",
|
|
88
|
+
"codegen"
|
|
85
89
|
],
|
|
86
90
|
"exports": {
|
|
87
91
|
".": {
|
|
@@ -113,5 +117,5 @@
|
|
|
113
117
|
"status": "alpha",
|
|
114
118
|
"year": 2022
|
|
115
119
|
},
|
|
116
|
-
"gitHead": "
|
|
120
|
+
"gitHead": "be8423e2019e95c14a096260a93b9762dde0c768\n"
|
|
117
121
|
}
|