Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
xan105 committed Sep 21, 2023
1 parent 50f7ecf commit 4869b67
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ ABI convention to use. Use this when you need to ex: winapi x86 requires "stdcal
**Return**

```ts
function(symbol: string | number, result: unknown, parameters: unknown[]): any;
function(symbol: string | number, result: unknown, parameters: unknown[]): unknown
```

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

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

⚠️ Types are not exposed under their own namespace because some words are illegal or already in use in JavaScript.
Expand Down
5 changes: 3 additions & 2 deletions lib/ffi-napi/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ function pointer(value){
}

function alloc(type){
return {
const buff = Object.assign(Object.create(null), {
pointer: ref.alloc(type),
get: function(){
return this.pointer.deref();
}
}
});
return buff;
}

export { Callback, pointer, alloc };
5 changes: 3 additions & 2 deletions lib/koffi/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ function pointer(value, direction = "in"){
}

function alloc(type){
return {
const buff = Object.assign(Object.create(null), {
pointer: Buffer.alloc(koffi.sizeof(type)),
get: function(){
return koffi.decode(this.pointer, type);
}
}
});
return buff;
}

export { Callback, pointer, alloc };
3 changes: 2 additions & 1 deletion lib/koffi/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function load(path, option = {}){
}[platform] ?? ".so";

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

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

return lib;
}
Expand Down
2 changes: 1 addition & 1 deletion types/koffi/open.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export function load(path: string, option?: object): (symbol: string | number, result: unknown, parameters: unknown[]) => any;
export function load(path: string, option?: object): (symbol: string | number, result: unknown, parameters: unknown[]) => unknown;
export function dlopen(path: string, symbols: object, option?: object): object;

0 comments on commit 4869b67

Please sign in to comment.