forked from bytecodealliance/wasm-micro-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples/native-lib: Add a bit more complicated example (bytecodeallia…
…nce#1643) Add test_hello sample and update the document
- Loading branch information
Showing
4 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) 2019 Intel Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "wasm_export.h" | ||
|
||
static int | ||
test_hello_wrapper(wasm_exec_env_t exec_env, const char *name, char *result, | ||
size_t resultlen) | ||
{ | ||
return snprintf(result, resultlen, "Hello, %s. This is %s!\n", name, | ||
__func__); | ||
} | ||
|
||
/* clang-format off */ | ||
#define REG_NATIVE_FUNC(func_name, signature) \ | ||
{ #func_name, func_name##_wrapper, signature, NULL } | ||
|
||
static NativeSymbol native_symbols[] = { | ||
REG_NATIVE_FUNC(test_hello, "($*~)i") | ||
}; | ||
/* clang-format on */ | ||
|
||
uint32_t | ||
get_native_lib(char **p_module_name, NativeSymbol **p_native_symbols) | ||
{ | ||
*p_module_name = "env"; | ||
*p_native_symbols = native_symbols; | ||
return sizeof(native_symbols) / sizeof(NativeSymbol); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters