Skip to content

Instantly share code, notes, and snippets.

@Yardanico
Created July 1, 2020 22:57
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 Yardanico/1717feb2aee4bd9298191be6255f0673 to your computer and use it in GitHub Desktop.
Save Yardanico/1717feb2aee4bd9298191be6255f0673 to your computer and use it in GitHub Desktop.
import ../wasmrt, mathexpr, strutils
let e = newEvaluator()
e.addVar("a", 5.5)
echo e.eval("2 + 2 * 2 - 4 + a - 2.5").int
<html>
<head>
<title>Webasm test nim</title>
</head>
<body>
<script>
function runNimWasm(w){for(i of WebAssembly.Module.exports(w)){n=i.name;if(n[0]==';'){new Function('m',n)(w);break}}}
fetch("test.wasm").then(response =>
response.arrayBuffer()
).then(bytes =>
WebAssembly.compile(bytes)
).then(mod =>
runNimWasm(mod)
);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment