Create a callback that can be passed to native functions.
The callback runs on the main thread. For thread-safe callbacks, use threadSafeCallback.
Important: Call .release() when the callback is no longer needed.
.release()
Python equivalent: ctypes.CFUNCTYPE(...)(func)
ctypes.CFUNCTYPE(...)(func)
JavaScript function to wrap
Return type of the callback
Argument types
A wrapper with a .pointer property and .release() method
.pointer
import { callback, c_int32, c_void_p, readValue } from 'node-ctypes';const compare = callback( (a, b) => readValue(a, c_int32) - readValue(b, c_int32), c_int32, [c_void_p, c_void_p]);// Pass compare.pointer to qsort, etc.compare.release(); Copy
import { callback, c_int32, c_void_p, readValue } from 'node-ctypes';const compare = callback( (a, b) => readValue(a, c_int32) - readValue(b, c_int32), c_int32, [c_void_p, c_void_p]);// Pass compare.pointer to qsort, etc.compare.release();
Create a callback that can be passed to native functions.
The callback runs on the main thread. For thread-safe callbacks, use threadSafeCallback.
Important: Call
.release()when the callback is no longer needed.Python equivalent:
ctypes.CFUNCTYPE(...)(func)