36

Release 0.2.0 · wasmerio/go-ext-wasm · GitHub

 6 years ago
source link: https://github.com/wasmerio/go-ext-wasm/releases/tag/0.2.0
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Hywan released this on Jul 16, 2019 · 250 commits to master since this release

Features

  • #55 Add the Memory.Grow method (@Hywan)

  • #42 Improve error messages when instantiating (@Hywan)

  • #38 Support import descriptors (@Hywan)

    var module, _ = wasm.Compile(bytes)
    
    assert.Equal(…, "log_message", module.Imports[0].Name)
    assert.Equal(…, "env", module.Imports[0].Namespace)
  • #37 Support export descriptors (@Hywan)

    var module, _ = wasm.Compile(bytes)
    
    assert.Equal(…, "sum", module.Exports[7].Name)
  • #34 Support module serialization and deserialization (@Hywan)

    // Compiles the bytes into a WebAssembly module.
    module1, _ := wasm.Compile(GetBytes())
    defer module1.Close()
    
    // Serializes the module into a sequence of bytes.
    serialization, _ := module1.Serialize()
    
    // Do something with `serialization`.
    // Then later…
    
    // Deserializes the module.
    module2, _ := wasm.DeserializeModule(serialization)
    defer module2.Close()
    // And enjoy!
    
    // Instantiates the WebAssembly module.
    instance, _ := module2.Instantiate()
    defer instance.Close()
    
    // Gets an exported function.
    sum, functionExists := instance.Exports["sum"]
    
    fmt.Println(functionExists)
    
    // Calls the `sum` exported function with Go values.
    result, _ := sum(1, 2)
    
    fmt.Println(result)
    
    // Output:
    // true
    // 3
  • #33 Add Compile, Module.Instantiate* and Module.Close (@Hywan)

  • #30 Support instance context data (@Hywan)

    //export logMessageWithContextData
    func logMessageWithContextData(context unsafe.Pointer, pointer int32, length int32) {
            var instanceContext = wasm.IntoInstanceContext(context)
            var memory = instanceContext.Memory().Data()
            var logMessage = (*logMessageContext)(instanceContext.Data())
    
            logMessage.message = string(memory[pointer : pointer+length])
    }
    
    type logMessageContext struct {
            message string
    }
    
    func testImportInstanceContextData(t *testing.T) {
            imports, err := wasm.NewImports().Append("log_message", logMessageWithContextData, C.logMessageWithContextData)
            assert.NoError(t, err)
    
            instance, err := wasm.NewInstanceWithImports(getImportedFunctionBytes("log.wasm"), imports)
            assert.NoError(t, err)
    
            defer instance.Close()
    
            contextData := logMessageContext{message: "first"}
            instance.SetContextData(unsafe.Pointer(&contextData))
    
            doSomething := instance.Exports["do_something"]
    
            result, err := doSomething()
    
            assert.NoError(t, err)
            assert.Equal(t, wasm.TypeVoid, result.GetType())
            assert.Equal(t, "hello", contextData.message)
    }
  • #29 Add Imports.Namespace to set the current import namespace (@Hywan)

    // By default, the namespace is `"env"`. Change it to `"ns"`.
    wasm.NewImports().Namespace("ns").Append("f", f, C.f)
  • #26 Support instance context API (@Hywan)

Bug/security fixes

Documentation/Test

  • #51 Test that all Wasm types can be used in imported functions (@Hywan)
  • #36 Improve the Benchmarks Section (@Hywan)
  • #32 Move examples in the root directory for godoc.org (@Hywan)
  • #31 Fix example namespaces for godoc.org (@Hywan)
  • #30 Increase the cgocheck level (@Hywan)

Chore

Assets 2

</div


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK