Browse files

publish bin, add prefix option previously missing, add script to readme

  • Loading branch information...
1 parent 28441df commit 3c020fce51c3ca7df233083540811c353c47ccd0 @tjfontaine committed Jan 2, 2012
@@ -27,12 +27,32 @@ tu.dispose();
Generate FFI Bindings
+`ffi-generate-node -f /path/to/myLibrary/header.h -l libmyLibrary`
+Will parse the given filename and print to standard out the resulting javascript
+suitable for use as a module.
+ * f -- required -- The header file you wish to parse
+ * l -- required -- The library FFI will use to dlopen
+ * m -- optional -- The module name underwhich functions will be stored (uses library name otherwise)
+ * p -- optional -- Only include functions whose name starts with the provided prefix
+ * x -- optional -- Restrict to only functions declared in the given header file
+It may be necessary to pass additional flags to libclang so it can better parse
+the header (i.e. include paths). To pass options directly to libclang use `--`
+so ffi-generate-node knows to stop parsing arguments, the rest will be passed
+to libclang without modification.
+`ffi-generate-node -f /usr/include/ImageMagick/wand/MagickWand.h -l libMagickWand -m wand -p Magick -- $(Magick-config --cflags)`
+Generate FFI Bindings Programatically
var exec = require('child_process').exec;
var path = require('path');
var fs = require('fs');
var jsb = require('beautifyjs');
-var generate = require('examples/generateffi').generate;
+var generate = require('lib/generateffi').generate;
exec('llvm-config --includedir', function (fail, out, err) {
var includedir = out.replace(/\s+$/, '');
@@ -63,6 +83,8 @@ Input to the generate method
* opts.prefix -- optional -- restrict imported functions to a given prefix
* opts.includes -- optional -- a set of directory paths to aid type expansion
* opts.compiler_args -- optional -- a set of clang command line options passed to the parser
+ * opts.single_file -- optional -- restricts functions to only those defined in the header file
+ - this does not restrict dependent types
The result from generate is an object that has two properties
@@ -78,4 +100,4 @@ map a type to ffi type.
The native wrapper isn't completely fleshed out or free of errors. Enough is
-wrapped to allow for C modules to be successfully generated by `examples/generateffi.js`.
+wrapped to allow for C modules to be successfully generated by `lib/generateffi.js`.
@@ -1,17 +1,21 @@
-var generate = require('../examples/generateffi').generate;
+#!/usr/bin/env node
+var generate = require('../lib/generateffi').generate;
var jsb = require('beautifyjs');
var argv = require('optimist')
.usage('Generate node-ffi bindings for a given header file\nUsage: $0')
.demand('f').alias('f', 'file').describe('f', 'The header file to parse')
.demand('l').alias('l', 'library').describe('l', 'The name of the library to dlopen')
.alias('m', 'module').describe('m', 'The name of module the bindings will be exported as')
.boolean('x').alias('x', 'file_only').describe('x', 'Only export functions found in this file')
+ .alias('p', 'prefix').describe('p', 'Only import functions whose name start with prefix')
filename: argv.f,
library: argv.l,
module: argv.m,
+ prefix: argv.p,
compiler_args: argv._,
single_file: argv.x,
File renamed without changes.
File renamed without changes.
@@ -4,8 +4,12 @@
"main": "libclang",
"description": "Native bindings to libclang -- Generate FFI Bindings from header file",
"keywords": ["libclang", "ffi", "bindings"],
- "author": "Timothy J Fontaine <>"
+ "author": "Timothy J Fontaine <>",
"bin": {
"ffi-generate-node": "bin/ffi-generate-node.js"
+ },
+ "dependencies": {
+ "optimist": "",
+ "beautifyjs": ""

0 comments on commit 3c020fc

Please sign in to comment.