Files
experimental-evaluation-of-…/chapters/05_experiment_setup/listings/wamrmodulecall.cpp
T

24 lines
751 B
C++

// Error handling is omitted
char error_buf[128];
wasm_module_t module = wasm_runtime_load(
module_array, module_array_length, error_buf, sizeof(error_buf));
wasm_module_inst_t module_inst = wasm_runtime_instantiate(
module, STACK_SIZE, HEAP_SIZE, error_buf, sizeof(error_buf));
wasm_exec_env_t exec_env = wasm_runtime_create_exec_env(
module_inst, STACK_SIZE);
wasm_function_inst_t func = wasm_runtime_lookup_function(
module_inst, "wasm_module");
// Arguments can be supplied to the function
// by passing a pointer to an args buffer.
// No arguments are set here, but a single
// slot is reserved for the return value.
uint32_t argv[1];
uint32_t argc = 0;
wasm_runtime_call_wasm(exec_env, func, argc, argv);
uint32_t retval = argv[0];