29 lines
740 B
Python
29 lines
740 B
Python
import wasm3 # type: ignore
|
|
|
|
from phasmplatform.common.exceptions import PhashPlatformNonIntMainReturnError
|
|
|
|
|
|
def post_message(namespace: int, topic: int, kind: int, body: int) -> None:
|
|
print('namespace', namespace)
|
|
print('topic', topic)
|
|
print('kind', kind)
|
|
print('body', body)
|
|
|
|
|
|
def run_once_wasm3(wasm_bin: bytes) -> int:
|
|
env = wasm3.Environment()
|
|
rtime = env.new_runtime(1024 * 1024)
|
|
|
|
mod = env.parse_module(wasm_bin)
|
|
mod.link_function('imports', 'post_message', post_message)
|
|
|
|
rtime.load(mod)
|
|
result = rtime.find_function('handle_message')()
|
|
if result is None:
|
|
return 0
|
|
|
|
if not isinstance(result, int):
|
|
raise PhashPlatformNonIntMainReturnError(result)
|
|
|
|
return result
|