bytecodealliance / bytecodealliance/wasmtime-rb
Wasmtime::Component::Instance.get_func(handle) -> form of handle unclear
- Dominant language
- Rust
- Stars
- 146
- Forks
- 28
- Avg merge
- 7h 52m
- Merged PRs (30d)
- 9
Description
Hi, i have a game.wasm component.
If i do `wasm-tools component wit game.wasm` i get
```wit
package root:component;
world root {
export teleyos:connect4/types@0.0.1;
}
package teleyos:connect4@0.0.1 {
interface types {
enum error-code {
col-not-empty,
out-of-bound,
}
type error = tuple;
type play-result = result;
enum player {
first,
second,
}
type grid = list>;
type winner = player;
resource state {
constructor();
play: func(index: s8) -> play-result;
check-finished: func() -> tuple>;
}
}
}
```
I want the name or path that i need to give to give to [get_func](https://bytecodealliance.github.io/wasmtime-rb/latest/Wasmtime/Component/Instance.html#get_func-instance_method) in order to get the check_finished [Func](https://bytecodealliance.github.io/wasmtime-rb/latest/Wasmtime/Component/Func.html).
I tried a lot of possibilities but i struggle to find which path to give because it's in root > teleyos:connect4@0.0.1 > types > state > check-finished and i don't know how to articulate that even after looking at the docs and source code.
I have this for now :
```ruby
require 'wasmtime'
engine = Wasmtime::Engine.new
component = Wasmtime::Component::Component.from_file(engine, "./game.wasm")
store = Wasmtime::Store.new(engine, {})
linker = Wasmtime::Component::Linker.new(engine)
instance = linker.instantiate(store, component)
check_finished_func = instance.get_func(["root", "teleyos:connect4@0.0.1","types","state","check-finished"])
if (check_finished_func == nil) then
puts "didn't find function"
puts check_finished_func
exit
end
```
Update: Working on implementing Resource bindings and exposing a way to discover exports and their names.
Contributor guide
Research direction
Start with Wasmtime::Component::Instance#get_func and its linked API documentation and source code, then review the resource-bindings work mentioned in the update. Trace how the WIT export path for state/check-finished is represented; done means the requested Func can be obtained or the supported export and resource-discovery behavior is clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby, rust, wasm
- Domain
- api, developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100