Web assembly, internet's new toy...

edited November 2017 in Tech Support
it is available for a little while under Chrome and Firefox. Web assembly enables coder to compiles whatever language you coded into web assembly format.

for example, I did test it in nexus client to see if it will execute, and it worked. Although at the time, I don't think I can load wasm file from external site. still, alternatively, it is possible to store an utf8 array of bytecode of a compiled program in a script to execute.

e.g:


//Enter the function here

let wasmcode = {};

wasmcode.buffer = new Uint8Array([0,97,115,109,1,0,0,0,1,133,128,128,128,0,1,96,0,1,127,3,130,128,128,128,0,1,0,4,132,128,128,128,0,1,112,0,0,5,131,128,128,128,0,1,0,1,6,129,128,128,128,0,0,7,146,128,128,128,0,2,6,109,101,109,111,114,121,2,0,5,104,101,108,108,111,0,0,10,138,128,128,128,0,1,132,128,128,128,0,0,65,16,11,11,146,128,128,128,0,1,0,65,16,11,12,72,101,108,108,111,32,87,111,114,108,100,0]);


wasmcode.utf8ToString = function(h, p) {
  let s = "";
  for (i = p; h[i]; i++) {
    s += String.fromCharCode(h[i]);
  }
  return s;
}

wasmcode.m = new WebAssembly.Instance(new WebAssembly.Module(wasmcode.buffer));
wasmcode.h = new Uint8Array(wasmcode.m.exports.memory.buffer);

helloWorld = function (){
    wasmcode.p = wasmcode.m.exports.hello();
    print(wasmcode.utf8ToString(wasmcode.h, wasmcode.p));
};

window.wasmcode = wasmcode;
window.helloWorld = helloWorld;<br>

Then make alias 'helloWorld
' then add the only line to the script 'helloWorld();' to see it echoing. :D
'hello world' wasm compiled from C.

more info on web assembly:
http://webassembly.org/

In theory, it may be slightly, or more, faster than javascript depend in some situation.

2015/01/12 Tecton, the Terraformer has bestowed His divine favour upon you. It will last for approximately 1 Achaean month.

Comments

  • edited November 2017
    ugh, code block didn't add <br> to each line? nightmare...
    @Tecton
    @Sarapis

    I guess cut/paste is not very helpful. lol...

    edit: nevermind fixed. I just copied a code into notepad++ and back into code block in a post, so it worked okay. weird stuff.

    2015/01/12 Tecton, the Terraformer has bestowed His divine favour upon you. It will last for approximately 1 Achaean month.
Sign In or Register to comment.