From 7702fb17290e76606bdd7010a0c3cbb32e85db76 Mon Sep 17 00:00:00 2001 From: pravic Date: Wed, 22 Jul 2020 22:04:07 +0300 Subject: [PATCH] tweak: Small changes. Remove `todo!` as it wants Rust 1.40. --- examples/extension/src/extension.rs | 15 ++++++--------- src/capi/scdef.rs | 4 +++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/examples/extension/src/extension.rs b/examples/extension/src/extension.rs index 5e3ffba..6791034 100644 --- a/examples/extension/src/extension.rs +++ b/examples/extension/src/extension.rs @@ -10,14 +10,9 @@ use sciter::Value; /// Extension entry point. #[no_mangle] -pub extern "system" -fn SciterLibraryInit(api: &'static sciter::ISciterAPI, exported: &mut VALUE) -> BOOL -{ +pub extern "system" fn SciterLibraryInit(api: &'static sciter::ISciterAPI, exported: &mut VALUE) -> BOOL { sciter::set_host_api(api); - let _a = Value::from(add); - let _b = Value::from(sub); - let ext_api = vmap! { "add" => add, "sub" => sub, @@ -28,7 +23,6 @@ fn SciterLibraryInit(api: &'static sciter::ISciterAPI, exported: &mut VALUE) -> true as BOOL } - /// Calculate the sum of all the given arguments. pub fn add(args: &[Value]) -> Value { let sum: i32 = args @@ -38,7 +32,7 @@ pub fn add(args: &[Value]) -> Value { .map(|v| v.unwrap()) .sum(); - Value::from(sum) + sum.into() } /// `function sub(a, b) { return a - b; }` @@ -46,7 +40,10 @@ pub fn sub(args: &[Value]) -> std::result::Result { if let [a, b] = args { let a = a.to_int().ok_or("`a` is not an int")?; let b = b.to_int().ok_or("`b` is not an int")?; - Ok(Value::from(a - b)) + + let result = a - b; + + Ok(result.into()) } else { Err(format!("sub(a,b) expects 2 parameters, given {} instead.", args.len())) } diff --git a/src/capi/scdef.rs b/src/capi/scdef.rs index 48e0123..ae3488f 100644 --- a/src/capi/scdef.rs +++ b/src/capi/scdef.rs @@ -370,7 +370,9 @@ pub type KeyValueCallback = extern "system" fn (param: LPVOID, pkey: *const VALU /// fn SciterLibraryInit(api: &'static sciter::ISciterAPI, exported: &mut VALUE) -> BOOL /// { /// sciter::set_host_api(api); -/// todo!("export some extension functions"); +/// +/// unimplemented!("export some extension functions"); +/// /// true as BOOL /// } /// ```