Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
加載共享庫並獲取類型化函數定義
dlopen
Library
function dlopen<Fns extends Record<string, FFIFunction>>( libName: string, defs: Fns, ): Library<Fns>;
import { dlopen, FFIType } from 'arkffi'; const lib = dlopen('libffi_target.so', { add: { args: [FFIType.double, FFIType.double], returns: FFIType.double }, compute: { args: [FFIType.int32, FFIType.double, FFIType.CString], returns: FFIType.double }, }); lib.symbols.add(2.0, 3.0); lib.symbols.compute(0, 4.0, 'square'); lib.close();
libName
string
.so
defs
Record<string, FFIFunction>
interface FFIFunction { args: string[]; // 參數類型編碼 returns: string; // 返回類型編碼 threadsafe?: boolean; // 用於 JSCallback 定義 }
symbols
import { dlopen, FFIType } from 'arkffi'; const lib = dlopen('lib.so', { myFunc: { args: [FFIType.double, FFIType.double], returns: FFIType.double }, }); lib.symbols.myFunc(2.0, 3.0); // 自動補全
這個頁面有幫助嗎?