nodex-plugin-helloworld

Crates.ionodex-plugin-helloworld
lib.rsnodex-plugin-helloworld
version0.2.0
created_at2022-01-26 18:15:30.328326+00
updated_at2022-03-06 13:18:58.145709+00
descriptionA small crate to show how to write a nodex plugin.
homepagehttps://github.com/uuhan/nodex
repositoryhttps://github.com/uuhan/nodex
max_upload_size
id521765
size3,044
uuhan (uuhan)

documentation

README

It is an example to show how to write a nodex-plugin

Just add nodex as the dependency:

[package]
name = "nodex-plugin-helloworld"
version = "0.1.1"
edition = "2021"

[dependencies]
nodex = "^0.2"

Then export your own function with the signature:

lib.rs

use nodex::prelude::*;

pub fn init(env: NapiEnv, mut object: JsObject) -> NapiResult<()> {
    object.set_named_property(
        "hello_world",
        env.func(|this, ()| {
            let env = this.env();
            let res: JsValue = env.run_script(
                r#"
                    console.log("hello, nodex!");
                "#
            )?;
            Ok(res)
        })?,
    )?;

    Ok(())
}

So you can use this crate as the dependency of your nodex project:

plugin example

[package]
name = "plugin"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies.nodex]
features = ["v8"]
version = "^0.1"

[dependencies.nodex-plugin-helloworld]
version = "0.1"

lib.rs

use nodex::prelude::*;
nodex::napi_module!(init);

fn init(env: NapiEnv, exports: JsObject) -> NapiResult<()> {
    nodex_plugin_helloworld::init(env, exports)?;

    Ok(())
}
Commit count: 357

cargo fmt