d.ts
// add.js/// <reference types="./add.d.ts" />const add = (a) => a + 1
// add.d.tsexport declare const add: (a: number) => number
add
add.js
#[no_mangle]pub extern "C" fn play(path: *const u8) { let path = unsafe { assert!(!path.is_null()); std::ffi::CStr::from_ptr(path as *const i8) }; let path = path.to_str().unwrap(); println!("path: {path}");}
const lib = "./audio/target/debug/libaudio.so"const dylib = Deno.dlopen(lib, { "play": { parameters: ["buffer"], result: "void" } } as const)const encoded = new TextEncoder().encode("path")dylib.symbols.play(encoded)
$ deno run -A --unstable --allow-ffi audio.tsthread '<unnamed>' panicked at src/lib.rs:29:30:called `Result::unwrap()` on an `Err` value: Utf8Error { valid_up_to: 3, error_len: Some(1) }note: run with `RUST_BACKTRACE=1` environment variable to display a backtracefatal runtime error: failed to initiate panic, error 5
deno test -A --watch tools/json_tools/examples/*.ts
ctrl+c