System object ‣ wasi - chung-leong/zigar GitHub Wiki

An object that implements the WebAssembly System Interface (WASI) that will provide baseline support for system calls.

Usage

const std = @import("std");

pub fn print(path: []const u8) !void {
    var file = try std.fs.openFileAbsolute(path, .{});
    defer file.close();
    const stdout = std.io.getStdOut();
    var buffer: [128]u8 = undefined;
    while (true) {
        const read = try file.read(&buffer);
        if (read == 0) break;
        _ = try stdout.write(buffer[0..read]);
    }
}
import { fileURLToPath } from 'node:url';
import { WASI } from 'node:wasi';
import { __zigar, print } from './system-object-wasi-example-1.zig';
const { set } = __zigar;

set('wasi', new WASI({
  version: 'preview1',
  args: [],
  env: {},
  preopens: { '/': '/' },
}));

const path = fileURLToPath(import.meta.url);
print(path);
import { fileURLToPath } from 'node:url';
import { WASI } from 'node:wasi';
import { __zigar, print } from './system-object-wasi-example-1.zig';
const { set } = __zigar;

set('wasi', new WASI({
  version: 'preview1',
  args: [],
  env: {},
  preopens: { '/': '/' },
}));

const path = fileURLToPath(import.meta.url);
print(path);

System objects