wasm-micro-runtime/samples/basic
TianlongLiang c3e33a96ea
Remove unused argument in wasm_runtime_lookup_function and refactor WASMModuleInstance (#3218)
Remove the unused parameter `signature` from `wasm_runtime_lookup_function`.

Refactor the layout of WASMModuleInstance structure:
- move common data members `c_api_func_imports` and `cur_exec_env` from
  `WASMModuleInstanceExtraCommon` to `WASMModuleInstance`
- In `WASMModuleInstance`, enlarge `reserved[3]` to `reserved[5]` in case that
  we need to add more fields in the future

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/issues/2530
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3202
2024-03-13 12:28:45 +08:00
..
src Remove unused argument in wasm_runtime_lookup_function and refactor WASMModuleInstance (#3218) 2024-03-13 12:28:45 +08:00
wasm-apps Fix sample basic intToStr was called with wrong length (#2876) 2023-12-07 10:26:28 +08:00
.gitignore Fix function type not set issue of aot_call_indirect (#229) 2020-04-07 11:04:46 +08:00
build.sh Forward log and log level to custom bh_log callback (#3070) 2024-01-24 13:05:07 +08:00
CMakeLists.txt Enable MASM automatically in runtime_lib.cmake (#2634) 2023-10-12 20:42:25 +08:00
README.md fix one typo in samples/basic.README.md (#274) 2020-06-03 15:17:22 +08:00
run.sh Add a basic sample to show how native runtime invokes wasm apps in WAMR and how wasm apps invoke native functions. (#207) 2020-03-20 16:39:13 +08:00

The "basic" sample project

This sample demonstrates a few basic usages of embedding WAMR:

  • initialize runtime
  • load wasm app and instantiate the module
  • call wasm function and pass arguments
  • export native functions to the WASM apps
  • wasm function calls native function and pass arguments
  • deinitialize runtime

Build this sample

Execute the build.sh script then all binaries including wasm application files would be generated in 'out' directory.

$ ./build.sh

Run the sample

Enter the out directory.

$ cd ./out/
$
$ ./basic -f wasm-apps/testapp.wasm
calling into WASM function: generate_float
Native finished calling wasm function generate_float(), returned a float value: 102009.921875f
calling into WASM function: float_to_string
calling into native function: intToStr
calling into native function: get_pow
calling into native function: intToStr
Native finished calling wasm function: float_to_string, returned a formatted string: 102009.921

Or execute the run.sh script in samples/basic folder.

$ ./run.sh
calling into WASM function: generate_float
Native finished calling wasm function generate_float(), returned a float value: 102009.921875f
calling into WASM function: float_to_string
calling into native function: intToStr
calling into native function: get_pow
calling into native function: intToStr
Native finished calling wasm function: float_to_string, returned a formatted  string: 102009.921