hybridgroup / mechanoid

Mechanoid is a framework for WebAssembly applications on embedded systems and IoT devices.
https://mechanoid.io
Apache License 2.0
170 stars 8 forks source link

engine: add LoadAndRun method to reduce needed code to support most typical usage #23

Closed deadprogram closed 4 months ago

deadprogram commented 4 months ago

This PR adds a LoadAndRun() method to the engine to reduce the boilerplate needed code to support the most typical usage.

deadprogram commented 4 months ago

With this change you can now do this:

    println("Loading and running WASM code...")
    ins, err := eng.LoadAndRun(bytes.NewReader(wasmCode))
    if err != nil {
        println(err.Error())
        return
    }

instead of always having to do this:

    println("Loading WASM module...")
    if err := eng.Interpreter.Load(bytes.NewReader(wasmModule)); err != nil {
        println(err.Error())
        return
    }

    println("Running module...")
    ins, err := eng.Interpreter.Run()
    if err != nil {
        println(err.Error())
        return
    }
deadprogram commented 4 months ago

Based on side-channel conversation with @orsinium we will also do some additional work in future PR to better scope Interpreter and Module for the individual Load() and Run() methods respectively.

deadprogram commented 4 months ago

Now merging.