Safe API to embed an ECMAScript engine.

Related tags

Miscellaneous kopi
Overview

Kopi

Kopi is a small abstraction to easily and safely embed an ECMAScript runtime inside a Rust based application. It uses the V8 execution engine to provide JITed ECMAScript execution and aims to use very few dependencies.

Status

This crate is still in the design phase and in large parts unfinished. Once it reaches a certain stage of maturity it will be published to cargo.io.

Features

  • getrandom - V8 expects the implementation to provide a good, strong entropy source, or else it might use a weak entropy sources. This features uses the getrandom crate to provide a strong entropy source provided by the operating system.
  • (1) serde - Adds support to serialize and deserialize any serde compatible type.

(1) Not implemented yet

Example

use kopi::*;

fastcall_function! {
    fn mul(x: f64, y: f64) -> f64 {
        x * y
    }
}

initialize_with_defaults();

let mut extension = Extension::new(None);
extension.add_function("madd", move |(a, b, c): (f32, f32, f32)| a + (b * c));
extension.add_fastcall_function("mul", mul);

let mut runtime = Runtime::new(
    RuntimeOptions {
        extensions: vec![extension],
        ..Default::default()
    },
    (),
)
.expect("Can't create runtime");

let val: i32 = runtime
    .execute("madd(10, 5, 6)")
    .expect("Can't execute code");

assert_eq!(val, 40);

let val: i32 = runtime.execute("mul(10, 20)").expect("Can't execute code");

assert_eq!(val, 200);

Testing

Some tests need a ICU data file placed inside the project root directory (icudt71l.dat for little endian or icudt71b.dat for big endian systems).

You need to download a ICU version 71 data file from the ICU project release page.

Roadmap

Sooner than later following functionality will be added:

  • Module loading
  • Embedded types
  • Fallible fastcall functions
  • Optional serde support

We're not yet totally sure how the API for async should look.

Documentation

The local documentation can be generated with:

RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

You might also like...
Amethyst is a systems language aimed at being simple, small, portable, and safe.

amethyst Amethyst is a systems language aimed at being simple, small, portable, and safe. What is this language? From the r/ProgLangs discord server:

MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine
MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine

MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine. Both searching and indexing are highly customizable. Features such as typo-tolerance, filters, and synonyms are provided out-of-the-box. For more information about features go to our documentation.

A collection of exponentially-smoothed camera controllers for the Bevy Engine.

smooth-bevy-cameras A collection of exponentially-smoothed camera controllers for the Bevy Engine. Look Transform All controllers are based on a LookT

A simple induction and BMC engine.

Mikino is a (relatively) simple induction and BMC engine. Its goal is to serve as a simple yet interesting tool for those interested in formal verification, especially SMT-based induction.

A scalable differentiable probabilistic Datalog engine, with Rust

Scallop A scalable probabilistic datalog engine with Rust. Usage The Scallop system is best integrated inside of the Rust context. With scallop! { ...

Blueboat is an open-source alternative to Cloudflare Workers. The monolithic engine for serverless web apps.

Blueboat Blueboat is an open-source alternative to Cloudflare Workers. Blueboat aims to be a developer-friendly, multi-tenant platform for serverless

A prisma query-engine concurrency runner

Smash A prisma query-engine concurrency runner. Smash can be used to run concurrent requests against the prisma query engine. Currently it has workloa

This crate converts Rust compatible regex-syntax to Vim's NFA engine compatible regex.

This crate converts Rust compatible regex-syntax to Vim's NFA engine compatible regex.

Toy: Layout-Engine
Toy: Layout-Engine

Toy: Layout-Engine

Owner
Nils Hasenbanck
Nils Hasenbanck
Payments Engine is a simple toy payments engine

Payments Engine is a simple toy payments engine that reads a series of transactions from a CSV, updates client accounts, handles disputes and chargebacks, and then outputs the state of clients accounts as a CSV.

Bogdan Arabadzhi 0 Feb 3, 2022
Modrinth API is a simple library for using, you guessed it, the Modrinth API in Rust projects

Modrinth API is a simple library for using, you guessed it, the Modrinth API in Rust projects. It uses reqwest as its HTTP(S) client and deserialises responses to typed structs using serde.

null 21 Jan 1, 2023
API wrapper for the tankerkönig api

tankerkoenig-rs API wrapper for the tankerkoenig-api written in rust. Gives you ready deserialized structs and a easy to use and strictly typed api. I

Jonathan 2 Feb 27, 2022
A repository full of manually generated hand curated JSON files, which contain the API Types that the Discord API returns.

Discord API Types A repository full of manually generated hand curated JSON files, which contain the API Types that the Discord API returns. Also did

Unofficial Discord Documentation 1 Sep 16, 2022
Rust ABI safe code generator

CGlue offers an easy way to ABI (application binary interface) safety. Just a few annotations and your trait is ready to go!

Auri 142 Jan 2, 2023
Totally Speedy Transmute (TST) is a library providing a small, performance oriented, safe version of std::mem::transmute

Totally Speedy Transmute An evil spiritual successor to Totally Safe Transmute What is it? Totally Speedy Transmute (TST) is a library providing a sma

John Schmidt 19 Jun 7, 2022
Display strings in a safe platform-appropriate way

os_display Printing strings can be tricky. They may contain control codes that mess up the message or the whole terminal. On Unix even filenames can c

Jan Verbeek 19 Dec 19, 2022
The working code for my Safe Pay app - check out my tutorial!

Safe Pay Tutorial This repository contains the source code for my blog post Using PDAs and SPL Token in Anchor. The code contains the following: Solan

Daniel Pyrathon 39 Aug 28, 2022
Define safe interfaces to MMIO and CPU registers with ease

regi regi lets you define safe interfaces to MMIO and CPU registers with ease. License Licensed under either of Apache License, Version 2.0 or MIT lic

Valentin B. 2 Feb 10, 2022
A simple, stable and thread-safe implementation of a lazy value

Laizy Laizy is a Rust library that provides a simple, stable and thread-safe implementation of a Lazy Features Name Description Dependencies nightly A

Alex 5 May 15, 2022