Aggiorna index.js

This commit is contained in:
Fransisco Moles 2025-01-05 00:56:32 +01:00
parent f4f473b949
commit 96c5a78739

View file

@ -1,14 +1,21 @@
import { dlopen, FFIType, suffix } from "bun:ffi"; import { dlopen, FFIType, suffix } from "bun:ffi";
const path = `./libfibonacci.so`; const path = `./libtesticolo.so`;
const { symbols } = dlopen(path, { const { symbols } = dlopen(path, {
fibonacci_gmp: { testicolo: {
args: [], args: [FFIType.cstring, FFIType.cstring],
returns: FFIType.cstring, returns: FFIType.void,
}, },
}); });
const result = symbols.fibonacci_gmp(); const input = "qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890";
console.log("Fibonacci(25000) =", result); const output = new ArrayBuffer(input.length + 1);
const outputView = new Uint8Array(output);
// Call the function with the input string
symbols.testicolo(input, outputView);
// Convert the output buffer to a string and log it
const result = new TextDecoder().decode(outputView);
console.log(result);