ffi-libraries
Version:
A Node.js library for loading and calling functions from dynamic libraries
37 lines (36 loc) • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Library = void 0;
const ffiBindings = require('bindings')('ffi_libraries');
/**
* Creates a new library instance with function definitions
* @param {string} path Path to the dynamic library
* @param {Object} functions Object containing function definitions
* @returns {Object} Object containing the defined functions
* @example
* const lib = new Library('user32.dll', {
* 'MessageBoxA': ['int32', ['pointer', 'string', 'string', 'uint32']],
* 'GetLastError': ['uint32', []]
* });
*/
class LibraryImpl {
constructor(path, functions) {
if (typeof path !== 'string') {
throw new TypeError('Library path must be a string');
}
if (typeof functions !== 'object' || functions === null) {
throw new TypeError('Functions definition must be an object');
}
const library = new ffiBindings.Library(path, functions);
Object.assign(this, library);
}
/**
* Closes the library and frees resources
*/
close() {
if (typeof this.close === 'function') {
this.close();
}
}
}
exports.Library = LibraryImpl;