cbind
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "cbind", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Streamlined C/C++ v8 bindings generator for Node.JS inspired by tolua++ (requires C++11)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
113
README.md
@@ -1,4 +0,7 @@ | ||
node-tov8 | ||
========= | ||
[![Build Status](https://travis-ci.org/CodeCharmLtd/node-cbind.svg?branch=master)](https://travis-ci.org/CodeCharmLtd/node-tov8) | ||
node-![cbind](https://raw.githubusercontent.com/CodeCharmLtd/node-cbind/master/cbind.png) | ||
============== | ||
[![Build Status](https://travis-ci.org/CodeCharmLtd/node-cbind.svg?branch=master)](https://travis-ci.org/CodeCharmLtd/node-cbind) | ||
[![Package version](https://img.shields.io/npm/v/cbind.svg)](https://www.npmjs.org/package/cbind) | ||
[![Package version](https://img.shields.io/npm/dm/cbind.svg)](https://www.npmjs.org/package/cbind) | ||
[![Dependcies status](http://img.shields.io/gemnasium/CodeCharmLtd/node-cbind.svg)](https://gemnasium.com/CodeCharmLtd/node-cbind) | ||
@@ -9,2 +12,3 @@ Streamlined automatic C/C++ v8 bindings generator for Node.JS inspired by tolua++ (requires C++11) | ||
Simple things: | ||
```c++ | ||
@@ -26,2 +30,20 @@ | ||
More complex things: | ||
```c++ | ||
#include <stdio.h> | ||
int errno; // make errno available as getter and setter | ||
// make fopen available and mark FILE* pointers for automatic closing when gced | ||
FILE * [[free(fclose)]] fopen(const char* filename, const char* mode); | ||
// make fread available and automatically set one of its arguments | ||
size_t fread(void* ptr [[buffer]], size_t size, size_t nmemb [[set(ptr.length / size)]], FILE* stream [[handle]]); | ||
// tell cbind to mark the object containing pointer as invalid | ||
int fclose(FILE* f [[clear_free,unref]]); | ||
``` | ||
## Supported and tested features | ||
@@ -39,2 +61,3 @@ | ||
* Handle binary buffers as Buffer. | ||
* Handling function pointer types. Function pointers are automatically converted to javascript functions and vice-versa. Function pointer variables as getter/setters and function pointers as arguments are equally handled. | ||
@@ -55,4 +78,86 @@ * Handling constructors of structs/classes and binding them to javascript new. | ||
## How-to | ||
## How-to use | ||
* `npm install --save cbind` | ||
* Create `example.nid` file | ||
Put your native interface definition there, for example: | ||
``` | ||
void hello(int b); | ||
``` | ||
* Have your `binding.gyp` follow this example: | ||
``` | ||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "cbind_example", | ||
"sources": [ | ||
"src/addon.cc" | ||
], | ||
"include_dirs" : [ | ||
"<!(node -e \"require('nan')\" 2> /dev/null)", | ||
"<!(node -e \"require('cbind')('example.nid')\" 2> /dev/null)" | ||
], | ||
"cflags": ["-g", "-std=c++11"], | ||
"cflags_cc!": [ '-fno-exceptions' ] | ||
} | ||
] | ||
} | ||
``` | ||
* Have your `addon.cc` the following content | ||
```c++ | ||
#include <cstdio> | ||
void hello(int a) { | ||
printf("Hello world: %i\n", a); | ||
} | ||
#include <cbind_example.h> | ||
void init(v8::Handle<v8::Object> exports) { | ||
cbind::init_example(exports); | ||
} | ||
NODE_MODULE(tov8_example, init); | ||
``` | ||
* Run `node-gyp rebuild` | ||
* With hello.js having the following content: | ||
``` | ||
var bindings = require('./build/Release/cbind_example.node'); | ||
bindings = hello(42); | ||
``` | ||
* `node hello.js` should print "Hello world 42` | ||
The above is in the repository https://github.com/CodeCharmLtd/cbind-example | ||
Please open issues or follow example tests. README will be gradually expanded. | ||
## Special thanks | ||
https://github.com/celer/fire-ts - awesome templates for code generation | ||
<a name="authors"/> | ||
## Authors | ||
* Damian Kaczmarek <damian@codecharm.co.uk> <rush@rushbase.net> | ||
<a name="sponsors"/> | ||
## Sponsors | ||
Please open an issue if you would like a specific feature to be implemented and sponsored. | ||
<a name="license"/> | ||
## License | ||
Copyright (c) 2013-2014 [Code Charm Ltd](http://codecharm.co.uk) | ||
Licensed under the MIT license, see `LICENSE` for details. | ||
@@ -136,7 +136,12 @@ | ||
// not working yet | ||
// it('should call function char*(int, float, double, const char*, std::string) that automatically frees result after conversion to v8', function() { | ||
// var args = [9219, 35, 4444, 'eenie', 'meenie']; | ||
// functions.functionConcat4.apply(null, args).should.equal(args.join(',').length); | ||
// }); | ||
it('should call function char*(int, float, double, const char*, std::string) that automatically frees result after conversion to v8', function() { | ||
var args = [9219, 35, 4444, 'eenie', 'meenie']; | ||
var expected = args.join(','); | ||
assert.deepEqual(functions.functionConcat4.apply(null, args), | ||
{ | ||
out: expected, | ||
retValue: expected.length | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
66209
33
466
160