Complete the code to load a native library using Deno FFI.
const dylib = Deno.dlopen("./libexample.so", [1]);
You must provide a symbols object describing the native functions you want to use. This object maps function names to their parameter and result types.
Complete the code to call the native 'add' function with arguments 5 and 3.
const result = dylib.symbols.add([1], [2]);
The 'add' function expects two 32-bit integers. You must pass both arguments in the correct order.
Fix the error in the native function declaration to correctly specify a function returning void.
const dylib = Deno.dlopen("./libexample.so", { "log": { parameters: ["pointer"], result: [1] } });
In Deno FFI, a native function returning nothing uses the result type "void".
Fill both blanks to define a native function 'multiply' that takes two 64-bit floats and returns a 64-bit float.
const dylib = Deno.dlopen("./libexample.so", { "multiply": { parameters: [[1], [2]], result: "f64" } });
The 'multiply' function takes two 64-bit floats as parameters, so both parameters must be "f64".
Fill all three blanks to create a safe wrapper function that calls the native 'subtract' function and returns its result.
function safeSubtract(a: number, b: number): number {
return dylib.symbols.[1]([2], [3]);
}The wrapper calls the native 'subtract' function with arguments 'a' and 'b' and returns the result.
