Skip to content
This repository
Browse code

README++

  • Loading branch information...
commit eaeba018d71cf05c43cc79a6a472d91f6f1f8255 1 parent 24ebf62
Nathan Rajlich authored May 26, 2012

Showing 1 changed file with 26 additions and 40 deletions. Show diff stats Hide diff stats

  1. 66  README.md
66  README.md
Source Rendered
@@ -8,7 +8,9 @@ It also simplifies the augmentation of node.js with C code as it takes care of h
8 8
 
9 9
 **WARNING**: node-ffi assumes you know what you're doing. You can pretty easily create situations where you will segfault the interpreter and unless you've got C debugger skills, you probably won't know what's going on.
10 10
 
11  
-# EXAMPLE
  11
+
  12
+Example
  13
+-------
12 14
 
13 15
 ``` js
14 16
 var ffi = require('ffi');
@@ -21,20 +23,24 @@ var current = ffi.Library(null, { 'atoi': [ 'int32', [ 'string' ] ] });
21 23
 current.atoi('1234'); // 1234
22 24
 ```
23 25
 
24  
-# REQUIREMENTS
  26
+
  27
+Requirements
  28
+------------
25 29
 
26 30
  * Linux, OS X, Windows, or Solaris.
27 31
  * `libffi` comes bundled with node-ffi, it does not need to be installed on your system.
28  
- * The current version is tested to run on node 0.6.x.
29  
- * If you need node 0.4.x support, use the `0.4` branch of node-ffi.
  32
+ * The current version is tested to run on node 0.6.x and 0.7.x.
30 33
 
31  
-# NPM INSTALL
  34
+
  35
+Installation
  36
+------------
32 37
 
33 38
 ``` bash
34 39
 $ npm install ffi
35 40
 ```
36 41
 
37  
-# SOURCE INSTALL / MANUAL COMPILATION
  42
+Source Install / Manual Compilation
  43
+-----------------------------------
38 44
 
39 45
 To compile from source it's easiest to use
40 46
 [`node-gyp`](https://github.com/TooTallNate/node-gyp):
@@ -51,45 +57,25 @@ $ cd node-ffi
51 57
 $ node-gyp configure build
52 58
 ```
53 59
 
54  
-# TYPES
55  
-
56  
-    int8        Signed 8-bit Integer
57  
-    uint8       Unsigned 8-bit Integer
58  
-    int16       Signed 16-bit Integer
59  
-    uint16      Unsigned 16-bit Integer
60  
-    int32       Signed 32-bit Integer
61  
-    uint32      Unsigned 32-bit Integer
62  
-    int64       Signed 64-bit Integer
63  
-    uint64      Unsigned 64-bit Integer
64  
-    float       Single Precision Floating Point Number (float)
65  
-    double      Double Precision Floating Point Number (double)
66  
-    pointer     Pointer Type
67  
-    string      Null-Terminated String (char *)
68  
-
69  
-In addition to the basic types, there are type aliases for common C types.
70  
-
71  
-    byte        unsigned char
72  
-    char        char
73  
-    uchar       unsigned char
74  
-    short       short
75  
-    ushort      unsigned short
76  
-    int         int
77  
-    uint        unsigned int
78  
-    long        long
79  
-    ulong       unsigned long
80  
-    longlong    long
81  
-    ulonglong   unsigned long long
82  
-    size_t      platform-dependent, usually pointer size
83  
-
84  
-# V8 and 64-bit Types
  60
+
  61
+Types
  62
+-----
  63
+
  64
+The types that you specify in function declarations correspond to ref's types
  65
+system. So see that for a reference if you are unfamiliar.
  66
+
  67
+
  68
+V8 and 64-bit Types
  69
+-------------------
85 70
 
86 71
 Internally, V8 stores integers that will fit into a 32-bit space in a 32-bit integer, and those that fall outside of this get put into double-precision floating point numbers. This is problematic because FP numbers are imprecise. To get around this, the methods in node-ffi that deal with 64-bit integers return strings and can accept strings as parameters.
87 72
 
88  
-# Call Overhead
  73
+Call Overhead
  74
+-------------
89 75
 
90 76
 There is non-trivial overhead associated with FFI calls. Comparing a hard-coded binding version of `strtoul()` to an FFI version of `strtoul()` shows that the native hard-coded binding is 5x faster. So don't just use the C version of a function just because it's faster. There's a significant cost in FFI calls, so make them worth it.
91 77
 
92  
-# LICENSE
  78
+License
  79
+-------
93 80
 
94 81
 MIT License. See the `LICENSE` file.
95  
-

0 notes on commit eaeba01

Please sign in to comment.
Something went wrong with that request. Please try again.