28
28
29
29
` genepi ` is ** MIT licensed** and based on templates and macros inspired by [ nbind] ( https://github.com/charto/nbind ) but using N-API.
30
30
31
- ## Quick start
32
-
33
- ## Requirements
34
- You need [ Node.js] ( https://nodejs.org/ ) (at least v10.x) and one of the following C++ compilers:
35
-
36
- - GCC 4.8 or above,
37
- - Clang 3.6 or above,
38
- - Visual Studio 2015 ([ the Community version] ( https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx ) is fine).
39
-
40
31
## Features
41
32
` genepi ` allows you to:
42
33
@@ -56,6 +47,78 @@ In more detail:
56
47
- Call C++ methods from JavaScript with type checking.
57
48
- Pass instances of compatible classes by value between languages (through the C++ stack).
58
49
50
+ ## Requirements
51
+ You need [ Node.js] ( https://nodejs.org/ ) (at least v10.x) and one of the following C++ compilers:
52
+
53
+ - GCC 4.8 or above,
54
+ - Clang 3.6 or above,
55
+ - Visual Studio 2015 ([ the Community version] ( https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx ) is fine).
56
+
57
+ ## Quick start
58
+ 1 . Use your already existing C++ code in JavaScript
59
+
60
+ ``` C++
61
+ // My C++ code in hello.cpp
62
+ #include < iostream>
63
+ #include < string>
64
+
65
+ struct Greeter {
66
+ static void sayHello( const std::string& name )
67
+ {
68
+ std::cout << "Hello, " << name << std::endl;
69
+ }
70
+ };
71
+ ```
72
+
73
+ 2. Install genepi and add some scripts to the `package.json`
74
+ ```Shell
75
+ npm install @geode/genepi
76
+ ```
77
+
78
+ ``` JSON
79
+ {
80
+ "scripts" : {
81
+ "build" : " cmake-js compile" ,
82
+ "build:debug" : " cmake-js compile -D"
83
+ }
84
+ }
85
+ ```
86
+
87
+ 3 . Add JavaScript binding
88
+
89
+ ``` C++
90
+ // Add this to the file (or in another file)
91
+ #include < genepi/genepi.h>
92
+
93
+ GENEPI_CLASS ( Greeter )
94
+ {
95
+ GENEPI_METHOD( sayHello );
96
+ }
97
+ GENEPI_MODULE( hello )
98
+ ```
99
+
100
+ 4. Configure your project by creating a `CMakeLists.txt`
101
+ ```CMake
102
+ cmake_minimum_required(VERSION 3.5)
103
+
104
+ project(my_project)
105
+
106
+ find_package(genepi REQUIRED PATHS ${PROJECT_SOURCE_DIR}/node_modules/@geode/genepi/build)
107
+
108
+ add_genepi_library(my_project "hello.cpp")
109
+ ```
110
+
111
+ 5 . Compile your addon
112
+ ``` Shell
113
+ npm run build
114
+ ```
115
+
116
+ 6 . Use it!
117
+ ``` JavaScript
118
+ var myProject = require (' my_project.node' );
119
+ myProject .Greeter .sayHello (' you' );
120
+ ```
121
+
59
122
## User guide
60
123
- [ Creating your project] ( #creating-your-project )
61
124
- [ Calling from Node.js] ( #calling-from-nodejs )
@@ -71,18 +134,20 @@ In more detail:
71
134
72
135
### Creating your project
73
136
Create your repository using the provided Github template: [ genepi-template] ( https://github.com/Geode-solutions/genepi-template ) .
74
-
75
- ================================TODO============================
137
+ Here is how to use a Github template: [ link] ( https://help.github.com/en/articles/creating-a-repository-from-a-template ) .
76
138
77
139
### Calling from Node.js
78
140
Each ` genepi ` module (i.e. each Node.js addon generated) needs to be registered using the ` GENEPI_MODULE ` macro:
79
141
80
142
``` C++
81
143
// My C++ library
82
144
83
- GENEPI_MODULE ( my-genepi-addon );
145
+ GENEPI_MODULE ( my_addon );
84
146
```
85
147
148
+ This name `my_addon` is only used by [N-API](https://nodejs.org/api/n-api.html#n_api_module_registration).
149
+ The name of the addon is set in the `CMakeLists.txt` using the `add_genepi_library` macro. See [Quick start](#quick-start).
150
+
86
151
```JavaScript
87
152
// My JavaScript file
88
153
var example = require('my-genepi-addon.node');
0 commit comments