MCPcopy Index your code
hub / github.com/node-ffi/node-ffi / ForeignFunction

Function ForeignFunction

lib/foreign_function.js:19–37  ·  view source on GitHub ↗

* Represents a foreign function in another library. Manages all of the aspects * of function execution, including marshalling the data parameters for the * function into native types and also unmarshalling the return from function * execution.

(funcPtr, returnType, argTypes, abi)

Source from the content-addressed store, hash-verified

17 */
18
19function ForeignFunction (funcPtr, returnType, argTypes, abi) {
20 debug('creating new ForeignFunction', funcPtr)
21
22 // check args
23 assert(Buffer.isBuffer(funcPtr), 'expected Buffer as first argument')
24 assert(!!returnType, 'expected a return "type" object as the second argument')
25 assert(Array.isArray(argTypes), 'expected Array of arg "type" objects as the third argument')
26
27 // normalize the "types" (they could be strings,
28 // so turn into real type instances)
29 returnType = ref.coerceType(returnType)
30 argTypes = argTypes.map(ref.coerceType)
31
32 // create the `ffi_cif *` instance
33 var cif = CIF(returnType, argTypes, abi)
34
35 // create and return the JS proxy function
36 return _ForeignFunction(cif, funcPtr, returnType, argTypes)
37}
38module.exports = ForeignFunction

Callers 4

dynamic_library.jsFile · 0.70
errno.jsFile · 0.70
LibraryFunction · 0.70
function.jsFile · 0.70

Calls 1

CIFFunction · 0.85

Tested by

no test coverage detected