@lakutata/ffi 0.0.0-stage → 3.1.2
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/LICENSE +23 -0
- package/README.md +163 -2
- package/README.zh-CN.md +140 -0
- package/dist/cjs/components/NativeLibrary.d.ts +229 -0
- package/dist/cjs/components/NativeLibrary.js +346 -0
- package/dist/cjs/decorators/Library.d.ts +61 -0
- package/dist/cjs/decorators/Library.js +44 -0
- package/dist/cjs/decorators/Native.d.ts +69 -0
- package/dist/cjs/decorators/Native.js +90 -0
- package/dist/cjs/exceptions/NativeDeclarationException.d.ts +12 -0
- package/dist/cjs/exceptions/NativeDeclarationException.js +19 -0
- package/dist/cjs/exceptions/NativeLibraryClosedException.d.ts +12 -0
- package/dist/cjs/exceptions/NativeLibraryClosedException.js +19 -0
- package/dist/cjs/exceptions/NativeLibraryNotFoundException.d.ts +11 -0
- package/dist/cjs/exceptions/NativeLibraryNotFoundException.js +18 -0
- package/dist/cjs/exceptions/NativeMemoryException.d.ts +11 -0
- package/dist/cjs/exceptions/NativeMemoryException.js +18 -0
- package/dist/cjs/exports/FFI.d.ts +12 -0
- package/dist/cjs/exports/FFI.js +40 -0
- package/dist/cjs/exports/Generator.d.ts +2 -0
- package/dist/cjs/exports/Generator.js +10 -0
- package/dist/cjs/lib/Memory.d.ts +188 -0
- package/dist/cjs/lib/Memory.js +227 -0
- package/dist/cjs/lib/Runtime.d.ts +98 -0
- package/dist/cjs/lib/Runtime.js +209 -0
- package/dist/cjs/lib/backend/Functions.d.ts +65 -0
- package/dist/cjs/lib/backend/Functions.js +214 -0
- package/dist/cjs/lib/backend/KoffiTypes.d.ts +53 -0
- package/dist/cjs/lib/backend/KoffiTypes.js +426 -0
- package/dist/cjs/lib/declarations/Builtins.d.ts +33 -0
- package/dist/cjs/lib/declarations/Builtins.js +179 -0
- package/dist/cjs/lib/declarations/Layout.d.ts +41 -0
- package/dist/cjs/lib/declarations/Layout.js +180 -0
- package/dist/cjs/lib/declarations/Lexer.d.ts +40 -0
- package/dist/cjs/lib/declarations/Lexer.js +325 -0
- package/dist/cjs/lib/declarations/Parser.d.ts +90 -0
- package/dist/cjs/lib/declarations/Parser.js +1425 -0
- package/dist/cjs/lib/declarations/Platform.d.ts +50 -0
- package/dist/cjs/lib/declarations/Platform.js +27 -0
- package/dist/cjs/lib/declarations/Types.d.ts +173 -0
- package/dist/cjs/lib/declarations/Types.js +179 -0
- package/dist/cjs/lib/generator/CText.d.ts +14 -0
- package/dist/cjs/lib/generator/CText.js +133 -0
- package/dist/cjs/lib/generator/Generator.d.ts +136 -0
- package/dist/cjs/lib/generator/Generator.js +395 -0
- package/dist/cjs/lib/generator/Preprocessor.d.ts +60 -0
- package/dist/cjs/lib/generator/Preprocessor.js +94 -0
- package/dist/cjs/lib/generator/TypeScriptTypes.d.ts +35 -0
- package/dist/cjs/lib/generator/TypeScriptTypes.js +153 -0
- package/dist/cjs/lib/library/NativeCallback.d.ts +44 -0
- package/dist/cjs/lib/library/NativeCallback.js +66 -0
- package/dist/cjs/lib/library/NativeLibraryHandle.d.ts +268 -0
- package/dist/cjs/lib/library/NativeLibraryHandle.js +540 -0
- package/dist/cjs/lib/library/Resolve.d.ts +49 -0
- package/dist/cjs/lib/library/Resolve.js +130 -0
- package/dist/cjs/lib/thread/NativeThreads.d.ts +80 -0
- package/dist/cjs/lib/thread/NativeThreads.js +384 -0
- package/dist/cjs/lib/thread/NativeWorker.d.ts +6 -0
- package/dist/cjs/lib/thread/NativeWorker.js +96 -0
- package/dist/cjs/lib/thread/NativeWorkerCode.d.ts +5 -0
- package/dist/cjs/lib/thread/NativeWorkerCode.js +4 -0
- package/dist/cjs/lib/thread/PackageRequire.d.ts +6 -0
- package/dist/cjs/lib/thread/PackageRequire.js +4 -0
- package/dist/cjs/lib/thread/ThreadProtocol.d.ts +77 -0
- package/dist/cjs/lib/thread/ThreadProtocol.js +2 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/components/NativeLibrary.js +338 -0
- package/dist/esm/decorators/Library.js +40 -0
- package/dist/esm/decorators/Native.js +85 -0
- package/dist/esm/exceptions/NativeDeclarationException.js +15 -0
- package/dist/esm/exceptions/NativeLibraryClosedException.js +15 -0
- package/dist/esm/exceptions/NativeLibraryNotFoundException.js +14 -0
- package/dist/esm/exceptions/NativeMemoryException.js +14 -0
- package/dist/esm/exports/FFI.js +10 -0
- package/dist/esm/exports/Generator.js +2 -0
- package/dist/esm/lib/Memory.js +210 -0
- package/dist/esm/lib/Runtime.js +192 -0
- package/dist/esm/lib/backend/Functions.js +206 -0
- package/dist/esm/lib/backend/KoffiTypes.js +418 -0
- package/dist/esm/lib/declarations/Builtins.js +174 -0
- package/dist/esm/lib/declarations/Layout.js +175 -0
- package/dist/esm/lib/declarations/Lexer.js +321 -0
- package/dist/esm/lib/declarations/Parser.js +1421 -0
- package/dist/esm/lib/declarations/Platform.js +23 -0
- package/dist/esm/lib/declarations/Types.js +170 -0
- package/dist/esm/lib/generator/CText.js +129 -0
- package/dist/esm/lib/generator/Generator.js +388 -0
- package/dist/esm/lib/generator/Preprocessor.js +87 -0
- package/dist/esm/lib/generator/TypeScriptTypes.js +149 -0
- package/dist/esm/lib/library/NativeCallback.js +59 -0
- package/dist/esm/lib/library/NativeLibraryHandle.js +532 -0
- package/dist/esm/lib/library/Resolve.js +122 -0
- package/dist/esm/lib/thread/NativeThreads.js +377 -0
- package/dist/esm/lib/thread/NativeWorker.js +93 -0
- package/dist/esm/lib/thread/NativeWorkerCode.js +1 -0
- package/dist/esm/lib/thread/PackageRequire.js +2 -0
- package/dist/esm/lib/thread/ThreadProtocol.js +1 -0
- package/dist/types/components/NativeLibrary.d.ts +229 -0
- package/dist/types/decorators/Library.d.ts +61 -0
- package/dist/types/decorators/Native.d.ts +69 -0
- package/dist/types/exceptions/NativeDeclarationException.d.ts +12 -0
- package/dist/types/exceptions/NativeLibraryClosedException.d.ts +12 -0
- package/dist/types/exceptions/NativeLibraryNotFoundException.d.ts +11 -0
- package/dist/types/exceptions/NativeMemoryException.d.ts +11 -0
- package/dist/types/exports/FFI.d.ts +12 -0
- package/dist/types/exports/Generator.d.ts +2 -0
- package/dist/types/lib/Memory.d.ts +188 -0
- package/dist/types/lib/Runtime.d.ts +98 -0
- package/dist/types/lib/backend/Functions.d.ts +65 -0
- package/dist/types/lib/backend/KoffiTypes.d.ts +53 -0
- package/dist/types/lib/declarations/Builtins.d.ts +33 -0
- package/dist/types/lib/declarations/Layout.d.ts +41 -0
- package/dist/types/lib/declarations/Lexer.d.ts +40 -0
- package/dist/types/lib/declarations/Parser.d.ts +90 -0
- package/dist/types/lib/declarations/Platform.d.ts +50 -0
- package/dist/types/lib/declarations/Types.d.ts +173 -0
- package/dist/types/lib/generator/CText.d.ts +14 -0
- package/dist/types/lib/generator/Generator.d.ts +136 -0
- package/dist/types/lib/generator/Preprocessor.d.ts +60 -0
- package/dist/types/lib/generator/TypeScriptTypes.d.ts +35 -0
- package/dist/types/lib/library/NativeCallback.d.ts +44 -0
- package/dist/types/lib/library/NativeLibraryHandle.d.ts +268 -0
- package/dist/types/lib/library/Resolve.d.ts +49 -0
- package/dist/types/lib/thread/NativeThreads.d.ts +80 -0
- package/dist/types/lib/thread/NativeWorker.d.ts +6 -0
- package/dist/types/lib/thread/NativeWorkerCode.d.ts +5 -0
- package/dist/types/lib/thread/PackageRequire.d.ts +6 -0
- package/dist/types/lib/thread/ThreadProtocol.d.ts +77 -0
- package/package.json +85 -4
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when a library cannot be loaded: its message lists each file tried and why it could not be loaded (not found,
|
|
4
|
+
* built for another architecture, a library it needs missing). Its `errno` is `'E_NATIVE_LIBRARY_NOT_FOUND'`.
|
|
5
|
+
*/
|
|
6
|
+
export declare class NativeLibraryNotFoundException extends Exception {
|
|
7
|
+
/**
|
|
8
|
+
* `'E_NATIVE_LIBRARY_NOT_FOUND'`.
|
|
9
|
+
*/
|
|
10
|
+
errno: string | number;
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NativeLibraryNotFoundException = void 0;
|
|
4
|
+
const core_1 = require("@lakutata/core");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when a library cannot be loaded: its message lists each file tried and why it could not be loaded (not found,
|
|
7
|
+
* built for another architecture, a library it needs missing). Its `errno` is `'E_NATIVE_LIBRARY_NOT_FOUND'`.
|
|
8
|
+
*/
|
|
9
|
+
class NativeLibraryNotFoundException extends core_1.Exception {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
/**
|
|
13
|
+
* `'E_NATIVE_LIBRARY_NOT_FOUND'`.
|
|
14
|
+
*/
|
|
15
|
+
this.errno = 'E_NATIVE_LIBRARY_NOT_FOUND';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.NativeLibraryNotFoundException = NativeLibraryNotFoundException;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when native memory cannot be read or written as asked: a null pointer, a negative length, a view of native
|
|
4
|
+
* memory where the runtime forbids it (Electron). Its `errno` is `'E_NATIVE_MEMORY'`.
|
|
5
|
+
*/
|
|
6
|
+
export declare class NativeMemoryException extends Exception {
|
|
7
|
+
/**
|
|
8
|
+
* `'E_NATIVE_MEMORY'`.
|
|
9
|
+
*/
|
|
10
|
+
errno: string | number;
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NativeMemoryException = void 0;
|
|
4
|
+
const core_1 = require("@lakutata/core");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when native memory cannot be read or written as asked: a null pointer, a negative length, a view of native
|
|
7
|
+
* memory where the runtime forbids it (Electron). Its `errno` is `'E_NATIVE_MEMORY'`.
|
|
8
|
+
*/
|
|
9
|
+
class NativeMemoryException extends core_1.Exception {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
/**
|
|
13
|
+
* `'E_NATIVE_MEMORY'`.
|
|
14
|
+
*/
|
|
15
|
+
this.errno = 'E_NATIVE_MEMORY';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.NativeMemoryException = NativeMemoryException;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { NativeDeclarationException } from '../exceptions/NativeDeclarationException.js';
|
|
2
|
+
export { NativeLibraryNotFoundException } from '../exceptions/NativeLibraryNotFoundException.js';
|
|
3
|
+
export { NativeLibraryClosedException } from '../exceptions/NativeLibraryClosedException.js';
|
|
4
|
+
export { NativeMemoryException } from '../exceptions/NativeMemoryException.js';
|
|
5
|
+
export { type Pointer } from '../lib/Runtime.js';
|
|
6
|
+
export { type LibraryNames } from '../lib/library/Resolve.js';
|
|
7
|
+
export { NativeCallback } from '../lib/library/NativeCallback.js';
|
|
8
|
+
export { loadNativeLibrary, NativeLibraryHandle, type NativeFunctionOptions, type NativeLibraryOptions, type NativeVariableAccessor } from '../lib/library/NativeLibraryHandle.js';
|
|
9
|
+
export { allocMemory, freeMemory, lastErrno, lastWindowsError, type Out, readArray, readBuffer, readCString, readValue, readWString, sizeOf, viewBuffer, writeValue } from '../lib/Memory.js';
|
|
10
|
+
export { Library, type LibraryOptions } from '../decorators/Library.js';
|
|
11
|
+
export { Native, NativeVariable } from '../decorators/Native.js';
|
|
12
|
+
export { buildNativeLibraryOptions, NativeLibrary, type NativeLibraryConfig } from '../components/NativeLibrary.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NativeLibrary = exports.buildNativeLibraryOptions = exports.NativeVariable = exports.Native = exports.Library = exports.writeValue = exports.viewBuffer = exports.sizeOf = exports.readWString = exports.readValue = exports.readCString = exports.readBuffer = exports.readArray = exports.lastWindowsError = exports.lastErrno = exports.freeMemory = exports.allocMemory = exports.NativeLibraryHandle = exports.loadNativeLibrary = exports.NativeCallback = exports.NativeMemoryException = exports.NativeLibraryClosedException = exports.NativeLibraryNotFoundException = exports.NativeDeclarationException = void 0;
|
|
4
|
+
var NativeDeclarationException_js_1 = require("../exceptions/NativeDeclarationException.js");
|
|
5
|
+
Object.defineProperty(exports, "NativeDeclarationException", { enumerable: true, get: function () { return NativeDeclarationException_js_1.NativeDeclarationException; } });
|
|
6
|
+
var NativeLibraryNotFoundException_js_1 = require("../exceptions/NativeLibraryNotFoundException.js");
|
|
7
|
+
Object.defineProperty(exports, "NativeLibraryNotFoundException", { enumerable: true, get: function () { return NativeLibraryNotFoundException_js_1.NativeLibraryNotFoundException; } });
|
|
8
|
+
var NativeLibraryClosedException_js_1 = require("../exceptions/NativeLibraryClosedException.js");
|
|
9
|
+
Object.defineProperty(exports, "NativeLibraryClosedException", { enumerable: true, get: function () { return NativeLibraryClosedException_js_1.NativeLibraryClosedException; } });
|
|
10
|
+
var NativeMemoryException_js_1 = require("../exceptions/NativeMemoryException.js");
|
|
11
|
+
Object.defineProperty(exports, "NativeMemoryException", { enumerable: true, get: function () { return NativeMemoryException_js_1.NativeMemoryException; } });
|
|
12
|
+
var NativeCallback_js_1 = require("../lib/library/NativeCallback.js");
|
|
13
|
+
Object.defineProperty(exports, "NativeCallback", { enumerable: true, get: function () { return NativeCallback_js_1.NativeCallback; } });
|
|
14
|
+
var NativeLibraryHandle_js_1 = require("../lib/library/NativeLibraryHandle.js");
|
|
15
|
+
Object.defineProperty(exports, "loadNativeLibrary", { enumerable: true, get: function () { return NativeLibraryHandle_js_1.loadNativeLibrary; } });
|
|
16
|
+
Object.defineProperty(exports, "NativeLibraryHandle", { enumerable: true, get: function () { return NativeLibraryHandle_js_1.NativeLibraryHandle; } });
|
|
17
|
+
var Memory_js_1 = require("../lib/Memory.js");
|
|
18
|
+
Object.defineProperty(exports, "allocMemory", { enumerable: true, get: function () { return Memory_js_1.allocMemory; } });
|
|
19
|
+
Object.defineProperty(exports, "freeMemory", { enumerable: true, get: function () { return Memory_js_1.freeMemory; } });
|
|
20
|
+
Object.defineProperty(exports, "lastErrno", { enumerable: true, get: function () { return Memory_js_1.lastErrno; } });
|
|
21
|
+
Object.defineProperty(exports, "lastWindowsError", { enumerable: true, get: function () { return Memory_js_1.lastWindowsError; } });
|
|
22
|
+
Object.defineProperty(exports, "readArray", { enumerable: true, get: function () { return Memory_js_1.readArray; } });
|
|
23
|
+
Object.defineProperty(exports, "readBuffer", { enumerable: true, get: function () { return Memory_js_1.readBuffer; } });
|
|
24
|
+
Object.defineProperty(exports, "readCString", { enumerable: true, get: function () { return Memory_js_1.readCString; } });
|
|
25
|
+
Object.defineProperty(exports, "readValue", { enumerable: true, get: function () { return Memory_js_1.readValue; } });
|
|
26
|
+
Object.defineProperty(exports, "readWString", { enumerable: true, get: function () { return Memory_js_1.readWString; } });
|
|
27
|
+
Object.defineProperty(exports, "sizeOf", { enumerable: true, get: function () { return Memory_js_1.sizeOf; } });
|
|
28
|
+
Object.defineProperty(exports, "viewBuffer", { enumerable: true, get: function () { return Memory_js_1.viewBuffer; } });
|
|
29
|
+
Object.defineProperty(exports, "writeValue", { enumerable: true, get: function () { return Memory_js_1.writeValue; } });
|
|
30
|
+
var Library_js_1 = require("../decorators/Library.js");
|
|
31
|
+
Object.defineProperty(exports, "Library", { enumerable: true, get: function () { return Library_js_1.Library; } });
|
|
32
|
+
var Native_js_1 = require("../decorators/Native.js");
|
|
33
|
+
Object.defineProperty(exports, "Native", { enumerable: true, get: function () { return Native_js_1.Native; } });
|
|
34
|
+
Object.defineProperty(exports, "NativeVariable", { enumerable: true, get: function () { return Native_js_1.NativeVariable; } });
|
|
35
|
+
var NativeLibrary_js_1 = require("../components/NativeLibrary.js");
|
|
36
|
+
Object.defineProperty(exports, "buildNativeLibraryOptions", { enumerable: true, get: function () { return NativeLibrary_js_1.buildNativeLibraryOptions; } });
|
|
37
|
+
Object.defineProperty(exports, "NativeLibrary", { enumerable: true, get: function () { return NativeLibrary_js_1.NativeLibrary; } });
|
|
38
|
+
|
|
39
|
+
//The default of the entry: the entry itself (scripts/package-build/cjs-package.mjs)
|
|
40
|
+
if (!Object.prototype.hasOwnProperty.call(exports, 'default')) Object.defineProperty(exports, 'default', {value: exports})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultCompiler = exports.generateNativeLibrary = void 0;
|
|
4
|
+
var Generator_js_1 = require("../lib/generator/Generator.js");
|
|
5
|
+
Object.defineProperty(exports, "generateNativeLibrary", { enumerable: true, get: function () { return Generator_js_1.generateNativeLibrary; } });
|
|
6
|
+
var Preprocessor_js_1 = require("../lib/generator/Preprocessor.js");
|
|
7
|
+
Object.defineProperty(exports, "defaultCompiler", { enumerable: true, get: function () { return Preprocessor_js_1.defaultCompiler; } });
|
|
8
|
+
|
|
9
|
+
//The default of the entry: the entry itself (scripts/package-build/cjs-package.mjs)
|
|
10
|
+
if (!Object.prototype.hasOwnProperty.call(exports, 'default')) Object.defineProperty(exports, 'default', {value: exports})
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { type Pointer } from './Runtime.js';
|
|
2
|
+
/**
|
|
3
|
+
* An output parameter of a pointer or an integer: an array of one element, null before the call, set by the function
|
|
4
|
+
* (`[null]` given to `_Out_ sqlite3 **db`, then `db[0]`)
|
|
5
|
+
*/
|
|
6
|
+
export type Out<T> = [T | null];
|
|
7
|
+
/**
|
|
8
|
+
* Read a C string (UTF-8, ended by a NUL byte) from native memory: a `char *` given as a pointer (a `void *` result, an
|
|
9
|
+
* argument of a callback, a member of a struct).
|
|
10
|
+
* @param pointer Its address.
|
|
11
|
+
* @param length Its length in bytes, when it is not ended by a NUL byte.
|
|
12
|
+
* @returns The string.
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import {readCString, type Pointer} from '@lakutata/ffi'
|
|
16
|
+
*
|
|
17
|
+
* export function messageOf(pointer: Pointer): string {
|
|
18
|
+
* return readCString(pointer)
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function readCString(pointer: Pointer, length?: number): string;
|
|
23
|
+
/**
|
|
24
|
+
* Read a wide string from native memory: a `wchar_t *` (UTF-16 on Windows, UTF-32 elsewhere), ended by a NUL character.
|
|
25
|
+
* @param pointer Its address.
|
|
26
|
+
* @param length Its length in characters, when it is not ended by a NUL character.
|
|
27
|
+
* @returns The string.
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import {readWString, type Pointer} from '@lakutata/ffi'
|
|
31
|
+
*
|
|
32
|
+
* export function titleOf(pointer: Pointer): string {
|
|
33
|
+
* return readWString(pointer)
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function readWString(pointer: Pointer, length?: number): string;
|
|
38
|
+
/**
|
|
39
|
+
* Copy native memory into a buffer of its own, which stays valid once the native memory is freed (about 10 GB/s).
|
|
40
|
+
* @param pointer The address of the memory.
|
|
41
|
+
* @param length Its length in bytes.
|
|
42
|
+
* @returns The copy.
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import {readBuffer, type Pointer} from '@lakutata/ffi'
|
|
46
|
+
*
|
|
47
|
+
* export function frameOf(pixels: Pointer, width: number, height: number): Buffer {
|
|
48
|
+
* return readBuffer(pixels, width * height * 4)
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function readBuffer(pointer: Pointer, length: number): Buffer;
|
|
53
|
+
/**
|
|
54
|
+
* A view of native memory, without copy: worth it for large blocks read often (8 MiB: about 0.13 ms rather than 1 ms
|
|
55
|
+
* for a copy). The view must not be used once the native memory is freed: the process would crash. Electron forbids
|
|
56
|
+
* these views: it throws there (use readBuffer).
|
|
57
|
+
* @param pointer The address of the memory.
|
|
58
|
+
* @param length Its length in bytes.
|
|
59
|
+
* @returns The memory, as an ArrayBuffer.
|
|
60
|
+
* @throws {NativeMemoryException} In Electron, or for a null pointer.
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import {viewBuffer, type Pointer} from '@lakutata/ffi'
|
|
64
|
+
*
|
|
65
|
+
* export function firstPixel(pixels: Pointer): number {
|
|
66
|
+
* return new Uint32Array(viewBuffer(pixels, 4))[0]
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function viewBuffer(pointer: Pointer, length: number): ArrayBuffer;
|
|
71
|
+
/**
|
|
72
|
+
* Read a value of a built-in type from native memory (`int`, `double`, `uint64_t`, `char *`…): the 64-bit integers as
|
|
73
|
+
* bigints. The types of a library are read by `read()` of the library.
|
|
74
|
+
* @param pointer Its address.
|
|
75
|
+
* @param type Its type.
|
|
76
|
+
* @returns The value.
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* import {readValue, type Pointer} from '@lakutata/ffi'
|
|
80
|
+
*
|
|
81
|
+
* export function countAt(pointer: Pointer): number {
|
|
82
|
+
* return readValue(pointer, 'int32_t') as number
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function readValue(pointer: Pointer, type: string): unknown;
|
|
87
|
+
/**
|
|
88
|
+
* Read an array of values of a built-in type from native memory.
|
|
89
|
+
* @param pointer The address of its first element.
|
|
90
|
+
* @param type The type of its elements (`char *` reads strings).
|
|
91
|
+
* @param count Its length.
|
|
92
|
+
* @returns The values.
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* import {readArray, type Pointer} from '@lakutata/ffi'
|
|
96
|
+
*
|
|
97
|
+
* //The row of a callback of sqlite3_exec: char **values
|
|
98
|
+
* export function rowOf(values: Pointer, count: number): string[] {
|
|
99
|
+
* return readArray(values, 'char *', count) as string[]
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function readArray(pointer: Pointer, type: string, count: number): unknown[];
|
|
104
|
+
/**
|
|
105
|
+
* Write a value of a built-in type to native memory.
|
|
106
|
+
* @param pointer Its address.
|
|
107
|
+
* @param type Its type.
|
|
108
|
+
* @param value The value.
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* import {allocMemory, freeMemory, readValue, writeValue} from '@lakutata/ffi'
|
|
112
|
+
*
|
|
113
|
+
* const counter: bigint = allocMemory('int64_t')
|
|
114
|
+
* writeValue(counter, 'int64_t', 42n)
|
|
115
|
+
* console.log(readValue(counter, 'int64_t'))
|
|
116
|
+
* freeMemory(counter)
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function writeValue(pointer: Pointer, type: string, value: unknown): void;
|
|
120
|
+
/**
|
|
121
|
+
* Allocate native memory for values of a built-in type: memory that does not move, which a library can keep (a buffer
|
|
122
|
+
* given to a function is valid during the call only). Freed by freeMemory.
|
|
123
|
+
* @param type The type of the values.
|
|
124
|
+
* @param count Their number.
|
|
125
|
+
* @returns Its address.
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* import {allocMemory, freeMemory} from '@lakutata/ffi'
|
|
129
|
+
*
|
|
130
|
+
* const buffer: bigint = allocMemory('uint8_t', 4096)
|
|
131
|
+
* freeMemory(buffer)
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function allocMemory(type: string, count?: number): Pointer;
|
|
135
|
+
/**
|
|
136
|
+
* Free native memory allocated by allocMemory.
|
|
137
|
+
* @param pointer Its address.
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* import {allocMemory, freeMemory} from '@lakutata/ffi'
|
|
141
|
+
*
|
|
142
|
+
* freeMemory(allocMemory('double', 16))
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function freeMemory(pointer: Pointer): void;
|
|
146
|
+
/**
|
|
147
|
+
* The size of a built-in type on the platform, in bytes (`long` is 8 on 64-bit Linux and macOS, 4 on Windows).
|
|
148
|
+
* @param type The type.
|
|
149
|
+
* @returns Its size.
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* import {sizeOf} from '@lakutata/ffi'
|
|
153
|
+
*
|
|
154
|
+
* console.log(sizeOf('long'), sizeOf('wchar_t'), sizeOf('void *'))
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare function sizeOf(type: string): number;
|
|
158
|
+
/**
|
|
159
|
+
* The errno of the last native call of the thread. On Windows, each C library has its own errno: the one of the C
|
|
160
|
+
* library of Microsoft (ucrtbase.dll) by default.
|
|
161
|
+
* @param crt On Windows, the C library the function called uses (`msvcrt.dll` for the old libraries).
|
|
162
|
+
* @returns The errno.
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import {lastErrno, loadNativeLibrary} from '@lakutata/ffi'
|
|
166
|
+
*
|
|
167
|
+
* const libc = loadNativeLibrary('c')
|
|
168
|
+
* const open = libc.func<(path: string, flags: number) => number>('int open(const char *path, int flags, ...)')
|
|
169
|
+
* if (open('/surely/missing', 0) < 0) console.log('errno', lastErrno())
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare function lastErrno(crt?: string): number;
|
|
173
|
+
/**
|
|
174
|
+
* The last error of the Windows API of the thread (GetLastError), kept after each native call; undefined on the other
|
|
175
|
+
* systems.
|
|
176
|
+
* @returns The error.
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* import {lastWindowsError, loadNativeLibrary} from '@lakutata/ffi'
|
|
180
|
+
*
|
|
181
|
+
* if (process.platform === 'win32') {
|
|
182
|
+
* const kernel32 = loadNativeLibrary('kernel32.dll')
|
|
183
|
+
* const attributes = kernel32.func<(path: string) => number>('DWORD WINAPI GetFileAttributesW(LPCWSTR path)')
|
|
184
|
+
* if (attributes('C:\\missing') === 0xFFFFFFFF) console.log('error', lastWindowsError())
|
|
185
|
+
* }
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export declare function lastWindowsError(): number | undefined;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readCString = readCString;
|
|
7
|
+
exports.readWString = readWString;
|
|
8
|
+
exports.readBuffer = readBuffer;
|
|
9
|
+
exports.viewBuffer = viewBuffer;
|
|
10
|
+
exports.readValue = readValue;
|
|
11
|
+
exports.readArray = readArray;
|
|
12
|
+
exports.writeValue = writeValue;
|
|
13
|
+
exports.allocMemory = allocMemory;
|
|
14
|
+
exports.freeMemory = freeMemory;
|
|
15
|
+
exports.sizeOf = sizeOf;
|
|
16
|
+
exports.lastErrno = lastErrno;
|
|
17
|
+
exports.lastWindowsError = lastWindowsError;
|
|
18
|
+
const koffi_1 = __importDefault(require("koffi"));
|
|
19
|
+
const Runtime_js_1 = require("./Runtime.js");
|
|
20
|
+
/**
|
|
21
|
+
* Read a C string (UTF-8, ended by a NUL byte) from native memory: a `char *` given as a pointer (a `void *` result, an
|
|
22
|
+
* argument of a callback, a member of a struct).
|
|
23
|
+
* @param pointer Its address.
|
|
24
|
+
* @param length Its length in bytes, when it is not ended by a NUL byte.
|
|
25
|
+
* @returns The string.
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import {readCString, type Pointer} from '@lakutata/ffi'
|
|
29
|
+
*
|
|
30
|
+
* export function messageOf(pointer: Pointer): string {
|
|
31
|
+
* return readCString(pointer)
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
function readCString(pointer, length) {
|
|
36
|
+
const address = (0, Runtime_js_1.checkedPointer)(pointer, 'readCString');
|
|
37
|
+
return length === undefined ? koffi_1.default.decode.string(address) : koffi_1.default.decode.string(address, length);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Read a wide string from native memory: a `wchar_t *` (UTF-16 on Windows, UTF-32 elsewhere), ended by a NUL character.
|
|
41
|
+
* @param pointer Its address.
|
|
42
|
+
* @param length Its length in characters, when it is not ended by a NUL character.
|
|
43
|
+
* @returns The string.
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import {readWString, type Pointer} from '@lakutata/ffi'
|
|
47
|
+
*
|
|
48
|
+
* export function titleOf(pointer: Pointer): string {
|
|
49
|
+
* return readWString(pointer)
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
function readWString(pointer, length) {
|
|
54
|
+
const address = (0, Runtime_js_1.checkedPointer)(pointer, 'readWString');
|
|
55
|
+
return length === undefined ? koffi_1.default.decode.wstring(address) : koffi_1.default.decode.wstring(address, length);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Copy native memory into a buffer of its own, which stays valid once the native memory is freed (about 10 GB/s).
|
|
59
|
+
* @param pointer The address of the memory.
|
|
60
|
+
* @param length Its length in bytes.
|
|
61
|
+
* @returns The copy.
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* import {readBuffer, type Pointer} from '@lakutata/ffi'
|
|
65
|
+
*
|
|
66
|
+
* export function frameOf(pixels: Pointer, width: number, height: number): Buffer {
|
|
67
|
+
* return readBuffer(pixels, width * height * 4)
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
function readBuffer(pointer, length) {
|
|
72
|
+
return (0, Runtime_js_1.copyBuffer)(pointer, length);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A view of native memory, without copy: worth it for large blocks read often (8 MiB: about 0.13 ms rather than 1 ms
|
|
76
|
+
* for a copy). The view must not be used once the native memory is freed: the process would crash. Electron forbids
|
|
77
|
+
* these views: it throws there (use readBuffer).
|
|
78
|
+
* @param pointer The address of the memory.
|
|
79
|
+
* @param length Its length in bytes.
|
|
80
|
+
* @returns The memory, as an ArrayBuffer.
|
|
81
|
+
* @throws {NativeMemoryException} In Electron, or for a null pointer.
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import {viewBuffer, type Pointer} from '@lakutata/ffi'
|
|
85
|
+
*
|
|
86
|
+
* export function firstPixel(pixels: Pointer): number {
|
|
87
|
+
* return new Uint32Array(viewBuffer(pixels, 4))[0]
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
function viewBuffer(pointer, length) {
|
|
92
|
+
return (0, Runtime_js_1.nativeView)(pointer, length);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Read a value of a built-in type from native memory (`int`, `double`, `uint64_t`, `char *`…): the 64-bit integers as
|
|
96
|
+
* bigints. The types of a library are read by `read()` of the library.
|
|
97
|
+
* @param pointer Its address.
|
|
98
|
+
* @param type Its type.
|
|
99
|
+
* @returns The value.
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* import {readValue, type Pointer} from '@lakutata/ffi'
|
|
103
|
+
*
|
|
104
|
+
* export function countAt(pointer: Pointer): number {
|
|
105
|
+
* return readValue(pointer, 'int32_t') as number
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
function readValue(pointer, type) {
|
|
110
|
+
return (0, Runtime_js_1.readNative)(Runtime_js_1.BUILTIN_TYPES, pointer, type);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Read an array of values of a built-in type from native memory.
|
|
114
|
+
* @param pointer The address of its first element.
|
|
115
|
+
* @param type The type of its elements (`char *` reads strings).
|
|
116
|
+
* @param count Its length.
|
|
117
|
+
* @returns The values.
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* import {readArray, type Pointer} from '@lakutata/ffi'
|
|
121
|
+
*
|
|
122
|
+
* //The row of a callback of sqlite3_exec: char **values
|
|
123
|
+
* export function rowOf(values: Pointer, count: number): string[] {
|
|
124
|
+
* return readArray(values, 'char *', count) as string[]
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
function readArray(pointer, type, count) {
|
|
129
|
+
return (0, Runtime_js_1.readNative)(Runtime_js_1.BUILTIN_TYPES, pointer, type, count);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Write a value of a built-in type to native memory.
|
|
133
|
+
* @param pointer Its address.
|
|
134
|
+
* @param type Its type.
|
|
135
|
+
* @param value The value.
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* import {allocMemory, freeMemory, readValue, writeValue} from '@lakutata/ffi'
|
|
139
|
+
*
|
|
140
|
+
* const counter: bigint = allocMemory('int64_t')
|
|
141
|
+
* writeValue(counter, 'int64_t', 42n)
|
|
142
|
+
* console.log(readValue(counter, 'int64_t'))
|
|
143
|
+
* freeMemory(counter)
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
function writeValue(pointer, type, value) {
|
|
147
|
+
(0, Runtime_js_1.writeNative)(Runtime_js_1.BUILTIN_TYPES, pointer, type, value);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Allocate native memory for values of a built-in type: memory that does not move, which a library can keep (a buffer
|
|
151
|
+
* given to a function is valid during the call only). Freed by freeMemory.
|
|
152
|
+
* @param type The type of the values.
|
|
153
|
+
* @param count Their number.
|
|
154
|
+
* @returns Its address.
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* import {allocMemory, freeMemory} from '@lakutata/ffi'
|
|
158
|
+
*
|
|
159
|
+
* const buffer: bigint = allocMemory('uint8_t', 4096)
|
|
160
|
+
* freeMemory(buffer)
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
function allocMemory(type, count = 1) {
|
|
164
|
+
return (0, Runtime_js_1.allocateNative)(Runtime_js_1.BUILTIN_TYPES, type, count);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Free native memory allocated by allocMemory.
|
|
168
|
+
* @param pointer Its address.
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* import {allocMemory, freeMemory} from '@lakutata/ffi'
|
|
172
|
+
*
|
|
173
|
+
* freeMemory(allocMemory('double', 16))
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
function freeMemory(pointer) {
|
|
177
|
+
(0, Runtime_js_1.freeNative)(pointer);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The size of a built-in type on the platform, in bytes (`long` is 8 on 64-bit Linux and macOS, 4 on Windows).
|
|
181
|
+
* @param type The type.
|
|
182
|
+
* @returns Its size.
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* import {sizeOf} from '@lakutata/ffi'
|
|
186
|
+
*
|
|
187
|
+
* console.log(sizeOf('long'), sizeOf('wchar_t'), sizeOf('void *'))
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
function sizeOf(type) {
|
|
191
|
+
return (0, Runtime_js_1.typeSize)(Runtime_js_1.BUILTIN_TYPES, type);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The errno of the last native call of the thread. On Windows, each C library has its own errno: the one of the C
|
|
195
|
+
* library of Microsoft (ucrtbase.dll) by default.
|
|
196
|
+
* @param crt On Windows, the C library the function called uses (`msvcrt.dll` for the old libraries).
|
|
197
|
+
* @returns The errno.
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* import {lastErrno, loadNativeLibrary} from '@lakutata/ffi'
|
|
201
|
+
*
|
|
202
|
+
* const libc = loadNativeLibrary('c')
|
|
203
|
+
* const open = libc.func<(path: string, flags: number) => number>('int open(const char *path, int flags, ...)')
|
|
204
|
+
* if (open('/surely/missing', 0) < 0) console.log('errno', lastErrno())
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
function lastErrno(crt) {
|
|
208
|
+
return (0, Runtime_js_1.nativeErrno)(crt);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* The last error of the Windows API of the thread (GetLastError), kept after each native call; undefined on the other
|
|
212
|
+
* systems.
|
|
213
|
+
* @returns The error.
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* import {lastWindowsError, loadNativeLibrary} from '@lakutata/ffi'
|
|
217
|
+
*
|
|
218
|
+
* if (process.platform === 'win32') {
|
|
219
|
+
* const kernel32 = loadNativeLibrary('kernel32.dll')
|
|
220
|
+
* const attributes = kernel32.func<(path: string) => number>('DWORD WINAPI GetFileAttributesW(LPCWSTR path)')
|
|
221
|
+
* if (attributes('C:\\missing') === 0xFFFFFFFF) console.log('error', lastWindowsError())
|
|
222
|
+
* }
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
function lastWindowsError() {
|
|
226
|
+
return (0, Runtime_js_1.nativeWindowsError)();
|
|
227
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { type KoffiType, KoffiTypes } from './backend/KoffiTypes.js';
|
|
2
|
+
import { DeclarationParser } from './declarations/Parser.js';
|
|
3
|
+
import type { CType } from './declarations/Types.js';
|
|
4
|
+
/**
|
|
5
|
+
* The koffi types of the process: one per C type, whatever library declares it
|
|
6
|
+
*/
|
|
7
|
+
export declare const TYPES: KoffiTypes;
|
|
8
|
+
/**
|
|
9
|
+
* A pointer to native memory: a bigint (its address), null for NULL
|
|
10
|
+
*/
|
|
11
|
+
export type Pointer = bigint;
|
|
12
|
+
/**
|
|
13
|
+
* The C types read from their names, with the declarations of a library or the built-in types only
|
|
14
|
+
*/
|
|
15
|
+
export declare class TypeNames {
|
|
16
|
+
#private;
|
|
17
|
+
/**
|
|
18
|
+
* The type names of a library.
|
|
19
|
+
* @param parser Its declarations.
|
|
20
|
+
*/
|
|
21
|
+
constructor(parser: DeclarationParser);
|
|
22
|
+
/**
|
|
23
|
+
* A type, from its name.
|
|
24
|
+
* @param text Its name: `int`, `struct timeval`, `const char *`.
|
|
25
|
+
*/
|
|
26
|
+
type(text: string): CType;
|
|
27
|
+
/**
|
|
28
|
+
* The koffi type of a type name.
|
|
29
|
+
* @param text Its name.
|
|
30
|
+
*/
|
|
31
|
+
koffi(text: string): KoffiType;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The type names of the built-in types (of no library)
|
|
35
|
+
*/
|
|
36
|
+
export declare const BUILTIN_TYPES: TypeNames;
|
|
37
|
+
/**
|
|
38
|
+
* A pointer checked: not null, a bigint or a number
|
|
39
|
+
* @param pointer
|
|
40
|
+
* @param what
|
|
41
|
+
*/
|
|
42
|
+
export declare function checkedPointer(pointer: unknown, what: string): Pointer;
|
|
43
|
+
/**
|
|
44
|
+
* A copy of native memory, in a buffer of its own.
|
|
45
|
+
* @param pointer The address of the memory.
|
|
46
|
+
* @param length Its length in bytes.
|
|
47
|
+
*/
|
|
48
|
+
export declare function copyBuffer(pointer: Pointer, length: number): Buffer;
|
|
49
|
+
/**
|
|
50
|
+
* A view of native memory, without copy: refused in Electron, which forbids them (koffi would end the process).
|
|
51
|
+
* @param pointer The address of the memory.
|
|
52
|
+
* @param length Its length in bytes.
|
|
53
|
+
*/
|
|
54
|
+
export declare function nativeView(pointer: Pointer, length: number): ArrayBuffer;
|
|
55
|
+
/**
|
|
56
|
+
* A value read from native memory, converted as the package gives values (64-bit integers as bigints).
|
|
57
|
+
* @param names The type names to read the type with.
|
|
58
|
+
* @param pointer The address.
|
|
59
|
+
* @param type The type name.
|
|
60
|
+
* @param count The number of values, for an array.
|
|
61
|
+
*/
|
|
62
|
+
export declare function readNative(names: TypeNames, pointer: Pointer, type: string, count?: number): unknown;
|
|
63
|
+
/**
|
|
64
|
+
* A value written to native memory.
|
|
65
|
+
* @param names The type names to read the type with.
|
|
66
|
+
* @param pointer The address.
|
|
67
|
+
* @param type The type name.
|
|
68
|
+
* @param value The value.
|
|
69
|
+
*/
|
|
70
|
+
export declare function writeNative(names: TypeNames, pointer: Pointer, type: string, value: unknown): void;
|
|
71
|
+
/**
|
|
72
|
+
* Native memory allocated for values of a type (C's malloc: freed by freeNative).
|
|
73
|
+
* @param names The type names to read the type with.
|
|
74
|
+
* @param type The type name.
|
|
75
|
+
* @param count The number of values.
|
|
76
|
+
*/
|
|
77
|
+
export declare function allocateNative(names: TypeNames, type: string, count?: number): Pointer;
|
|
78
|
+
/**
|
|
79
|
+
* Free native memory allocated by allocateNative (or by the malloc of the C library the package is built with).
|
|
80
|
+
* @param pointer The address.
|
|
81
|
+
*/
|
|
82
|
+
export declare function freeNative(pointer: Pointer): void;
|
|
83
|
+
/**
|
|
84
|
+
* The errno of the last call made by the thread: on Windows, the one of the C library of Microsoft (ucrtbase.dll), each
|
|
85
|
+
* C library having its own; elsewhere the one koffi keeps after each call.
|
|
86
|
+
* @param crt On Windows, the C library the function called uses.
|
|
87
|
+
*/
|
|
88
|
+
export declare function nativeErrno(crt?: string): number;
|
|
89
|
+
/**
|
|
90
|
+
* The last error of the Windows API of the thread (GetLastError), kept by koffi after each call; undefined elsewhere.
|
|
91
|
+
*/
|
|
92
|
+
export declare function nativeWindowsError(): number | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* The size of a type on the platform, by its name.
|
|
95
|
+
* @param names The type names.
|
|
96
|
+
* @param type The type name.
|
|
97
|
+
*/
|
|
98
|
+
export declare function typeSize(names: TypeNames, type: string): number;
|