JSCallback wraps a TypeScript function so it can be passed to C code that expects a function pointer.
Example
Constructor
| Parameter | Type | Default | Description |
|---|---|---|---|
callback | Function | — | TypeScript function to wrap |
def.args | string[] | — | C function argument type codes |
def.returns | string | — | C function return type code |
def.threadsafe | boolean | false | Safe to call from any thread |
Properties
ptr
- Non-threadsafe: returns a slot handle (small integer).
- Threadsafe: returns a real executable trampoline address.
getHandle()
ffi.invokeCallback() and ffi.callCallbackThreadSafe().
threadsafe
Methods
call()
close()
Thread-Safe Callbacks
threadsafe: true, cb.ptr returns a real C function pointer (trampoline) that can be passed directly to native C functions: