Crates.io | quickjs_runtime |
lib.rs | quickjs_runtime |
version | 0.14.4 |
source | src |
created_at | 2021-02-07 18:00:47.820814 |
updated_at | 2024-10-15 11:17:44.301409 |
description | Wrapper API and utils for the QuickJS JavaScript engine with support for Promise, Modules, Async/await |
homepage | https://github.com/HiRoFa/quickjs_es_runtime |
repository | https://github.com/HiRoFa/quickjs_es_runtime |
max_upload_size | |
id | 352021 |
size | 592,297 |
quickjs_runtime is a library for quickly getting started with embedding a javascript engine in your rust project.
as of 2024 this lib no longer relies on libquickjs-sys but on our own hirofa-quickjs-sys adding flexibility in used quickjs version
quickjs_runtime runs all javascript action in a single thread using an EventLoop. This means you can call javascript safely from several threads by adding tasks to the EventLoop.
quickjs_runtime supports both the original quickjs and the quickjs-ng project.
You can try out quickjs-ng by adding the dep to quickjs_runtime like this (use at your own risk as I have not extensively tested it yet):
quickjs_runtime = {git="https://github.com/HiRoFa/quickjs_es_runtime", features=["console", "setimmediate", "setinterval", "settimeout", "typescript", "quickjs-ng"], default-features=false}
An example on how to embed a script engine in rust using this lib can be found here: github.com/andrieshiemstra/ScriptExtensionLayerExample. It was published in TWIR as a walkthrough.
quickjs_runtime focuses on making quickjs easy to use and does not add any additional features, that's where these projects come in:
Please see the DOCS for all inner workings
Embedding a script engine in a rust project seems a very tedious job which involves learning a lot about the inner workings of that engine.
The main goal of this project is to make that job easy!
The manner in which this is achieved is primarily focused on abstracting the workings of the engine from the implementor, therefore some functionality may not be the fastest way of getting things done.
So a second goal is to make implementing a fast and efficient integration doable for the uninitiated, the most common tasks you do with the engine should be doable with the utils in this package and working examples should be provided in the test modules.
The reason I chose QuickJS as the engine is that I've been dealing with less modern engines in my java projects and not being able to use the latest and greatest ECMA-script features becomes quite disappointing at times.
The fun stuff about QuickJS:
Cargo.toml
[dependencies]
quickjs_runtime = "0.13.1"
Here are some quickstarts:
The quickjs Api utils: