hello_oop.py 863 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  4. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. #
  6. import ctypes
  7. from wamr import *
  8. def hello_callback():
  9. print("Calling back...")
  10. print("> Hello World!")
  11. def main():
  12. print("Initializing...")
  13. engine = Engine()
  14. store = Store(engine)
  15. print("Loading binary...")
  16. print("Compiling module...")
  17. module = Module.from_file(engine, "./hello.wasm")
  18. print("Creating callback...")
  19. hello = Func(store, FuncType([], []), hello_callback)
  20. print("Instantiating module...")
  21. instance = Instance(store, module, [hello])
  22. print("Extracting export...")
  23. run = instance.exports(store)["run"]
  24. print("Calling export...")
  25. run(store)
  26. print("Shutting down...")
  27. print("Done.")
  28. if __name__ == "__main__":
  29. main()