Skip to content

manyuanrong/deno-ffi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deno-ffi

Deno Foreign Function Interface

tag Build Status license downloads tag

deno-ffi is a Deno plugin for loading and calling dynamic libraries using pure TypeScript. It can be used to create bindings to native libraries without writing any C++ code.

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

Example

import { ApiDefine, DataType, loadLibrary } from "https://deno.land/x/ffi@v0.1.0/mod.ts";

const libPath = "test.dylib";

interface LibApi {
  rust_fun_print_something(): void;
  rust_fun_add_one(num: number): number;
}

const apiDefine: ApiDefine[] = [
  {
    name: "rust_fun_print_something",
    type: "function",
  },
  {
    name: "rust_fun_add_one",
    type: "function",
    params: [DataType.i32],
    returnType: DataType.i32,
  },
];

const lib = await loadLibrary<LibApi>(libPath, apiDefine);

lib.rust_fun_print_something();

const value = lib.rust_fun_add_one(1);
console.log(value);

About

Deno Foreign Function Interface

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published