meow
This commit is contained in:
parent
84bcb9fb2e
commit
282a2d04d8
3 changed files with 14 additions and 8 deletions
22
index.js
22
index.js
|
|
@ -1,21 +1,27 @@
|
|||
import { dlopen, FFIType, suffix } from "bun:ffi";
|
||||
import { dlopen, FFIType } from "bun:ffi";
|
||||
|
||||
const path = `./libtesticolo.so`;
|
||||
|
||||
// Carica la libreria
|
||||
const { symbols } = dlopen(path, {
|
||||
testicolo: {
|
||||
args: [FFIType.cstring, FFIType.cstring],
|
||||
args: [FFIType.pointer, FFIType.pointer], // Usato pointer per i buffer
|
||||
returns: FFIType.void,
|
||||
},
|
||||
});
|
||||
|
||||
const input = "qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890";
|
||||
const output = new ArrayBuffer(input.length + 1);
|
||||
const outputView = new Uint8Array(output);
|
||||
|
||||
// Call the function with the input string
|
||||
symbols.testicolo(input, outputView);
|
||||
// Converti la stringa in un buffer (Uint8Array)
|
||||
const inputBuffer = new TextEncoder().encode(input);
|
||||
|
||||
// Convert the output buffer to a string and log it
|
||||
const result = new TextDecoder().decode(outputView);
|
||||
// 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);
|
||||
|
||||
|
|
|
|||
BIN
libtesticolo.so
Executable file
BIN
libtesticolo.so
Executable file
Binary file not shown.
BIN
meow
Executable file
BIN
meow
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue