mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 18:38:33 +00:00
feat(ext/ffi): structs by value (#15060)
Adds support for passing and returning structs as buffers to FFI. This does not implement fastapi support for structs. Needed for certain system APIs such as AppKit on macOS.
This commit is contained in:
parent
84ef26ac9b
commit
ad82918f56
15 changed files with 568 additions and 80 deletions
24
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
24
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
|
@ -94,6 +94,13 @@ declare namespace Deno {
|
|||
*/
|
||||
type NativeVoidType = "void";
|
||||
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
* The native struct type for interfacing with foreign functions.
|
||||
*
|
||||
*/
|
||||
type NativeStructType = { readonly struct: readonly NativeType[] };
|
||||
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
* All supported types for interfacing with foreign functions.
|
||||
|
@ -106,7 +113,8 @@ declare namespace Deno {
|
|||
| NativeBooleanType
|
||||
| NativePointerType
|
||||
| NativeBufferType
|
||||
| NativeFunctionType;
|
||||
| NativeFunctionType
|
||||
| NativeStructType;
|
||||
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
|
@ -136,7 +144,9 @@ declare namespace Deno {
|
|||
*
|
||||
* @category FFI
|
||||
*/
|
||||
type ToNativeType<T extends NativeType = NativeType> = ToNativeTypeMap[T];
|
||||
type ToNativeType<T extends NativeType = NativeType> = T extends
|
||||
NativeStructType ? BufferSource
|
||||
: ToNativeTypeMap[Exclude<T, NativeStructType>];
|
||||
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
|
@ -153,7 +163,8 @@ declare namespace Deno {
|
|||
* @category FFI
|
||||
*/
|
||||
type ToNativeResultType<T extends NativeResultType = NativeResultType> =
|
||||
ToNativeResultTypeMap[T];
|
||||
T extends NativeStructType ? BufferSource
|
||||
: ToNativeResultTypeMap[Exclude<T, NativeStructType>];
|
||||
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
|
@ -193,7 +204,9 @@ declare namespace Deno {
|
|||
*
|
||||
* @category FFI
|
||||
*/
|
||||
type FromNativeType<T extends NativeType = NativeType> = FromNativeTypeMap[T];
|
||||
type FromNativeType<T extends NativeType = NativeType> = T extends
|
||||
NativeStructType ? Uint8Array
|
||||
: FromNativeTypeMap[Exclude<T, NativeStructType>];
|
||||
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
|
@ -212,7 +225,8 @@ declare namespace Deno {
|
|||
* @category FFI
|
||||
*/
|
||||
type FromNativeResultType<T extends NativeResultType = NativeResultType> =
|
||||
FromNativeResultTypeMap[T];
|
||||
T extends NativeStructType ? Uint8Array
|
||||
: FromNativeResultTypeMap[Exclude<T, NativeStructType>];
|
||||
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue