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

Function Library

lib/library.js:34–74  ·  view source on GitHub ↗

* Provides a friendly abstraction/API on-top of DynamicLibrary and * ForeignFunction.

(libfile, funcs, lib)

Source from the content-addressed store, hash-verified

32 */
33
34function Library (libfile, funcs, lib) {
35 debug('creating Library object for', libfile)
36
37 if (libfile && libfile.indexOf(EXT) === -1) {
38 debug('appending library extension to library name', EXT)
39 libfile += EXT
40 }
41
42 if (!lib) {
43 lib = {}
44 }
45 var dl = new DynamicLibrary(libfile || null, RTLD_NOW)
46
47 Object.keys(funcs || {}).forEach(function (func) {
48 debug('defining function', func)
49
50 var fptr = dl.get(func)
51 , info = funcs[func]
52
53 if (fptr.isNull()) {
54 throw new Error('Library: "' + libfile
55 + '" returned NULL function pointer for "' + func + '"')
56 }
57
58 var resultType = info[0]
59 , paramTypes = info[1]
60 , fopts = info[2]
61 , abi = fopts && fopts.abi
62 , async = fopts && fopts.async
63 , varargs = fopts && fopts.varargs
64
65 if (varargs) {
66 lib[func] = VariadicForeignFunction(fptr, resultType, paramTypes, abi)
67 } else {
68 var ff = ForeignFunction(fptr, resultType, paramTypes, abi)
69 lib[func] = async ? ff.async : ff
70 }
71 })
72
73 return lib
74}
75module.exports = Library

Callers

nothing calls this directly

Calls 2

VariadicForeignFunctionFunction · 0.85
ForeignFunctionFunction · 0.70

Tested by

no test coverage detected