Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
Created June 26, 2020 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamSaffron/eef88564b0ae4e32cd21dbc5a576261e to your computer and use it in GitHub Desktop.
Save SamSaffron/eef88564b0ae4e32cd21dbc5a576261e to your computer and use it in GitHub Desktop.
require 'mini_racer'
ctx = MiniRacer::Context.new
ctx.attach("print", proc {|x| puts x})
ctx.attach("read", proc {|f, type| File.read(f)})
ctx.attach("quit", proc {|status| exit(status)})
ctx.attach("readbuffer", proc {|f| File.read(f).each_char.map(&:to_i)})
#ctx.eval("WebAssembly.instantiate(readbuffer('hello.wasm'), { imports: {} }).then(r => print(999)).catch(e => print('bang'))")
#ctx.eval("1")
#exit
ctx.eval <<~JS
Module = {
print: print,
printErr: function(x) { print("ERR: " + x); }
}
JS
ctx.eval(File.read('hello.js'))
puts "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment