Skip to content

Wasmtime::Component::Instance.get_func(handle) -> form of handle unclear #619

Description

@teleyos

Hi, i have a game.wasm component.
If i do wasm-tools component wit game.wasm i get

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<error-code, string>;

    type play-result = result<u8, error>;

    enum player {
      first,
      second,
    }

    type grid = list<option<player>>;

    type winner = player;

    resource state {
      constructor();
      play: func(index: s8) -> play-result;
      check-finished: func() -> tuple<bool, option<winner>>;
    }
  }
}

I want the name or path that i need to give to give to get_func in order to get the check_finished Func.

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 :

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions