How to use the ffi.Library function in ffi

To help you get started, we’ve selected a few ffi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vgxbj / node-ngspice / node-ngspice / wrapper / wrapper.js View on Github external
_load_ngshared_lib(path) {

    // judge platform and search for lib
    try {
      return ffi.Library(path, struct.methods_structure);
    } catch (e) {
      throw Error(`cannot open ${path} for ngspice shared library, due to error: ${e}`);
    }
  }
  // _load_ngshared_lib() ends
github nebrius / raspi-llio / lib / i2c.js View on Github external
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

var ffi = require('ffi');

// Create the interface to the wiringPi interface
var pi = ffi.Library('libwiringPi', {
  wiringPiI2CSetup: [ 'int', [ 'int' ] ],
  wiringPiI2CRead: [ 'int', [ 'int' ] ],
  wiringPiI2CWrite: [ 'int', [ 'int', 'int' ] ],
  wiringPiI2CWriteReg8: [ 'int', [ 'int', 'int', 'int' ] ],
  wiringPiI2CWriteReg16: [ 'int', [ 'int', 'int', 'int' ] ],
  wiringPiI2CReadReg8: [ 'int', [ 'int', 'int' ] ],
  wiringPiI2CReadReg16: [ 'int', [ 'int', 'int' ] ]
});

module.exports = I2C;

function I2C(address) {
  if (typeof address != 'number') {
    throw new Error('Invalid I2C address "' + address + '". Addresses must be a number');
  }
  var fd = pi.wiringPiI2CSetup(address);
github zetsin / node-sdl2 / dep / SDL_test_assert.js View on Github external
var FFI = require('ffi')
var ArrayType = require('ref-array')
var Struct = require('ref-struct')
var Union = require('ref-union');
var ref = require('ref')



var voit = exports.voit = ref.types.void
var int32 = exports.int32 = ref.types.int32

FFI.Library(process.platform == 'win32' ? 'SDL2' : 'libSDL2', {
	SDLTest_ResetAssertSummary: [ voit, [ ] ],
	SDLTest_LogAssertSummary: [ voit, [ ] ],
	SDLTest_AssertSummaryToTestResult: [ int32, [ ] ],
}, exports)
github nebrius / raspi-llio / lib / raspi.js View on Github external
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

var ffi = require('ffi');

var pi;
try {
  pi = ffi.Library('libwiringPi', {
    wiringPiSetup: [ 'int', [] ],
    piBoardRev: [ 'int', [] ]
  });
  pi.wiringPiSetup();
} catch(e) {
  console.error('Wiring PI is not installed. Please install it from http://wiringpi.com/');
  process.exit(1);
}

module.exports = {
  GPIO: require('./gpio'),
  I2C: require('./i2c'),
  PWM: require('./pwm'),
  SPI: require('./spi'),
  UART: require('./uart'),
  getBoardRev: function getBoardRev() {
github wtfil / rust-in-node / src / native-rust-ffi.js View on Github external
var ffi = require('ffi');
var process = require('process')

var isWin = /^win/.test(process.platform);

module.exports = ffi.Library('rust/target/release/'+(!isWin?'lib':'')+'embed', {
	fibonacci: ['int', ['int']]
});
github zetsin / node-sdl2 / dep / begin_code.js View on Github external
var FFI = require('ffi')
var ArrayType = require('ref-array')
var Struct = require('ref-struct')
var Union = require('ref-union');
var ref = require('ref')



var voit = exports.voit = ref.types.void

FFI.Library(process.platform == 'win32' ? 'SDL2' : 'libSDL2', {
}, exports)
github zetsin / node-sdl2 / dep / SDL_opengles2.js View on Github external
var FFI = require('ffi')
var ArrayType = require('ref-array')
var Struct = require('ref-struct')
var Union = require('ref-union');
var ref = require('ref')



var voit = exports.voit = ref.types.void

FFI.Library(process.platform == 'win32' ? 'SDL2' : 'libSDL2', {
}, exports)
github zetsin / node-sdl2 / dep / SDL_opengles2_gl2platform.js View on Github external
var FFI = require('ffi')
var ArrayType = require('ref-array')
var Struct = require('ref-struct')
var Union = require('ref-union');
var ref = require('ref')



var voit = exports.voit = ref.types.void

FFI.Library(process.platform == 'win32' ? 'SDL2' : 'libSDL2', {
}, exports)
github zetsin / node-sdl2 / dep / SDL_name.js View on Github external
var FFI = require('ffi')
var ArrayType = require('ref-array')
var Struct = require('ref-struct')
var Union = require('ref-union');
var ref = require('ref')



var voit = exports.voit = ref.types.void

FFI.Library(process.platform == 'win32' ? 'SDL2' : 'libSDL2', {
}, exports)
github maidsafe / safe_examples / dns_example / src / scripts / safe_api / safe_io.js View on Github external
this.load = function(libPath) {
    api = ffi.Library(path.resolve(libPath, process.platform === 'win32' ? 'safe_ffi' : 'libsafe_ffi'), {
      'create_sub_directory': ['int', ['string', 'bool']],
      'create_file': ['int', ['string', IntArray, 'int']],
      'register_dns': ['int', ['string', 'string', 'string']]
    });
  };

ffi

A foreign function interface (FFI) for Node.js

MIT
Latest version published 6 years ago

Package Health Score

53 / 100
Full package analysis

Popular ffi functions