#quickjs #api-bindings #json

quickjs-wasm-rs

High-level bindings and serializers for a Wasm build of QuickJS

5 releases

0.1.4 Jan 24, 2023
0.1.3 Jan 5, 2023
0.1.2 Aug 9, 2022
0.1.1 Jul 29, 2022
0.1.0 Mar 14, 2022

#209 in WebAssembly

Download history 4/week @ 2022-12-08 5/week @ 2022-12-15 3/week @ 2022-12-22 5/week @ 2022-12-29 32/week @ 2023-01-05 4/week @ 2023-01-12 30/week @ 2023-01-19 72/week @ 2023-01-26 13/week @ 2023-02-02 35/week @ 2023-02-09 33/week @ 2023-02-16 12/week @ 2023-02-23 15/week @ 2023-03-02 22/week @ 2023-03-09 27/week @ 2023-03-16 10/week @ 2023-03-23

74 downloads per month

MIT license

3MB
89K SLoC

C 79K SLoC // 0.0% comments JavaScript 7.5K SLoC // 0.0% comments Rust 2.5K SLoC // 0.0% comments Shell 115 SLoC // 0.1% comments

quickjs-wasm-rs

High-level bindings and serializers for a Wasm build of QuickJS.

Bindings

Context corresponds to a QuickJS JSContext and Value corresponds to a QuickJS JSValue.

use quickjs_wasm_rs::Context;

let mut context = Context::default();

will create a new context.

Serializers

This crate provides optional transcoding features for converting between serialization formats and Value:

  • messagepack provides quickjs_wasm_rs::messagepack for msgpack, using rmp_serde.
  • json provides quickjs_wasm_rs::json for JSON, using serde_json.

msgpack example:

use quickjs_wasm_rs::{messagepack, Context, Value};

let context = Context::default();
let input_bytes: &[u8] = ...;
let input_value = messagepack::transcode_input(&context, input_bytes).unwrap();
let output_value: Value = ...;
let output = messagepack::transcode_output(output_value).unwrap();

Building a project using this crate

  • Install the wasi-sdk for your platform
  • Set the QUICKJS_WASM_SYS_WASI_SDK_PATH environment variable to the absolute path where you installed the wasi-sdk

For example, if you install the wasi-sdk in /opt/wasi-sdk, you can run:

export QUICKJS_WASM_SYS_WASI_SDK_PATH=/opt/wasi-sdk

Publishing to crates.io

To publish this crate to crates.io, run ./publish.sh.

Dependencies