Skip to content

Commit b463042

Browse files
committed
fix(Readme): finish documentation
1 parent 9d7f21d commit b463042

File tree

1 file changed

+77
-12
lines changed

1 file changed

+77
-12
lines changed

README.md

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,6 @@
2828

2929
`genepi` is **MIT licensed** and based on templates and macros inspired by [nbind](https://github.com/charto/nbind) but using N-API.
3030

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-
4031
## Features
4132
`genepi` allows you to:
4233

@@ -56,6 +47,78 @@ In more detail:
5647
- Call C++ methods from JavaScript with type checking.
5748
- Pass instances of compatible classes by value between languages (through the C++ stack).
5849

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+
59122
## User guide
60123
- [Creating your project](#creating-your-project)
61124
- [Calling from Node.js](#calling-from-nodejs)
@@ -71,18 +134,20 @@ In more detail:
71134

72135
### Creating your project
73136
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).
76138

77139
### Calling from Node.js
78140
Each `genepi` module (i.e. each Node.js addon generated) needs to be registered using the `GENEPI_MODULE` macro:
79141

80142
```C++
81143
// My C++ library
82144

83-
GENEPI_MODULE( my-genepi-addon );
145+
GENEPI_MODULE( my_addon );
84146
```
85147
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+
86151
```JavaScript
87152
// My JavaScript file
88153
var example = require('my-genepi-addon.node');

0 commit comments

Comments
 (0)