docs: correct examples
This commit is contained in:
parent
90f615eee3
commit
08e5804c3b
1 changed files with 8 additions and 0 deletions
|
@ -65,24 +65,32 @@ fn fibonacci_native(n: i64) -> i64 {
|
|||
### Register module
|
||||
|
||||
```rust
|
||||
#[macro_use]
|
||||
extern crate napi_derive;
|
||||
|
||||
use napi::{JsObject, Result};
|
||||
|
||||
/// `exports` is `module.exports` object in NodeJS
|
||||
#[module_exports]
|
||||
fn init(mut exports: JsObject) -> Result<()> {
|
||||
exports.create_named_method("fibonacci", fibonacci)?;
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
And you can also create `JavaScript` value while registering module:
|
||||
|
||||
```rust
|
||||
#[macro_use]
|
||||
extern crate napi_derive;
|
||||
|
||||
use napi::{JsObject, Result, Env};
|
||||
|
||||
#[module_exports]
|
||||
fn init(mut exports: JsObject, env: Env) -> Result<()> {
|
||||
exports.create_named_method("fibonacci", fibonacci)?;
|
||||
exports.set_named_property("DEFAULT_VALUE", env.create_int64(100)?)?;
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in a new issue