2022-01-17 21:29:47 -08:00
|
|
|
use napi::{Env, JsObject};
|
|
|
|
|
2021-09-23 01:29:09 +08:00
|
|
|
#[napi]
|
2021-12-20 15:59:47 +08:00
|
|
|
pub fn get_words() -> Vec<&'static str> {
|
2021-09-23 01:29:09 +08:00
|
|
|
vec!["foo", "bar"]
|
|
|
|
}
|
|
|
|
|
|
|
|
#[napi]
|
2021-11-29 04:54:45 +00:00
|
|
|
/// Gets some numbers
|
2021-09-23 01:29:09 +08:00
|
|
|
fn get_nums() -> Vec<u32> {
|
|
|
|
vec![1, 1, 2, 3, 5, 8]
|
|
|
|
}
|
|
|
|
|
|
|
|
#[napi]
|
|
|
|
fn sum_nums(nums: Vec<u32>) -> u32 {
|
|
|
|
nums.iter().sum()
|
|
|
|
}
|
2022-01-17 21:29:47 -08:00
|
|
|
|
|
|
|
#[napi]
|
|
|
|
fn to_js_obj(env: Env) -> napi::Result<JsObject> {
|
|
|
|
let mut arr = env.create_array(0)?;
|
|
|
|
arr.insert("a string")?;
|
|
|
|
arr.insert(42)?;
|
|
|
|
arr.coerce_to_object()
|
|
|
|
}
|