#javascript #module #register #run-time #support #obj #wilton

wilton_rusty

Rust modules support for Wilton JavaScript runtime

2 releases

Uses old Rust 2015

0.3.1 Mar 11, 2021
0.3.0 Mar 11, 2021

#1932 in Development tools

Apache-2.0

15KB
178 lines

Rust modules support for Wilton JavaScript runtime

This library allows to write Wilton native modules in Rust.

License information

This project is released under the Apache License 2.0.

Changelog

2021-03-10

  • version 0.3.1
  • package rename to wilton_rusty
  • fix new compiler warnings
  • wilton URL changes in docs

2018-04-14

  • version 0.2.0
  • support backcalls to JS

2018-03-14

  • version 0.1.0
  • initial public version

lib.rs:

Rust modules support for Wilton JavaScript runtime

Usage example:

// configure Cargo to build a shared library
//[lib]
//crate-type = ["dylib"]

// in lib.rs, import serde and wilton_rusty
//#[macro_use]
//extern crate serde_derive;
//extern crate wilton_rusty;
// ...
// declare input/output structs
#[derive(Deserialize)]
struct MyIn { }
#[derive(Serialize)]
struct MyOut { }

// write a function that does some work
fn hello(obj: MyIn) -> MyOut { }

// register that function inside the `wilton_module_init` function,
// that will be called by Wilton during the Rust module load
#[no_mangle]
pub extern "C" fn wilton_module_init() -> *mut std::os::raw::c_char {
   // register a call, error checking omitted
   wilton_rusty::register_wiltocall("hello", |obj: MyIn| { hello(obj) });
   // return success status to Wilton
   wilton_rusty::create_wilton_error(None)
}

See an example how to load and use Rust library from JavaScript.

Dependencies

~360–770KB
~17K SLoC