[wasm] Bind native API
This commit is contained in:
parent
e79a7318c4
commit
9f4dc2e103
|
@ -48,6 +48,9 @@ HB_WASM_BEGIN_DECLS
|
|||
#ifndef HB_WASM_API
|
||||
#define HB_WASM_API(x) x
|
||||
#endif
|
||||
#ifndef HB_WASM_EXEC_ENV
|
||||
#define HB_WASM_EXEC_ENV
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef bool_t
|
||||
|
@ -61,13 +64,16 @@ typedef uint32_t buffer_t;
|
|||
/* font */
|
||||
|
||||
face_t
|
||||
HB_WASM_API (font_get_face) (font_t);
|
||||
HB_WASM_API (font_get_face) (HB_WASM_EXEC_ENV
|
||||
font_t);
|
||||
|
||||
|
||||
/* shape interface */
|
||||
|
||||
bool_t
|
||||
HB_WASM_API (shape) (font_t, buffer_t);
|
||||
HB_WASM_API (shape) (HB_WASM_EXEC_ENV
|
||||
font_t,
|
||||
buffer_t);
|
||||
|
||||
|
||||
HB_WASM_END_DECLS
|
||||
|
|
|
@ -27,11 +27,14 @@
|
|||
|
||||
#include "hb.h"
|
||||
|
||||
#include <wasm_export.h>
|
||||
|
||||
#define HB_WASM_API(x) HB_INTERNAL x
|
||||
#define HB_WASM_BEGIN_DECLS namespace hb { namespace wasm {
|
||||
#define HB_WASM_END_DECLS }}
|
||||
|
||||
#define HB_WASM_EXEC_ENV wasm_exec_env_t exec_env,
|
||||
|
||||
#include "hb-wasm-api.h"
|
||||
|
||||
#undef HB_WASM_API
|
||||
|
@ -41,5 +44,29 @@
|
|||
|
||||
#include "hb-wasm-font.hh"
|
||||
|
||||
static void debugprint(wasm_exec_env_t exec_env, char *the_string, uint8_t len) {
|
||||
printf("%*s", len, the_string);
|
||||
}
|
||||
|
||||
|
||||
/* Define an array of NativeSymbol for the APIs to be exported.
|
||||
* Note: the array must be static defined since runtime will keep it after registration
|
||||
* For the function signature specifications, goto the link:
|
||||
* https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/export_native_api.md
|
||||
*/
|
||||
|
||||
#define NATIVE_SYMBOL(signature, name) {#name, (void *) hb::wasm::name, signature, NULL}
|
||||
static NativeSymbol _hb_wasm_native_symbols[] =
|
||||
{
|
||||
NATIVE_SYMBOL ("(r)r", font_get_face),
|
||||
{
|
||||
"debugprint",
|
||||
(void *) debugprint,
|
||||
"($i)",
|
||||
NULL
|
||||
}
|
||||
};
|
||||
#undef NATIVE_SYMBOL
|
||||
|
||||
|
||||
#endif /* HB_WASM_API_HH */
|
||||
|
|
|
@ -32,7 +32,8 @@ namespace wasm {
|
|||
|
||||
|
||||
face_t
|
||||
font_get_face (font_t)
|
||||
font_get_face (HB_WASM_EXEC_ENV
|
||||
font_t)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
|
||||
#include "hb-wasm-api.hh"
|
||||
|
||||
#include <wasm_export.h>
|
||||
|
||||
|
||||
/*
|
||||
* shaper face data
|
||||
|
@ -46,10 +44,6 @@ struct hb_wasm_face_data_t {
|
|||
wasm_module_t wasm_module;
|
||||
};
|
||||
|
||||
static void debugprint(wasm_exec_env_t exec_env, char *the_string, uint8_t len) {
|
||||
printf("%*s", len, the_string);
|
||||
}
|
||||
|
||||
static bool
|
||||
init_wasm ()
|
||||
{
|
||||
|
@ -60,21 +54,6 @@ init_wasm ()
|
|||
RuntimeInitArgs init_args;
|
||||
memset (&init_args, 0, sizeof (RuntimeInitArgs));
|
||||
|
||||
// Define an array of NativeSymbol for the APIs to be exported.
|
||||
// Note: the array must be static defined since runtime
|
||||
// will keep it after registration
|
||||
// For the function signature specifications, goto the link:
|
||||
// https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/export_native_api.md
|
||||
|
||||
static NativeSymbol native_symbols[] = {
|
||||
{
|
||||
"debugprint",
|
||||
(void *)debugprint,
|
||||
"($i)",
|
||||
NULL
|
||||
}
|
||||
};
|
||||
|
||||
init_args.mem_alloc_type = Alloc_With_Allocator;
|
||||
init_args.mem_alloc_option.allocator.malloc_func = (void *) hb_malloc;
|
||||
init_args.mem_alloc_option.allocator.realloc_func = (void *) hb_realloc;
|
||||
|
@ -83,9 +62,9 @@ init_wasm ()
|
|||
init_args.mem_alloc_type = Alloc_With_System_Allocator;
|
||||
|
||||
// Native symbols need below registration phase
|
||||
init_args.n_native_symbols = sizeof(native_symbols) / sizeof(NativeSymbol);
|
||||
init_args.n_native_symbols = ARRAY_LENGTH (_hb_wasm_native_symbols);
|
||||
init_args.native_module_name = "env";
|
||||
init_args.native_symbols = native_symbols;
|
||||
init_args.native_symbols = _hb_wasm_native_symbols;
|
||||
|
||||
if (!wasm_runtime_full_init (&init_args))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue