Comments (3)
Thanks @alexcrichton , it works!
And to help others with the same requirement, I paste my code below as an example:
wat := `
(module
(import "foo" "hello" (func $hello1 (param externref)))
(import "bar" "hello" (func $hello2 (param externref)))
(func (export "run")(param externref)
local.get 0
call $hello1
local.get 0
call $hello2
)
)`
wasm, _ := wasmtime.Wat2Wasm(wat)
cfg := wasmtime.NewConfig()
cfg.SetWasmReferenceTypes(true)
store := wasmtime.NewStore(wasmtime.NewEngineWithConfig(cfg))
linker := wasmtime.NewLinker(store)
linker.DefineFunc("foo", "hello", func(w io.Writer) {
fmt.Fprintln(w, "foo.hello from Go!")
})
linker.DefineFunc("bar", "hello", func(w io.Writer) {
fmt.Fprintln(w, "bar.hello from Go!")
})
module, _ := wasmtime.NewModule(store.Engine, wasm)
instance, _ := linker.Instantiate(module)
run := instance.GetExport("run").Func()
run.Call(os.Stdout)
from wasmtime-go.
Indeed it can be imported by name! For that you'll want to use Linker
combined with Define
where you can define functions by name to get imported.
Does that work for your use case?
from wasmtime-go.
Ok glad it works for you!
from wasmtime-go.
Related Issues (20)
- Is it possible to dynamically link several wasm modules in Go host? HOT 6
- Works with wit-bindgen? HOT 3
- Out of bounds memory access panic HOT 5
- Support for ARM macs with bazel
- Allocation too large< ~lib/rt/itcms.ts<$Index out of range,~lib/rt.ts HOT 4
- Add changelog/releases info HOT 1
- SetMaxWasmStack fails with async_stack_size error HOT 6
- Please elaborate on installation instructions for unsupported platforms HOT 1
- Does debugging work when embedding in go like rust? HOT 1
- Equivalence for `WasiCtx.insert_file` from wasmtime_wasi Rust crate HOT 14
- Minor release HOT 4
- Windows build failure: undefined reference to `_setjmp' HOT 7
- Error out when using wasmtime-go to run Python code HOT 2
- Compilation failure on 32-bit systems HOT 3
- How to monitor memory usage HOT 4
- Go get latest version failed
- Missing V15 features.component_model in config HOT 3
- Support v16? HOT 2
- Feature request: support manual freeing of resources HOT 2
- No compiled main function from file called HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasmtime-go.