Skip to content

Commit 4869b67

Browse files
committed
sync
1 parent 50f7ecf commit 4869b67

5 files changed

Lines changed: 12 additions & 9 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ ABI convention to use. Use this when you need to ex: winapi x86 requires "stdcal
139139
**Return**
140140

141141
```ts
142-
function(symbol: string | number, result: unknown, parameters: unknown[]): any;
142+
function(symbol: string | number, result: unknown, parameters: unknown[]): unknown
143143
```
144144

145145
💡 `Koffi` can call by ordinal (symbol:number)
@@ -231,8 +231,8 @@ const { DWORD, LPCSTR } = types.win32;
231231

232232
```js
233233
import { load } from "@xan105/ffi/koffi";
234-
const call = load("user32.dll", { abi: "stdcall" });
235-
const MessageBoxA = call("MessageBoxA", "int", ["void *", "LPCSTR", "LPCSTR", "uint"]);
234+
const lib = load("user32.dll", { abi: "stdcall" });
235+
const MessageBoxA = lib("MessageBoxA", "int", ["void *", "LPCSTR", "LPCSTR", "uint"]);
236236
```
237237

238238
⚠️ Types are not exposed under their own namespace because some words are illegal or already in use in JavaScript.

lib/ffi-napi/helper.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ function pointer(value){
6464
}
6565

6666
function alloc(type){
67-
return {
67+
const buff = Object.assign(Object.create(null), {
6868
pointer: ref.alloc(type),
6969
get: function(){
7070
return this.pointer.deref();
7171
}
72-
}
72+
});
73+
return buff;
7374
}
7475

7576
export { Callback, pointer, alloc };

lib/koffi/helper.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ function pointer(value, direction = "in"){
7272
}
7373

7474
function alloc(type){
75-
return {
75+
const buff = Object.assign(Object.create(null), {
7676
pointer: Buffer.alloc(koffi.sizeof(type)),
7777
get: function(){
7878
return koffi.decode(this.pointer, type);
7979
}
80-
}
80+
});
81+
return buff;
8182
}
8283

8384
export { Callback, pointer, alloc };

lib/koffi/open.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function load(path, option = {}){
4040
}[platform] ?? ".so";
4141

4242
if (path.indexOf(ext) === -1) path += ext;
43-
const [dylib, err] = attemptify(koffi.load)(path);
43+
const [dylib, err] = attemptify(koffi.load)(path, { lazy: false });
4444

4545
if(err && !options.ignoreLoadingFail){
4646
throw new Failure(err.message, {
@@ -90,6 +90,7 @@ function dlopen(path, symbols, option){
9090
const fn = handle(symbol, result, parameters);
9191
if(typeof fn === "function")
9292
lib[name] = nonblocking ? promisify(fn.async) : fn;
93+
}
9394

9495
return lib;
9596
}

types/koffi/open.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export function load(path: string, option?: object): (symbol: string | number, result: unknown, parameters: unknown[]) => any;
1+
export function load(path: string, option?: object): (symbol: string | number, result: unknown, parameters: unknown[]) => unknown;
22
export function dlopen(path: string, symbols: object, option?: object): object;

0 commit comments

Comments
 (0)