27 lines
778 B
JavaScript
27 lines
778 B
JavaScript
import { dlopen, FFIType } from "bun:ffi";
|
|
|
|
const path = `./libtesticolo.so`;
|
|
|
|
// Carica la libreria
|
|
const { symbols } = dlopen(path, {
|
|
testicolo: {
|
|
args: [FFIType.pointer, FFIType.pointer], // Usato pointer per i buffer
|
|
returns: FFIType.void,
|
|
},
|
|
});
|
|
|
|
const input = "qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890";
|
|
|
|
// Converti la stringa in un buffer (Uint8Array)
|
|
const inputBuffer = new TextEncoder().encode(input);
|
|
|
|
// Crea un buffer di output della stessa dimensione
|
|
const outputBuffer = new ArrayBuffer(inputBuffer.length);
|
|
|
|
// Passa i buffer alla funzione C
|
|
symbols.testicolo(inputBuffer, outputBuffer);
|
|
|
|
// Decodifica l'output dal buffer
|
|
const result = new TextDecoder().decode(new Uint8Array(outputBuffer));
|
|
console.log(result);
|
|
|