logoalt Hacker News

Tepixyesterday at 6:13 PM0 repliesview on HN

Here is a minimal example for inline webassembly: A function a that adds two numbers. Can someone make the entire example shorter? (added linebreaks for readability)

    <!DOCTYPE html>
    <p id=r>
    <script>
    WebAssembly.instantiateStreaming(fetch(
    'data:application/wasm;base64,AGFzbQEAAAABBwFgAn9/AX8DAgEABwUBAWEAAAoJAQcAIAAgAWoL'))
    .then(x=>r.append(x.instance.exports.a(51,4)))
    </script>

And here is the wat code that we can turn into wasm with wat2wasm and then into base64 for a data URL:

    (module
      (func (export "a") (param i32 i32) (result i32)
        local.get 0
        local.get 1
        i32.add))