Coverage for examples/hello.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-02-20 16:25 +0000

1from wasmtime import Store, Module, Instance, Func, FuncType 

2 

3# Almost all operations in wasmtime require a contextual "store" argument to be 

4# shared amongst objects 

5store = Store() 

6 

7# Here we can compile a `Module` which is then ready for instantiation 

8# afterwards 

9module = Module.from_file(store.engine, './examples/hello.wat') 

10 

11# Our module needs one import, so we'll create that here. 

12 

13 

14def say_hello(): 

15 print("Hello from Python!") 

16 

17 

18hello = Func(store, FuncType([], []), say_hello) 

19 

20# And with all that we can instantiate our module and call the export! 

21instance = Instance(store, module, [hello]) 

22instance.exports(store)["run"](store)