Skip to content

Commit

Permalink
tweak: Small changes.
Browse files Browse the repository at this point in the history
Remove `todo!` as it wants Rust 1.40.
  • Loading branch information
pravic committed Jul 22, 2020
1 parent 688f46f commit 7702fb1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 6 additions & 9 deletions examples/extension/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -38,15 +32,18 @@ pub fn add(args: &[Value]) -> Value {
.map(|v| v.unwrap())
.sum();

Value::from(sum)
sum.into()
}

/// `function sub(a, b) { return a - b; }`
pub fn sub(args: &[Value]) -> std::result::Result<Value, String> {
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()))
}
Expand Down
4 changes: 3 additions & 1 deletion src/capi/scdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// }
/// ```
Expand Down

0 comments on commit 7702fb1

Please sign in to comment.