Coverage for examples/hello.py: 27%
11 statements
« prev ^ index » next coverage.py v7.11.3, created at 2025-12-01 19:40 +0000
« prev ^ index » next coverage.py v7.11.3, created at 2025-12-01 19:40 +0000
1from wasmtime import Store, Module, Instance, Func, FuncType
3def run():
4 # Almost all operations in wasmtime require a contextual "store" argument to be
5 # shared amongst objects
6 store = Store()
8 # Here we can compile a `Module` which is then ready for instantiation
9 # afterwards
10 module = Module.from_file(store.engine, './examples/hello.wat')
12 # Our module needs one import, so we'll create that here.
15 def say_hello():
16 print("Hello from Python!")
19 hello = Func(store, FuncType([], []), say_hello)
21 # And with all that we can instantiate our module and call the export!
22 instance = Instance(store, module, [hello])
23 instance.exports(store)["run"](store)
25if __name__ == '__main__':
26 run()