This library allows you to use native APIs.
Features:
You can declare native functions directly in the C syntax. Currently it supports typedefs, structs, common predefined types and functions. The token processor requires using of classes.
An example:
use "native/extern"; use "classes"; import "native/native"; extern "C" { typedef struct { int some; float value; } Test; bind("lib"); void some_func(Test *test); void other_func(); bind("c"); int printf(char *fmt, ...); } function test() { Library::bind("c"); Library::bind("lib", Library::open("./libcustom.so")); var test = Test::create(); test.set_some(5); test.set_value(123.0); some_func(test); printf("Hello, world! value=%f\n", 123.0); }
When using WebAssembly in the browser you can directly embed code of JavaScript functions. Here is an example:
use "native/extern"; use "classes"; import "native/native"; extern "JS" { function js_func(arg1: int, arg2: float, arg3: string): float { return 123.456; } }
The function declaration must include types for the parameters and the return value (unless there is none). The available types are:
boolean - booleanint - 32bit integerfloat - 32bit floatdouble - 64bit floatpointer - pointer (32bit integer)string - string (internally converted using UTF-8 encoding)The functions can use these variables:
global - global object for the WebAssembly modulememory - WebAssembly memorymem8 - memory view as Uint8Arraymem16 - memory view as Uint16Arraymem32 - memory view as Int32ArraymemF32 - memory view as Float32ArrayAnd these functions:
malloc(size) - allocate uninitialized memorycalloc(nmemb, size) - allocate zeroed memoryrealloc(ptr, size) - reallocates the memoryfree(ptr) - frees the memorysuspend() - suspends the execution and returns a continuation function that takes a return value