Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start documentation #192

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ values. Concepts and operations generally map to ideas specified in the
- **[Examples](#examples)**
- **[Tests](#tests)**
- **[More resource and info about native Addons](#resources)**
- **[Code of Conduct](CODE_OF_CONDUCT.md)**
- **[Contributors](#contributors)**
- **[License](#license)**

## **Current version: 1.0.0**
## **Current version: 1.1.0**

(See [CHANHELOG.md](CHANGELOG.md) for complete Changelog)

Expand Down Expand Up @@ -84,13 +85,29 @@ values. Concepts and operations generally map to ideas specified in the

### **Examples**

//TODO References to examples
Are you new to **N-API**? Take a look at our **[examples](https://github.com/nodejs/abi-stable-node-addon-examples)**

- **[Hello World](https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/1_hello_world/node-addon-api)**
- **[Pass arguments to a function](https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/2_function_arguments/node-addon-api)**
- **[Callbacks](https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/3_callbacks/node-addon-api)**
- **[Object factory](https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/4_object_factory/node-addon-api)**
- **[Function factory](https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/4_object_factory/node-addon-api)**
- **[Wrapping C++ Object](https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/6_object_wrap/node-addon-api)**
- **[Factory of wrapped object](https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/7_factory_wrap/node-addon-api)**
- **[Passing wrapped object around](https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/8_passing_wrapped/node-addon-api)**

<a name="tests"></a>

### **Tests**

//TODO References to tests
To run the **N-API** tests do:

```
npm install
npm test
```

Take a look and get inspired by our **[test suite](https://github.com/nodejs/node-addon-api/tree/master/test)**

<a name="resources"></a>

Expand Down
5 changes: 5 additions & 0 deletions doc/array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Array

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/array_buffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Array buffer

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/async_operations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Asynchronous operations

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/async_worker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Async worker

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/basic_types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Basic Types

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/boolean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Boolean

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/buffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Buffer

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/class_property_descriptor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Class propertry and descriptior

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
18 changes: 18 additions & 0 deletions doc/cmake-js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# CMake.js

**CMake.js** is a build tool that allow native addon developer to compile their
C++ code into executable form. It works like **[node-gyp](node-gyp.md)** but
instead of Google's **gyp** format it is base on **CMake** build system.

## **CMake** reference

- [Installation](https://www.npmjs.com/package/cmake-js#installation)
- [How to use](https://www.npmjs.com/package/cmake-js#usage)
- [Tutorials](https://www.npmjs.com/package/cmake-js#tutorials)
- [Use case in the works - ArrayFire.js](https://www.npmjs.com/package/cmake-js#use-case-in-the-works---arrayfirejs)

Sometimes finding the right settings is not easy so to accomplish at most
complicated task please refer to:

- [CMake documentation](https://cmake.org/)
- [CMake.js wiki](https://github.com/cmake-js/cmake-js/wiki)
10 changes: 5 additions & 5 deletions doc/conversion-tool.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## Conversion Tool
# Conversion Tool

To make the migration to node-addon-api easier, we have provided a script to help
complete the steps listed above. To use the conversion script:
To make the migration to **node-addon-api** easier, we have provided a script to
help complete some tasks.

## To use the conversion script:

1. Go to your module directory

Expand All @@ -14,15 +16,13 @@ cd [module_path]
```
npm install node-addon-api
```

3. Run node-addon-api conversion script

```
node ./node_modules/node-addon-api/tools/conversion.js ./
```

4. While this script makes conversion easier, it still cannot fully convert

the module. The next step is to try to build the module and complete the
remaining conversions necessary to allow it to compile and pass all of the
module's tests.
5 changes: 5 additions & 0 deletions doc/error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Error

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/error_handling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Error handling

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/escapable_handle_sope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Escapable handle scope

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/function.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Function

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/function_reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Function reference

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
15 changes: 15 additions & 0 deletions doc/generator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generator

## What is generator

**[generator-napi-module](https://www.npmjs.com/package/generator-napi-module)** is a module to quickly generate a skeleton module using
**N-API**, the new API for Native addons. This module automatically sets up your
**gyp file** to use **node-addon-api**, the C++ wrappers for N-API and generates
a wrapper JS module. Optionally, it can even configure the generated project to
use **TypeScript** instead.

## **generator-napi-module** reference

- [Installation and usage](https://www.npmjs.com/package/generator-napi-module#installation)


5 changes: 5 additions & 0 deletions doc/handle_scope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Handle scope

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Name

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
81 changes: 81 additions & 0 deletions doc/node-gyp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# node-gyp

C++ code needs to be compiled into executable form whether it be as an object
file to linked with others, a shared library, or a standalone executable.

The main reason for this is that we need to link to the Node.js dependencies and
headers correcrtly, another reason is that we need a cross platform way to build
C++ soucre into binary for the target platform,

Until now **node-gyp** is the **de-fafto** standard build tool for writing
Node.js addons. It's based on Google's **gyp** build tool, which abstract away
many of the tedious issues related to cross platform building.

**node-gyp** uses a file called ```binding.gyp``` that is located on the root of
your addon project.

```binding.gyp``` file, contains all building configurations organized with a
JSON like syntax. The most important parameter is the **target** that must be
set to the same value used on the initialization code of the addon as in the
examples reported below:

### **binding.gyp**

```gyp
{
"targets": [
{
# myModule is the name of your native addon
"target_name": "myModule",
"sources": ["src/my_module.cc", ...],
...
]
}
```

### **my_module.cc**

```cpp
#include <napi.h>

// ...

/**
* This code is our entry-point. We receive two arguments here, the first is the
* environment that represent an independent instance of the JavaScript runtime,
* the second is exports, the same as module.exports in a .js file.
* You can either add properties to the exports object passed in or create your
* own exports object. In either case you must return the object to be used as
* the exports for the module when you return from the Init function.
*/
Napi::Object Init(Napi::Env env, Napi::Object exports) {

// ...

return exports;
}

/**
* This code defines the entry-point for the Node addon, it tells Node where to go
* once the library has been loaded into active memory. The first argument must
* match the "target" in our *binding.gyp*. The second argument points to the
* function to invoke.
*/
NODE_API_MODULE(myModule, Init)
```

## **node-gyp** reference

- [Installation](https://www.npmjs.com/package/node-gyp#installation)
- [How to use](https://www.npmjs.com/package/node-gyp#how-to-use)
- [The binding.gyp file](https://www.npmjs.com/package/node-gyp#the-bindinggyp-file)
- [Commands](https://www.npmjs.com/package/node-gyp#commands)
- [Command options](https://www.npmjs.com/package/node-gyp#command-options)
- [Configuration](https://www.npmjs.com/package/node-gyp#configuration)

Sometimes finding the right settings for ```binding.gyp``` is not easy so to
accomplish at most complicated task please refer to:

- [GYP documentation](https://gyp.gsrc.io/index.md)
- [node-gyp wiki](https://github.com/nodejs/node-gyp/wiki)

5 changes: 5 additions & 0 deletions doc/object.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Object

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/object_reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Object reference

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
12 changes: 8 additions & 4 deletions doc/object_wrap.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
## Object Wrap

The ```ObjectWrap``` class can be used to expose C++ code to JavaScript. To do
The ```ObjectWrap``` class can be used to expose C++ code to JavaScript. To do
this you need to extend the ObjectWrap class that contain all the plumbing to connect
JavaScript code to a C++ object.
Classes extending ```ObjectWrap``` can be instantiated from JavaScript using the
JavaScript code to a C++ object.
Classes extending ```ObjectWrap``` can be instantiated from JavaScript using the
**new** operator, and their methods can be directly invoked from JavaScript.
The **wrap** word refers to a way to group methods and state of your class because it
will be your responsibility write custom code to bridge each of your C++ class methods.
will be your responsibility write custom code to bridge each of your C++ class methods.

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/onject_lifetime_management.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Object lifetime management

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/promises.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Promise

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/property_descriptor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# property descriptor

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Reference

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
17 changes: 15 additions & 2 deletions doc/setup.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
## Setup
# Setup

To use N-API in a native module:
## Prerequisites

Before starting to use **N-API** you need to assure you have the following
prerequisites:

* **Node.JS** see: [Installing Node.js](https://nodejs.org/)

* **Node.js native addon build tool**

- **[node-gyp](node-gyp.md)**

## Installation and usage

To use **N-API** in a native module:

1. Add a dependency on this package to `package.json`:

Expand Down
5 changes: 5 additions & 0 deletions doc/string.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# String

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
5 changes: 5 additions & 0 deletions doc/symbol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Symbol

You are reading a draft of the next documentation and it's in continuos update so
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/)
Loading