mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-06 23:15:16 +00:00
3cc132e8fc
Before adding the new bindings: 1. Moved wasm-c-api in a subfolder wasmcapi in the package. 2. Adapted the tests to be able to run in this new structure. New: 1. Added the WAMR API in another folder wamrapi in the same level as wasm-c-api. 2. Created an OOP proposal. 3. Added an example using this proposal.
42 lines
863 B
Python
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()
|