koffi 2.9.1 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -48
- package/build/koffi/darwin_arm64/koffi.node +0 -0
- package/build/koffi/darwin_x64/koffi.node +0 -0
- package/build/koffi/freebsd_arm64/koffi.node +0 -0
- package/build/koffi/freebsd_ia32/koffi.node +0 -0
- package/build/koffi/freebsd_x64/koffi.node +0 -0
- package/build/koffi/linux_arm32/koffi.node +0 -0
- package/build/koffi/linux_arm64/koffi.node +0 -0
- package/build/koffi/linux_ia32/koffi.node +0 -0
- package/build/koffi/linux_riscv64/koffi.node +0 -0
- package/build/koffi/linux_x64/koffi.node +0 -0
- package/build/koffi/musl_x64/koffi.node +0 -0
- package/build/koffi/openbsd_ia32/koffi.node +0 -0
- package/build/koffi/openbsd_x64/koffi.node +0 -0
- package/build/koffi/win32_arm64/koffi.node +0 -0
- package/build/koffi/win32_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/doc/README.md +27 -0
- package/doc/assets.ini +19 -0
- package/doc/develop.sh +14 -0
- package/doc/flaat/flaat.css +25 -0
- package/doc/flaat/flaat.js +150 -0
- package/doc/flaat/normal.css +335 -0
- package/doc/flaat/print.css +30 -0
- package/doc/flaat/small.css +101 -0
- package/doc/{benchmarks.md → pages/benchmarks.md} +14 -18
- package/doc/{callbacks.md → pages/callbacks.md} +27 -36
- package/doc/{contribute.md → pages/contribute.md} +10 -12
- package/doc/{functions.md → pages/functions.md} +29 -34
- package/doc/pages/index.md +20 -0
- package/doc/{input.md → pages/input.md} +28 -33
- package/doc/{migration.md → pages/migration.md} +7 -10
- package/doc/{misc.md → pages/misc.md} +54 -23
- package/doc/{output.md → pages/output.md} +17 -20
- package/doc/{packaging.md → pages/packaging.md} +19 -12
- package/doc/{platforms.md → pages/platforms.md} +25 -11
- package/doc/{pointers.md → pages/pointers.md} +13 -16
- package/doc/{start.md → pages/start.md} +12 -14
- package/doc/{unions.md → pages/unions.md} +5 -7
- package/doc/{variables.md → pages/variables.md} +7 -11
- package/doc/pages.ini +89 -0
- package/doc/static/koffi.css +21 -0
- package/doc/static/koffi.js +21 -0
- package/doc/static/koffi.png +0 -0
- package/doc/static/logo.webp +0 -0
- package/doc/static/print.css +22 -0
- package/doc/templates/page.html +48 -0
- package/index.js +2 -2
- package/indirect.js +2 -2
- package/package.json +2 -2
- package/src/koffi/CMakeLists.txt +6 -0
- package/src/koffi/examples/yao-pkg/README.md +17 -0
- package/src/koffi/examples/yao-pkg/index.js +2 -0
- package/src/koffi/examples/yao-pkg/package.json +22 -0
- package/src/koffi/src/call.cc +2 -0
- package/src/koffi/src/ffi.cc +40 -4
- package/src/koffi/src/util.cc +1 -1
- package/doc/Makefile +0 -20
- package/doc/benchmarks.xlsx +0 -0
- package/doc/changelog.md +0 -5
- package/doc/conf.py +0 -118
- package/doc/index.rst +0 -47
- package/doc/make.bat +0 -35
- package/doc/poetry.lock +0 -521
- package/doc/pyproject.toml +0 -19
- package/doc/static/bench_linux.png +0 -0
- package/doc/static/bench_windows.png +0 -0
- package/doc/static/custom.css +0 -70
- package/doc/static/node_c.webp +0 -0
- package/doc/static/opensans/LICENSE.txt +0 -202
- package/doc/static/opensans/OpenSans.css +0 -39
- package/doc/static/opensans/OpenSans_v17_Latin_Bold.woff +0 -0
- package/doc/static/opensans/OpenSans_v17_Latin_Bold.woff2 +0 -0
- package/doc/static/opensans/OpenSans_v17_Latin_BoldItalic.woff +0 -0
- package/doc/static/opensans/OpenSans_v17_Latin_BoldItalic.woff2 +0 -0
- package/doc/static/opensans/OpenSans_v17_Latin_Italic.woff +0 -0
- package/doc/static/opensans/OpenSans_v17_Latin_Italic.woff2 +0 -0
- package/doc/static/opensans/OpenSans_v17_Latin_Regular.woff +0 -0
- package/doc/static/opensans/OpenSans_v17_Latin_Regular.woff2 +0 -0
- package/doc/static/perf_linux_20220623.png +0 -0
- package/doc/static/perf_linux_20220623_2.png +0 -0
- package/doc/static/perf_linux_20220627.png +0 -0
- package/doc/static/perf_linux_20220628.png +0 -0
- package/doc/static/perf_linux_20220812.png +0 -0
- package/doc/static/perf_windows_20220623.png +0 -0
- package/doc/static/perf_windows_20220623_2.png +0 -0
- package/doc/static/perf_windows_20220627.png +0 -0
- package/doc/static/perf_windows_20220628.png +0 -0
- package/doc/static/perf_windows_20220812.png +0 -0
- package/doc/templates/badges.html +0 -7
- package/doc/templates/logo.html +0 -3
- /package/doc/static/{perf_linux_20231028.png → perf_linux.png} +0 -0
- /package/doc/static/{perf_windows_20231028.png → perf_windows.png} +0 -0
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Bundling
|
|
2
2
|
|
|
3
|
-
##
|
|
4
|
-
|
|
5
|
-
### Native modules
|
|
3
|
+
## Native modules
|
|
6
4
|
|
|
7
5
|
*Simplified in Koffi 2.5.9*
|
|
8
6
|
|
|
9
7
|
Koffi uses native modules to work. The NPM package contains binaries for various platforms and architectures, and the appropriate module is selected at runtime.
|
|
10
8
|
|
|
9
|
+
> [!IMPORTANT]
|
|
10
|
+
> Please note that Koffi is meant for Node.js (or Electron) and not for browsers! It it not possible to load native libraries inside a browser!
|
|
11
|
+
|
|
11
12
|
In theory, the **packagers/bundlers should be able to find all native modules** because they are explictly listed in the Javascript file (as static strings) and package them somehow.
|
|
12
13
|
|
|
13
14
|
If that is not the case, you can manually arrange to copy the `node_modules/koffi/build/koffi` directory next to your bundled script.
|
|
14
15
|
|
|
15
16
|
Here is an example that would work:
|
|
16
17
|
|
|
17
|
-
```
|
|
18
|
+
```text
|
|
18
19
|
koffi/
|
|
19
20
|
win32_x64/
|
|
20
21
|
koffi.node
|
|
@@ -26,7 +27,7 @@ MyBundle.js
|
|
|
26
27
|
|
|
27
28
|
When running in Electron, Koffi will also try to find the native module in `process.resourcesPath`. For an Electron app you could do something like this
|
|
28
29
|
|
|
29
|
-
```
|
|
30
|
+
```text
|
|
30
31
|
locales/
|
|
31
32
|
resources/
|
|
32
33
|
koffi/
|
|
@@ -38,7 +39,7 @@ resources/
|
|
|
38
39
|
MyApp.exe
|
|
39
40
|
```
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
## Indirect loader
|
|
42
43
|
|
|
43
44
|
*New in Koffi 2.6.2*
|
|
44
45
|
|
|
@@ -46,15 +47,15 @@ Some bundlers (such as vite) don't like when require is used with native modules
|
|
|
46
47
|
|
|
47
48
|
In this case, you can use `require('koffi/indirect')` but you will need to make sure that the native Koffi modules are packaged properly.
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
# Packaging examples
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
## Electron with electron-builder
|
|
52
53
|
|
|
53
54
|
Packaging with electron-builder should work as-is.
|
|
54
55
|
|
|
55
56
|
Take a look at the full [working example in the repository](https://github.com/Koromix/rygel/tree/master/src/koffi/examples/electron-builder).
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
## Electron Forge
|
|
58
59
|
|
|
59
60
|
Packaging with Electron Force should work as-is, even when using webpack as configured initially when you run:
|
|
60
61
|
|
|
@@ -64,13 +65,13 @@ npm init electron-app@latest my-app -- --template=webpack
|
|
|
64
65
|
|
|
65
66
|
Take a look at the full [working example in the repository](https://github.com/Koromix/rygel/tree/master/src/koffi/examples/electron-forge).
|
|
66
67
|
|
|
67
|
-
|
|
68
|
+
## NW.js
|
|
68
69
|
|
|
69
70
|
Packagers such as nw-builder should work as-is.
|
|
70
71
|
|
|
71
72
|
You can find a full [working example in the repository](https://github.com/Koromix/rygel/tree/master/src/koffi/examples/nwjs).
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
## Node.js and esbuild
|
|
74
75
|
|
|
75
76
|
You can easily tell esbuild to copy the native files with the copy loader and things should just work. Use something like:
|
|
76
77
|
|
|
@@ -79,3 +80,9 @@ esbuild index.js --platform=node --bundle --loader:.node=copy --outdir=dist/
|
|
|
79
80
|
```
|
|
80
81
|
|
|
81
82
|
You can find a full [working example in the repository](https://github.com/Koromix/rygel/tree/master/src/koffi/examples/node-esbuild).
|
|
83
|
+
|
|
84
|
+
## Node.js and yao-pkg
|
|
85
|
+
|
|
86
|
+
Use [yao-pkg](https://github.com/yao-pkg/pkg) to make binary packages of your Node.js-based project.
|
|
87
|
+
|
|
88
|
+
You can find a full [working example in the repository](https://github.com/Koromix/rygel/tree/master/src/koffi/examples/yao-pkg).
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Node.js
|
|
1
|
+
# Node.js
|
|
4
2
|
|
|
5
3
|
Koffi requires a recent [Node.js](https://nodejs.org/) version with [N-API](https://nodejs.org/api/n-api.html) version 8 support:
|
|
6
4
|
|
|
@@ -12,20 +10,36 @@ Koffi requires a recent [Node.js](https://nodejs.org/) version with [N-API](http
|
|
|
12
10
|
|
|
13
11
|
Use [NVM](https://github.com/nvm-sh/nvm) to install more recent Node versions on older Linux distributions.
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
# Supported platforms
|
|
16
14
|
|
|
17
15
|
The following combinations of OS and architectures __are officially supported and tested__ at the moment:
|
|
18
16
|
|
|
19
|
-
ISA / OS | Windows
|
|
20
|
-
------------------ |
|
|
21
|
-
x86 (IA32) [^1] | ✅
|
|
22
|
-
x86_64 (AMD64) | ✅
|
|
23
|
-
ARM32 LE [^2] | ⬜️
|
|
24
|
-
ARM64 (AArch64) LE | ✅
|
|
25
|
-
RISC-V 64 [^3] | ⬜️
|
|
17
|
+
ISA / OS | Windows | Linux (glibc) | Linux (musl)
|
|
18
|
+
------------------ | ------- | ------------- | ------------
|
|
19
|
+
x86 (IA32) [^1] | ✅ | ✅ | 🟨
|
|
20
|
+
x86_64 (AMD64) | ✅ | ✅ | ✅
|
|
21
|
+
ARM32 LE [^2] | ⬜️ | ✅ | 🟨
|
|
22
|
+
ARM64 (AArch64) LE | ✅ | ✅ | 🟨
|
|
23
|
+
RISC-V 64 [^3] | ⬜️ | ✅ | 🟨
|
|
24
|
+
|
|
25
|
+
<div class="legend">✅ Yes | 🟨 Probably | ⬜️ Not applicable</div>
|
|
26
|
+
|
|
27
|
+
ISA / OS | macOS | FreeBSD | OpenBSD
|
|
28
|
+
------------------ | ----- | ----------- | --------
|
|
29
|
+
x86 (IA32) [^1] | ⬜️ | ✅ | ✅
|
|
30
|
+
x86_64 (AMD64) | ✅ | ✅ | ✅
|
|
31
|
+
ARM32 LE [^2] | ⬜️ | 🟨 | 🟨
|
|
32
|
+
ARM64 (AArch64) LE | ✅ | ✅ | 🟨
|
|
33
|
+
RISC-V 64 [^3] | ⬜️ | 🟨 | 🟨
|
|
34
|
+
|
|
35
|
+
<div class="legend">✅ Yes | 🟨 Probably | ⬜️ Not applicable</div>
|
|
26
36
|
|
|
27
37
|
[^1]: The following call conventions are supported for forward calls: cdecl, stdcall, MS fastcall, thiscall. Only cdecl and stdcall can be used for C to JS callbacks.
|
|
28
38
|
[^2]: The prebuilt binary uses the hard float ABI and expects a VFP coprocessor. Build from source to use Koffi with a different ABI (softfp, soft).
|
|
29
39
|
[^3]: The prebuilt binary uses the LP64D (double-precision float) ABI. The LP64 ABI is supported in theory if you build Koffi from source (untested), the LP64F ABI is not supported.
|
|
30
40
|
|
|
31
41
|
For all fully supported platforms (green check marks), a prebuilt binary is included in the NPM package which means you can install Koffi without a C++ compiler.
|
|
42
|
+
|
|
43
|
+
<style>
|
|
44
|
+
table td:not(:first-child) { text-align: center; }
|
|
45
|
+
</style>
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## How pointers are used
|
|
1
|
+
# How pointers are used
|
|
4
2
|
|
|
5
3
|
In C, pointer arguments are used for differenty purposes. It is important to distinguish these use cases because Koffi provides different ways to deal with each of them:
|
|
6
4
|
|
|
@@ -9,9 +7,9 @@ In C, pointer arguments are used for differenty purposes. It is important to dis
|
|
|
9
7
|
- **Pointers to primitive types**: This is more rare, and generally used for output or input/output arguments. The Win32 API has a lot of these.
|
|
10
8
|
- **Arrays**: in C, you dynamically-sized arrays are usually passed to functions with pointers, either NULL-terminated (or any other sentinel value) or with an additional length argument.
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
# Pointer types
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
## Struct pointers
|
|
15
13
|
|
|
16
14
|
The following Win32 example uses `GetCursorPos()` (with an output parameter) to retrieve and show the current cursor position.
|
|
17
15
|
|
|
@@ -37,7 +35,7 @@ if (!GetCursorPos(pos))
|
|
|
37
35
|
console.log(pos);
|
|
38
36
|
```
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
## Opaque pointers
|
|
41
39
|
|
|
42
40
|
*New in Koffi 2.0*
|
|
43
41
|
|
|
@@ -51,7 +49,7 @@ const GetHandleInformation = lib.func('bool __stdcall GetHandleInformation(HANDL
|
|
|
51
49
|
const CloseHandle = lib.func('bool __stdcall CloseHandle(HANDLE h)');
|
|
52
50
|
```
|
|
53
51
|
|
|
54
|
-
|
|
52
|
+
## Pointer to primitive types
|
|
55
53
|
|
|
56
54
|
In javascript, it is not possible to pass a primitive value by reference to another function. This means that you cannot call a function and expect it to modify the value of one of its number or string parameter.
|
|
57
55
|
|
|
@@ -88,7 +86,7 @@ AddInt(sum, 6);
|
|
|
88
86
|
console.log(sum[0]); // Prints 42
|
|
89
87
|
```
|
|
90
88
|
|
|
91
|
-
|
|
89
|
+
## Dynamic arrays
|
|
92
90
|
|
|
93
91
|
In C, dynamically-sized arrays are usually passed around as pointers. The length is either passed as an additional argument, or inferred from the array content itself, for example with a terminating sentinel value (such as a NULL pointers in the case of an array of strings).
|
|
94
92
|
|
|
@@ -130,9 +128,9 @@ let total = ComputeTotalLength(strings);
|
|
|
130
128
|
console.log(total); // Prints 14
|
|
131
129
|
```
|
|
132
130
|
|
|
133
|
-
By default, just like for objects, array arguments are copied from JS to C but not vice-versa. You can however change the direction as documented in the section on [output parameters](output
|
|
131
|
+
By default, just like for objects, array arguments are copied from JS to C but not vice-versa. You can however change the direction as documented in the section on [output parameters](output).
|
|
134
132
|
|
|
135
|
-
|
|
133
|
+
# Handling void pointers
|
|
136
134
|
|
|
137
135
|
*New in Koffi 2.1*
|
|
138
136
|
|
|
@@ -195,7 +193,7 @@ let hdr = {};
|
|
|
195
193
|
console.log('PNG header:', hdr);
|
|
196
194
|
```
|
|
197
195
|
|
|
198
|
-
|
|
196
|
+
# Disposable types
|
|
199
197
|
|
|
200
198
|
*New in Koffi 2.0*
|
|
201
199
|
|
|
@@ -230,7 +228,7 @@ let copy = strdup('Hello!');
|
|
|
230
228
|
console.log(copy); // Prints Hello!
|
|
231
229
|
```
|
|
232
230
|
|
|
233
|
-
When you declare functions with the [prototype-like syntax](functions
|
|
231
|
+
When you declare functions with the [prototype-like syntax](functions#definition-syntax), you can either use named disposable types or use the '!' shortcut qualifier with compatibles types, as shown in the example below. This qualifier creates an anonymous disposable type that calls `koffi.free(ptr)`.
|
|
234
232
|
|
|
235
233
|
```js
|
|
236
234
|
// ES6 syntax: import koffi from 'koffi';
|
|
@@ -247,10 +245,9 @@ console.log(copy); // Prints World!
|
|
|
247
245
|
|
|
248
246
|
Disposable types can only be created from pointer or string types.
|
|
249
247
|
|
|
250
|
-
|
|
251
|
-
Be careful on Windows: if your shared library uses a different CRT (such as msvcrt), the memory could have been allocated by a different malloc/free implementation or heap, resulting in undefined behavior if you use `koffi.free()`.
|
|
252
|
-
```
|
|
248
|
+
> [!WARNING]
|
|
249
|
+
> Be careful on Windows: if your shared library uses a different CRT (such as msvcrt), the memory could have been allocated by a different malloc/free implementation or heap, resulting in undefined behavior if you use `koffi.free()`.
|
|
253
250
|
|
|
254
|
-
|
|
251
|
+
# Unwrap pointers
|
|
255
252
|
|
|
256
253
|
You can use `koffi.address(ptr)` on a pointer to get the numeric value as a [BigInt object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Install Koffi
|
|
1
|
+
# Install Koffi
|
|
4
2
|
|
|
5
3
|
You can install Koffi with npm:
|
|
6
4
|
|
|
@@ -18,14 +16,14 @@ const koffi = require('koffi');
|
|
|
18
16
|
import koffi from 'koffi';
|
|
19
17
|
```
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
# Simple examples
|
|
22
20
|
|
|
23
21
|
Below you can find two examples:
|
|
24
22
|
|
|
25
23
|
* The first one runs on Linux. The functions are declared with the C-like prototype language.
|
|
26
24
|
* The second one runs on Windows, and uses the node-ffi like syntax to declare functions.
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
## For Linux
|
|
29
27
|
|
|
30
28
|
This is a small example for Linux systems, which uses `gettimeofday()`, `localtime_r()` and `printf()` to print the current time.
|
|
31
29
|
|
|
@@ -52,7 +50,7 @@ const tm = koffi.struct('tm', {
|
|
|
52
50
|
tm_sec: 'int',
|
|
53
51
|
tm_min: 'int',
|
|
54
52
|
tm_hour: 'int',
|
|
55
|
-
|
|
53
|
+
tmay: 'int',
|
|
56
54
|
tm_mon: 'int',
|
|
57
55
|
tm_year: 'int',
|
|
58
56
|
tm_wday: 'int',
|
|
@@ -76,7 +74,7 @@ printf('Hello World!\n');
|
|
|
76
74
|
printf('Local time: %02d:%02d:%02d\n', 'int', now.tm_hour, 'int', now.tm_min, 'int', now.tm_sec);
|
|
77
75
|
```
|
|
78
76
|
|
|
79
|
-
|
|
77
|
+
## For Windows
|
|
80
78
|
|
|
81
79
|
This is a small example targeting the Win32 API, using `MessageBox()` to show a *Hello World!* message to the user.
|
|
82
80
|
|
|
@@ -103,18 +101,18 @@ const MessageBoxA = lib.func('__stdcall', 'MessageBoxA', 'int', ['void *', 'str'
|
|
|
103
101
|
const MessageBoxW = lib.func('__stdcall', 'MessageBoxW', 'int', ['void *', 'str16', 'str16', 'uint']);
|
|
104
102
|
|
|
105
103
|
let ret = MessageBoxA(null, 'Do you want another message box?', 'Koffi', MB_YESNO | MB_ICONQUESTION);
|
|
104
|
+
|
|
106
105
|
if (ret == IDYES)
|
|
107
106
|
MessageBoxW(null, 'Hello World!', 'Koffi', MB_ICONINFORMATION);
|
|
108
107
|
```
|
|
109
108
|
|
|
110
|
-
|
|
109
|
+
# Bundling Koffi
|
|
111
110
|
|
|
112
|
-
Please read the [dedicated page](packaging
|
|
111
|
+
Please read the [dedicated page](packaging) for information about bundling and packaging applications using Koffi.
|
|
113
112
|
|
|
114
|
-
|
|
113
|
+
# Build manually
|
|
115
114
|
|
|
116
|
-
Follow the [build instrutions](contribute
|
|
115
|
+
Follow the [build instrutions](contribute#build-from-source) if you want to build the native Koffi code yourself.
|
|
117
116
|
|
|
118
|
-
|
|
119
|
-
This is only needed if you want to hack on Koffi. The official NPM package provide prebuilt binaries and you don't need to compile anything if you only want to use Koffi in Node.js.
|
|
120
|
-
```
|
|
117
|
+
> [!NOTE]
|
|
118
|
+
> This is only needed if you want to hack on Koffi. The official NPM package provide prebuilt binaries and you don't need to compile anything if you only want to use Koffi in Node.js.
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
# Union
|
|
1
|
+
# Union definition
|
|
2
2
|
|
|
3
3
|
*New in Koffi 2.5*
|
|
4
4
|
|
|
5
|
-
## Union definition
|
|
6
|
-
|
|
7
5
|
You can declare unions with a syntax similar to structs, but with the `koffi.union()` function. This function takes two arguments: the first one is the name of the type, and the second one is an object containing the union member names and types. You can omit the first argument to declare an anonymous union.
|
|
8
6
|
|
|
9
7
|
The following example illustrates how to declare the same union in C and in JS with Koffi:
|
|
@@ -22,9 +20,9 @@ const IntOrDouble = koffi.union('IntOrDouble', {
|
|
|
22
20
|
});
|
|
23
21
|
```
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
# Input unions
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
## Passing union values to C
|
|
28
26
|
|
|
29
27
|
You can instantiate an union object with `koffi.Union(type)`. This will create a special object that contains at most one active member.
|
|
30
28
|
|
|
@@ -53,7 +51,7 @@ DoSomething('int', { i: 42 });
|
|
|
53
51
|
DoSomething('string', { str: 'Hello!' });
|
|
54
52
|
```
|
|
55
53
|
|
|
56
|
-
|
|
54
|
+
## Win32 example
|
|
57
55
|
|
|
58
56
|
The following example uses the [SendInput](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput) Win32 API to emit the Win+D shortcut and hide windows (show the desktop).
|
|
59
57
|
|
|
@@ -138,7 +136,7 @@ function make_keyboard_event(vk, down) {
|
|
|
138
136
|
}
|
|
139
137
|
```
|
|
140
138
|
|
|
141
|
-
|
|
139
|
+
# Output unions
|
|
142
140
|
|
|
143
141
|
Unlike structs, Koffi does not know which union member is valid, and it cannot decode it automatically. You can however use special `koffi.Union` objects for output parameters, and decode the memory after the call.
|
|
144
142
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Variable definitions
|
|
1
|
+
# Variable definitions
|
|
4
2
|
|
|
5
3
|
*New in Koffi 2.6*
|
|
6
4
|
|
|
@@ -21,7 +19,7 @@ You cannot directly manipulate these variables, use:
|
|
|
21
19
|
- [koffi.decode()](#decode-to-js-values) to read their value
|
|
22
20
|
- [koffi.encode()](#encode-to-c-memory) to change their valuèe
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
# Decode to JS values
|
|
25
23
|
|
|
26
24
|
*New in Koffi 2.2, changed in Koffi 2.3*
|
|
27
25
|
|
|
@@ -61,11 +59,10 @@ The example below will decode the symbol `my_string` defined above but only the
|
|
|
61
59
|
console.log(koffi.decode(my_string, 'const char *', 3)) // Prints "foo"
|
|
62
60
|
```
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
In Koffi 2.2 and earlier versions, the length argument is only used to decode strings and is ignored otherwise.
|
|
66
|
-
```
|
|
62
|
+
> [!NOTE]
|
|
63
|
+
> In Koffi 2.2 and earlier versions, the length argument is only used to decode strings and is ignored otherwise.
|
|
67
64
|
|
|
68
|
-
|
|
65
|
+
# Encode to C memory
|
|
69
66
|
|
|
70
67
|
*New in Koffi 2.6*
|
|
71
68
|
|
|
@@ -101,6 +98,5 @@ When encoding strings (either directly or embedded in arrays or structs), the me
|
|
|
101
98
|
|
|
102
99
|
There is also an optional ending `length` argument that you can use to encode an array. For example, here is how you can encode an array with 3 float values: `koffi.encode(symbol, 'float', [1, 2, 3], 3)`. This is equivalent to `koffi.encode(symbol, koffi.array('float', 3), [1, 2, 3])`.
|
|
103
100
|
|
|
104
|
-
|
|
105
|
-
The length argument did not work correctly before Koffi 2.6.11.
|
|
106
|
-
```
|
|
101
|
+
> [!NOTE]
|
|
102
|
+
> The length argument did not work correctly before Koffi 2.6.11.
|
package/doc/pages.ini
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
[pages/index.md]
|
|
2
|
+
Title = Koffi
|
|
3
|
+
Menu = Overview
|
|
4
|
+
Description = Koffi presentation and features
|
|
5
|
+
ToC = Off
|
|
6
|
+
Template = templates/page.html
|
|
7
|
+
|
|
8
|
+
[pages/platforms.md]
|
|
9
|
+
Title = Requirements | Koffi
|
|
10
|
+
Menu = Documentation / Requirements
|
|
11
|
+
Description = Supported systemd and architectures
|
|
12
|
+
Template = templates/page.html
|
|
13
|
+
|
|
14
|
+
[pages/start.md]
|
|
15
|
+
Title = Get started | Koffi
|
|
16
|
+
Menu = Documentation / Get started
|
|
17
|
+
Description = Install and start using Koffi in your Node.js project
|
|
18
|
+
Template = templates/page.html
|
|
19
|
+
|
|
20
|
+
[pages/functions.md]
|
|
21
|
+
Title = Function calls | Koffi
|
|
22
|
+
Menu = Documentation / Function calls
|
|
23
|
+
Description = Call native functions
|
|
24
|
+
Template = templates/page.html
|
|
25
|
+
|
|
26
|
+
[pages/input.md]
|
|
27
|
+
Title = Input parameters | Koffi
|
|
28
|
+
Menu = Documentation / Input parameters
|
|
29
|
+
Template = templates/page.html
|
|
30
|
+
|
|
31
|
+
[pages/pointers.md]
|
|
32
|
+
Title = Data pointers | Koffi
|
|
33
|
+
Menu = Documentation / Data pointers
|
|
34
|
+
Template = templates/page.html
|
|
35
|
+
|
|
36
|
+
[pages/output.md]
|
|
37
|
+
Title = Output parameters | Koffi
|
|
38
|
+
Menu = Documentation / Output parameters
|
|
39
|
+
Template = templates/page.html
|
|
40
|
+
|
|
41
|
+
[pages/unions.md]
|
|
42
|
+
Title = Union values | Koffi
|
|
43
|
+
Menu = Documentation / Union values
|
|
44
|
+
Template = templates/page.html
|
|
45
|
+
|
|
46
|
+
[pages/variables.md]
|
|
47
|
+
Title = Exported variables | Koffi
|
|
48
|
+
Menu = Documentation / Exported variables
|
|
49
|
+
Template = templates/page.html
|
|
50
|
+
|
|
51
|
+
[pages/callbacks.md]
|
|
52
|
+
Title = Callbacks | Koffi
|
|
53
|
+
Menu = Documentation / Javascript callbacks
|
|
54
|
+
Template = templates/page.html
|
|
55
|
+
|
|
56
|
+
[pages/misc.md]
|
|
57
|
+
Title = Miscellaneous | Koffi
|
|
58
|
+
Menu = Documentation / Miscellaneous
|
|
59
|
+
Template = templates/page.html
|
|
60
|
+
|
|
61
|
+
[pages/packaging.md]
|
|
62
|
+
Title = Packaging | Koffi
|
|
63
|
+
Menu = Documentation / Bundlers and Koffi
|
|
64
|
+
Template = templates/page.html
|
|
65
|
+
|
|
66
|
+
[pages/migration.md]
|
|
67
|
+
Title = Migration | Koffi
|
|
68
|
+
Menu = Documentation / Migration guide
|
|
69
|
+
Description = Migration between major Koffi versions
|
|
70
|
+
Template = templates/page.html
|
|
71
|
+
|
|
72
|
+
[pages/benchmarks.md]
|
|
73
|
+
Title = Benchmarks | Koffi
|
|
74
|
+
Menu = Benchmarks
|
|
75
|
+
Description = Performance of Koffi compared to NAPI and node-ffi
|
|
76
|
+
Template = templates/page.html
|
|
77
|
+
|
|
78
|
+
[pages/contribute.md]
|
|
79
|
+
Title = Contribute | Koffi
|
|
80
|
+
Menu = Contribute
|
|
81
|
+
Description = How to get, build and test Koffi code
|
|
82
|
+
Template = templates/page.html
|
|
83
|
+
|
|
84
|
+
[changelog]
|
|
85
|
+
SourceFile = ../../src/koffi/CHANGELOG.md
|
|
86
|
+
Title = Changelog | Koffi
|
|
87
|
+
Menu = Changelog
|
|
88
|
+
Description = List of Koffi versions
|
|
89
|
+
Template = templates/page.html
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* Copyright (C) 2024 Niels Martignène <niels.martignene@protonmail.com>
|
|
2
|
+
|
|
3
|
+
This program is free software: you can redistribute it and/or modify
|
|
4
|
+
it under the terms of the GNU General Public License as published by
|
|
5
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
(at your option) any later version.
|
|
7
|
+
|
|
8
|
+
This program is distributed in the hope that it will be useful,
|
|
9
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
GNU General Public License for more details.
|
|
12
|
+
|
|
13
|
+
You should have received a copy of the GNU General Public License
|
|
14
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
15
|
+
|
|
16
|
+
@import url('../flaat/flaat.css');
|
|
17
|
+
@import url('../../../vendor/highlight.js/styles/base16/tomorrow.css');
|
|
18
|
+
|
|
19
|
+
html {
|
|
20
|
+
--primary_color: #ec7400;
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright (C) 2024 Niels Martignène <niels.martignene@protonmail.com>
|
|
2
|
+
//
|
|
3
|
+
// This program is free software: you can redistribute it and/or modify
|
|
4
|
+
// it under the terms of the GNU General Public License as published by
|
|
5
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
// (at your option) any later version.
|
|
7
|
+
//
|
|
8
|
+
// This program is distributed in the hope that it will be useful,
|
|
9
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
// GNU General Public License for more details.
|
|
12
|
+
//
|
|
13
|
+
// You should have received a copy of the GNU General Public License
|
|
14
|
+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
15
|
+
|
|
16
|
+
import '../flaat/flaat.js';
|
|
17
|
+
import * as hljs from '../../../vendor/highlight.js/highlight.js';
|
|
18
|
+
|
|
19
|
+
window.addEventListener('load', e => {
|
|
20
|
+
hljs.highlightAll();
|
|
21
|
+
});
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* Copyright (C) 2024 Niels Martignène <niels.martignene@protonmail.com>
|
|
2
|
+
|
|
3
|
+
This program is free software: you can redistribute it and/or modify
|
|
4
|
+
it under the terms of the GNU General Public License as published by
|
|
5
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
(at your option) any later version.
|
|
7
|
+
|
|
8
|
+
This program is distributed in the hope that it will be useful,
|
|
9
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
GNU General Public License for more details.
|
|
12
|
+
|
|
13
|
+
You should have received a copy of the GNU General Public License
|
|
14
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
15
|
+
|
|
16
|
+
@media print {
|
|
17
|
+
.schema { width: 90%; }
|
|
18
|
+
|
|
19
|
+
.columns { display: block; }
|
|
20
|
+
.columns > * { width: auto; }
|
|
21
|
+
.columns > * + * { margin-top: 3em; }
|
|
22
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en" class="nojs">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
|
|
7
|
+
<title>{{ TITLE }}</title>
|
|
8
|
+
<meta name="author" content="Niels Martignène">
|
|
9
|
+
<meta name="description" content="{{ DESCRIPTION }}">
|
|
10
|
+
<link rel="icon" href="{{ ASSET favicon.png }}">
|
|
11
|
+
|
|
12
|
+
<meta name="theme-color" content="#6aa051">
|
|
13
|
+
<link rel="stylesheet" href="{{ ASSET static/site.min.css }}">
|
|
14
|
+
|
|
15
|
+
<script type="text/javascript" src="{{ ASSET static/site.min.js }}" async></script>
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<body>
|
|
19
|
+
<div id="deploy"></div>
|
|
20
|
+
|
|
21
|
+
<nav id="top">
|
|
22
|
+
<menu>
|
|
23
|
+
<a id="logo" href="/"><img src="{{ ASSET static/logo.webp }}" alt="Logo Koffi" /></a>
|
|
24
|
+
|
|
25
|
+
{{ LINKS }}
|
|
26
|
+
|
|
27
|
+
<div style="flex: 1;"></div>
|
|
28
|
+
|
|
29
|
+
<li><a href="https://www.npmjs.com/package/koffi" style="border-bottom-color: transparent; margin-top: 8px;"><img src="https://img.shields.io/badge/NPM-2.9.2-brightgreen" alt="NPM"/></a></li>
|
|
30
|
+
<li><a href="https://github.com/Koromix/koffi" style="border-bottom-color: transparent; margin-top: 8px;"><img src="https://img.shields.io/badge/GitHub-Koffi-ff6600" alt="GitHub"/></a></li>
|
|
31
|
+
</menu>
|
|
32
|
+
</nav>
|
|
33
|
+
|
|
34
|
+
{{ TOC }}
|
|
35
|
+
|
|
36
|
+
<main>
|
|
37
|
+
{{ CONTENT }}
|
|
38
|
+
</main>
|
|
39
|
+
|
|
40
|
+
<footer>
|
|
41
|
+
<div>Koffi © 2024</div>
|
|
42
|
+
<div style="font-size: 0.8em;">
|
|
43
|
+
Niels Martignène (<a href="https://github.com/Koromix/" target="_blank">Koromix</a>)<br>
|
|
44
|
+
<a href="mailto:niels.martignene@protonmail.com" style="font-weight: bold; color: inherit;">niels.martignene@protonmail.com</a>
|
|
45
|
+
</div>
|
|
46
|
+
</footer>
|
|
47
|
+
</body>
|
|
48
|
+
</html>
|
package/index.js
CHANGED
|
@@ -363,8 +363,8 @@ var require_package = __commonJS({
|
|
|
363
363
|
"../../bin/Koffi/package/src/koffi/package.json"(exports2, module2) {
|
|
364
364
|
module2.exports = {
|
|
365
365
|
name: "koffi",
|
|
366
|
-
version: "2.
|
|
367
|
-
stable: "2.
|
|
366
|
+
version: "2.10.0",
|
|
367
|
+
stable: "2.10.0",
|
|
368
368
|
description: "Fast and simple C FFI (foreign function interface) for Node.js",
|
|
369
369
|
keywords: [
|
|
370
370
|
"foreign",
|
package/indirect.js
CHANGED
|
@@ -363,8 +363,8 @@ var require_package = __commonJS({
|
|
|
363
363
|
"../../bin/Koffi/package/src/koffi/package.json"(exports2, module2) {
|
|
364
364
|
module2.exports = {
|
|
365
365
|
name: "koffi",
|
|
366
|
-
version: "2.
|
|
367
|
-
stable: "2.
|
|
366
|
+
version: "2.10.0",
|
|
367
|
+
stable: "2.10.0",
|
|
368
368
|
description: "Fast and simple C FFI (foreign function interface) for Node.js",
|
|
369
369
|
keywords: [
|
|
370
370
|
"foreign",
|
package/package.json
CHANGED
package/src/koffi/CMakeLists.txt
CHANGED
|
@@ -48,6 +48,12 @@ else()
|
|
|
48
48
|
endif()
|
|
49
49
|
endif()
|
|
50
50
|
|
|
51
|
+
if(UNIX AND NOT APPLE)
|
|
52
|
+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64")
|
|
53
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FILE_OFFSET_BITS=64")
|
|
54
|
+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z noexecstack")
|
|
55
|
+
endif()
|
|
56
|
+
|
|
51
57
|
# ---- Koffi ----
|
|
52
58
|
|
|
53
59
|
# Recompute the version string after each commit
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
This is a simple example to bundle a CLI node.js app that uses Koffi, using [yao-pkg](https://github.com/yao-pkg/pkg).
|
|
2
|
+
|
|
3
|
+
To run the app, execute the following:
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
cd examples/yao-pkg
|
|
7
|
+
npm install
|
|
8
|
+
npm start
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
You can bundle the script and the native modules with the following command
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
cd examples/yao-pkg
|
|
15
|
+
npm install
|
|
16
|
+
npm run bundle
|
|
17
|
+
```
|