Deno Foreign Function Interface.

Overview

deno_plugin_ffi (WIP & Need Help)

Build Status tag Crates.io Docs.rs license

Deno Foreign Function Interface.

deno_ffi is a Deno plugin for loading and calling dynamic libraries using pure JavaScript/TypeScript. It can be used to create bindings to native libraries without writing any Rust code.

It also simplifies the augmentation of Deno with Rust/C/C++ code as it takes care of handling the translation of types across JavaScript/TypeScript and C/Rust, which can add reams of boilerplate code to your otherwise simple C/Rust. See the example/ for an example of this use case.

Example

import * as ffi from "https://deno.land/x/ffi/mod.ts";

const libm = ffi.Library('libm', {
  'add': [ 'int', [ 'int', 'int' ] ]
});
libm.add(1, 2); // 3

// You can also access just functions in the current process by passing a null
var current = ffi.Library(null, {
  'btoa': [ 'string', [ 'string' ] ]
});
current.btoa('1234'); // MTIzNA==

License

deno_plugin_ffi is released under the MIT License. See the bundled LICENSE file for details.

You might also like...
Fast Function Dispatch: Improving the performance of Rust's dynamic function calls

Fast Function Dispatch: Improving the performance of Rust's dynamic function calls A safe, pragmatic toolkit for high-performance virtual function cal

Command line interface as a function.

Command line interface as a function. fncmd fncmd is an opinionated command line parser frontend that wraps around clap. The functionality is mostly i

WasmEdge Host Function Example Interface

A Rust library that provides Rust to WebAssembly developers with syntax for running self-defined host functions when their Wasm is being executed on WasmEdge (formerly SSVM).

On-the-fly machine code executing from Deno

jit from js Execute raw machine code from JavaScript. I hope you know what you're doing :) const inst = new Uint8Array([0xC3]); // ret const noop = ji

The module graph logic for Deno CLI

deno_graph The module graph/dependency logic for the Deno CLI. This repository is a Rust crate which provides the foundational code to be able to buil

SDL2 module for Deno
SDL2 module for Deno

