1
0
Fork 0

Make all fields readonly for wasm

This commit is contained in:
Pabloader 2026-05-22 09:10:19 +00:00
parent 1ceebeb5c7
commit 1637d4ed1b
3 changed files with 22 additions and 18 deletions

View File

@ -166,12 +166,12 @@ export function renderDts(wasmBytes: Uint8Array, meta?: Map<string, ExportMeta>)
return [
'// Auto-generated by wasmPlugin. Do not edit.',
'declare const _: {',
'declare const _: Readonly<{',
...fns.map(([name, sig]) => ` ${name}: ${tsSignature(sig, meta?.get(name))};`),
' memory: WebAssembly.Memory;',
' table: WebAssembly.Table;',
' readonly data: DataView;',
'};',
' data: DataView;',
'}>;',
'export default _;',
'',
].join('\n');

16
build/wasm.d.ts vendored
View File

@ -2,31 +2,31 @@
// After a build, a sibling `${file}.d.ts` with concrete export names takes precedence.
declare module '*.cpp' {
const _: {
const _: Readonly<{
memory: WebAssembly.Memory;
table: WebAssembly.Table;
readonly data: DataView;
data: DataView;
[fn: string]: unknown;
};
}>;
export default _;
}
declare module '*.c' {
const _: {
const _: Readonly<{
memory: WebAssembly.Memory;
table: WebAssembly.Table;
readonly data: DataView;
data: DataView;
[fn: string]: unknown;
};
}>;
export default _;
}
declare module '*.wasm' {
const _: {
const _: Readonly<{
memory: WebAssembly.Memory;
table?: WebAssembly.Table;
data: DataView;
[fn: string]: unknown;
};
}>;
export default _;
}

View File

@ -6,17 +6,17 @@
#include <stdlib.h>
#include <vec2.h>
#define TYPE_EMPTY 0
#define TYPE_CIRCLE 1
#define TYPE_PLANE 2
#define rb_get(idx) (rigid_bodies + (idx))
typedef enum : uint8_t {
TYPE_EMPTY = 0,
TYPE_CIRCLE = 1,
TYPE_PLANE = 2,
} body_type;
////////// Types
typedef struct rigid_body_t {
typedef struct {
// Public
uint8_t type;
body_type type;
uint8_t reserved[3];
vec2 pos;
vec2 vel;
@ -51,6 +51,10 @@ static rigid_body_collision_callback_t rigid_body_collision_callback = NULL;
////////// Functions
inline static rigid_body* rb_get(rigid_body_index idx) {
return (rigid_bodies + (idx));
}
JS_EXPORT rigid_body* rigid_body_get(rigid_body_index idx) {
return rb_get(idx);
}