This repository has been archived on 2023-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
wasm-micro-runtime/language-bindings/python/samples/hello_oop.py
Wenyong Huang 3d34a91f0b
Implement Python language binding (#1192) (#1195)
Implement the first version of Python language binding

Co-authored-by: liang.he <liang.he@intel.com>
2022-05-31 16:39:46 +08:00

42 lines
863 B
Python

#!/usr/bin/env python3
#
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
import ctypes
from wamr import *
def hello_callback():
print("Calling back...")
print("> Hello World!")
def main():
print("Initializing...")
engine = Engine()
store = Store(engine)
print("Loading binary...")
print("Compiling module...")
module = Module.from_file(engine, "./hello.wasm")
print("Creating callback...")
hello = Func(store, FuncType([], []), hello_callback)
print("Instantiating module...")
instance = Instance(store, module, [hello])
print("Extracting export...")
run = instance.exports(store)["run"]
print("Calling export...")
run(store)
print("Shutting down...")
print("Done.")
if __name__ == "__main__":
main()