veewee/ext-wasm

Support WebAssembly Memory

Opened this issue · 0 comments

See:

$memory = new Wasm\Memory(
    minimumPages: 1 
    maximulPages: null,
    shared: true
);

$instance = Wasm\InstanceBuilder::fromWat($wat)
    ->withImports(['env' => ['someMemory' => $memory]])
    ->build();

$memory = $instance->someMemory();

// settings
$sizeInBytes = $memory->bytes();
$sizeInPages = $memory->pages();
$memory->grow(2);

// views
// TODO: possibly add an ArrayWrapper or Buffer that allows both read and write
$str = pack('C*', ...$memory->view()); // TODO : separate int[n] vs float[n] views

// Buffer Resource
$resource = $memory->buffer();
fseek($resource, 0);
fread($resource, $memory->bytes());
fwrite($resource, $data);