Deno SDL2 Cross platform and stable bindings to SDL2. Have fun! Features Bindings to Video, Graphics, Font and Mixer subsystems. (Uses rodio instead o

Source text parsing, lexing, and AST related functionality for Deno

Source text parsing, lexing, and AST related functionality for Deno.

Simplified glue code generation for Deno FFI libraries written in Rust.

deno_bindgen This tool aims to simplify glue code generation for Deno FFI libraries written in Rust. Quickstart # install CLI deno install -Afq -n den

 Diplo is a script runner and dependency manager made in rust mainly for Deno.
Diplo is a script runner and dependency manager made in rust mainly for Deno.

Diplo is a script runner and dependency manager made in rust mainly for Deno. Documentation Tricked.pro/diplo Installing - windows installer Features

Prototype for a Deno to npm package build tool.

dnt - Deno to Node Transform Prototype for a Deno to npm package build tool. What does this do? It takes a Deno module and creates an npm package for

Prototype for a Deno to npm package build tool.

dnt - Deno to Node Transform Prototype for a Deno to npm package build tool. What does this do? It takes a Deno module and creates an npm package for

A Secure Capability-Based Runtime for JavaScript Based on Deno
A Secure Capability-Based Runtime for JavaScript Based on Deno

Secure Runtime secure-runtime, as the name implies, is a secure runtime for JavaScript, designed for the multi-tenant serverless environment. It is an

Deno wrapper around minifb, for making a framebuffer you can draw pixels to

deno minifb This is a thin wrapper around minifb that you can use in deno. Combine it with canvas for native window that works like the canvas web API

High-level non-blocking Deno bindings to the rust-bert machine learning crate.

bertml High-level non-blocking Deno bindings to the rust-bert machine learning crate. Guide Introduction The ModelManager class manages the FFI bindin

Windowing support for Deno WebGPU.
Windowing support for Deno WebGPU.

deno_desktop Windowing support for Deno WebGPU. In very early stages at the moment. Usage const win = Deno.createWindow({ title: "Deno Desktop", w

Examples for Deno Deploy

Deno Deploy Examples This repository contains a list of examples for Deno Deploy. fetch - Make outbound requests using the fetch() API. json_html - Re

Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust.

Deno Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust. Features Secure by default. No file,

Easy-to-use grammar-based black-box fuzzer. Has found dozens of bugs in important targets like Clang, Deno, and rustc.

tree-crasher tree-crasher is an easy-to-use grammar-based black-box fuzzer. It parses a number of input files using tree-sitter grammars, and produces

Comments
  • Question about structs and by value calls

    Question about structs and by value calls

    Thank you for maintaining this project. After browsing the internet I found out that im lacking some use-cases when it comes to deno FFI.

    First one is that I do not exactly know to to define an C-Struct Datatype on the deno end. Just given the example struct color { unsigned char r; unsigned char r; unsigned char b; unsigned char a; }

    I thought I should by using 'type' in Typescript. But this seems not to be valid syntax in Deno. Could you please provide me an example?

    If this struct would get providden as pointer or reference, I would know what to do. But I get it as 'by value'. Just replacing it with an u8Array was not working for me. Probably I did it wrong.

    So the second question is how to use this kind of data as argument. void setColor(Color c); Again, using u8Array was not successfull and an 'buffer' seems not to match the signature. Could you please provide an short sample how to make a function call 'by value' in this case?

    Thank you very much

    opened by Merulast 0
Releases(0.2.1)
Owner
Deno Foreign Function Interface
Deno Foreign Function Interface.
Deno Foreign Function Interface
Rust library to interface with Lua

hlua This library is a high-level binding for Lua 5.2. You don't have access to the Lua stack, all you can do is read/write variables (including callb

Pierre Krieger 488 Dec 26, 2022
CARBON is an interface-centric programming language named after the concept of an allotropy.

CARBON programming language Status: just an idea CARBON is an interface-centric programming language named after the concept of an allotropy. It is an

Tim McNamara 4 Aug 18, 2022
Rust bindings to the Java Native Interface — JNI

JNI Bindings for Rust This project provides complete JNI bindings for Rust, allowing to: Implement native Java methods for JVM and Android in Rust Cal

null 768 Dec 30, 2022
Foreign Function Interface Plugin for Deno.

Deno FFI Plugin to call dynamic library functions in Deno. Usage import { Library } from "https://deno.land/x/[email protected]/mod.ts"; const lib = new

DjDeveloper 4 Aug 18, 2022
Safe OCaml-Rust Foreign Function Interface

ocaml-rust This repo contains code for a proof of concept for a safe OCaml-Rust interop inspired by cxx. This is mostly optimized for calling Rust cod

Laurent Mazare 23 Dec 27, 2022
Redirect Deno dependencies from semantic versions to the newest fitting version on deno.land/x

Deno Semver Redirect Redirect Deno dependencies from semantic versions to the newest fitting version on deno.land/x. See also this Deno Issue. How to

EdJoPaTo 8 Mar 12, 2022
Subtitles-rs - Use SRT subtitle files to study foreign languages

Rust subtitle utilities Are you looking for substudy? Try here. (substudy has been merged into the subtitles-rs project.) This repository contains a n

Eric Kidd 268 Dec 29, 2022
Postgres Foreign Data Wrapper for Clerk.com API

Pre-requisites Postgres-15 Rust pgrx Getting Started To run the program locally, clone the repository git clone https://github.com/tembo-io/clerk_fdw.

Tembo 3 Aug 22, 2023
Demonstration of flexible function calls in Rust with function overloading and optional arguments

Table of Contents Table of Contents flexible-fn-rs What is this trying to demo? How is the code structured? Named/Unnamed and Optional arguments Mecha

Tien Duc (TiDu) Nguyen 81 Nov 3, 2022
A neural network model that can approximate any non-linear function by using the random search algorithm for the optimization of the loss function.

random_search A neural network model that can approximate any non-linear function by using the random search algorithm for the optimization of the los

ph04 2 Apr 1, 2022