Commit 6503d2fe authored by nanocryk's avatar nanocryk
Browse files

feature : class export with method

parent fed24c36
//! `duniter-rs-wotb-js` is a crate providing Javascript bindings of `duniter-rs-wotb`.
#![deny(missing_docs,
/*missing_debug_implementations, */
missing_copy_implementations,
trivial_casts, trivial_numeric_casts,
unsafe_code,
unstable_features,
unused_import_braces, unused_qualifications)]
#[macro_use]
extern crate neon;
extern crate duniter_rs_wotb;
use neon::vm::Throw;
use neon::js::{JsInteger, JsString};
use neon::js::{Value, JsInteger, JsString, JsBoolean, JsFunction, Object};
use neon::js::class::{Class, JsClass};
use neon::mem::Handle;
use neon::vm::{Throw, Lock};
use duniter_rs_wotb::WebOfTrust;
......@@ -44,5 +39,23 @@ declare_types! {
Err(Throw)
}
}
method to_file(call) {
let scope = call.scope;
let path = try!(try!(call.arguments.require(scope, 0)).to_string(scope)).value();
let result = call.arguments.this(scope).grab(|wot| {
wot.to_file(path.as_str())
});
Ok(JsBoolean::new(scope, result).upcast())
}
}
}
\ No newline at end of file
}
register_module!(m, {
let class: Handle<JsClass<JsWebOfTrust>> = try!(JsWebOfTrust::class(m.scope));
let constructor: Handle<JsFunction<JsWebOfTrust>> = try!(class.constructor(m.scope));
try!(m.exports.set("WebOfTrust", constructor));
Ok(())
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment