System object ‣ wasi - chung-leong/zigar GitHub Wiki
JavaScript | PHP
An object that implements the WebAssembly System Interface (WASI) that will provide baseline support for system calls.
Usage
const std = @import("std");
var threaded_io = std.Io.Threaded.init_single_threaded;
const io = threaded_io.io();
pub fn print(path: []const u8) !void {
var file = try std.Io.Dir.openFileAbsolute(io, path, .{});
defer file.close(io);
const stdout = std.Io.File.stdout();
var buffer: [128]u8 = undefined;
while (true) {
const read = file.readStreaming(io, &[1][]u8{&buffer}) catch break;
if (read == 0) break;
_ = try stdout.writeStreaming(io, "", &[1][]u8{buffer[0..read]}, 1);
}
}
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);