zoukankan      html  css  js  c++  java
  • 使用Go编写WebAssembly

    (Windows10 WSL) 

    I. Install go

        see 《install go on ubuntu

    II. go wasm

    1. compile

    set GOARCH=wasm
    set GOOS=js
    go build -o helloworld.wasm helloworld.go

    2. set mime type

    /etc/mime.types
    Ln132:

    application/wasm        wasm

    3. run


    (1) other files


    1) wasm_exec
    from E:progFilesgomiscwasm
    to e:go-project

    2) helloworld.html

    <html>
        <head>
            <meta charset="utf-8">
            <script src="wasm_exec.js"></script>
            <script>
                const go = new Go();
                WebAssembly.instantiateStreaming(fetch("helloworld.wasm"), go.importObject).then((result) => {
                    go.run(result.instance);
                });
            </script>
        </head>
        <body></body>
    </html>

    (2) exec

    cd /mnt/e/go-project
    python -m SimpleHTTPServer 8080

    http://localhost:8080/helloworld.html

    src: helloworld.go

    package main
    
    import (  
        "fmt"  
    )
    
    
    func main() {
        var str string
        var i = 1
        str = "Hello, WebAssembly!"
        
        for i < 10 {
            fmt.Println(str, i)
            i++
        }
    }

     开发者工具--》Console

    Reference:

        https://github.com/golang/go/wiki/WebAssembly

  • 相关阅读:
    C#反射
    做下一周计划
    OFFSET 函数
    微信跳一跳学习笔记
    跳一跳脚本代码搬运
    预测羽毛球赛成绩学习笔记
    将Python123中作业成绩绘制成雷达图
    Matplotlib库
    Numpy库
    第四周作业
  • 原文地址:https://www.cnblogs.com/xiaobin-hlj80/p/10624150.html
Copyright © 2011-2022 走看看