Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/npm-packages/ruby-wasm-wasi/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ $ # Open http://localhost:8000/script-src
```console
$ npm install
$ node --experimental-wasi-unstable-preview1 index.node.js
$ node ruby-box.node.js
```
28 changes: 28 additions & 0 deletions packages/npm-packages/ruby-wasm-wasi/example/ruby-box.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import fs from "fs/promises";
import { DefaultRubyVM } from "@ruby/wasm-wasi/dist/node";

// $ node ruby-box.node.js

const main = async () => {
const binary = await fs.readFile(
"./node_modules/@ruby/head-wasm-wasi/dist/ruby.wasm",
);
const module = await WebAssembly.compile(binary);
const { vm } = await DefaultRubyVM(module, {
env: {
RUBY_BOX: "1",
},
});

vm.eval(`
box = Ruby::Box.new
box.eval <<~RUBY
X = 123
RUBY

puts "Ruby::Box.enabled?: #{Ruby::Box.enabled?}"
puts "box::X: #{box::X}"
`);
};

main();
Loading