@@ -124,18 +124,18 @@ such as `0` and `1`; JavaScript `true` and `false` are not accepted.
124124
125125Functions and callbacks are described with signature objects.
126126
127- Supported fields:
127+ Signature objects may contain the following properties, both of which are
128+ optional:
128129
129- * ` result ` , ` return ` , or ` returns ` for the return type.
130- * ` parameters ` or ` arguments ` for the parameter type list.
130+ * ` return ` {string} A [ type name] [ type names ] specifying the return type of the
131+ function or callback. ** Default:** ` 'void' ` .
132+ * ` arguments ` {string\[ ] } An array of [ type names] [ ] specifying the argument
133+ type list of the function or callback. ** Default:** ` [] ` .
131134
132- Only one return-type field and one parameter-list field may be present in a
133- single signature object.
134-
135- ``` cjs
135+ ``` js
136136const signature = {
137- result : ' i32' ,
138- parameters : [' i32' , ' i32' ],
137+ return : ' i32' ,
138+ arguments : [' i32' , ' i32' ],
139139};
140140```
141141
@@ -193,7 +193,7 @@ import { dlopen } from 'node:ffi';
193193
194194{
195195 using handle = dlopen (' ./mylib.so' , {
196- add_i32: { parameters : [' i32' , ' i32' ], result : ' i32' },
196+ add_i32: { arguments : [' i32' , ' i32' ], return : ' i32' },
197197 });
198198 console .log (handle .functions .add_i32 (20 , 22 ));
199199} // handle.lib.close() is invoked automatically here.
@@ -203,8 +203,8 @@ import { dlopen } from 'node:ffi';
203203import { dlopen } from ' node:ffi' ;
204204
205205const { lib , functions } = dlopen (' ./mylib.so' , {
206- add_i32: { parameters : [' i32' , ' i32' ], result : ' i32' },
207- string_length: { parameters : [' pointer' ], result : ' u64' },
206+ add_i32: { arguments : [' i32' , ' i32' ], return : ' i32' },
207+ string_length: { arguments : [' pointer' ], return : ' u64' },
208208});
209209
210210console .log (functions .add_i32 (20 , 22 ));
@@ -214,8 +214,8 @@ console.log(functions.add_i32(20, 22));
214214const { dlopen } = require (' node:ffi' );
215215
216216const { lib , functions } = dlopen (' ./mylib.so' , {
217- add_i32: { parameters : [' i32' , ' i32' ], result : ' i32' },
218- string_length: { parameters : [' pointer' ], result : ' u64' },
217+ add_i32: { arguments : [' i32' , ' i32' ], return : ' i32' },
218+ string_length: { arguments : [' pointer' ], return : ' u64' },
219219});
220220
221221console .log (functions .add_i32 (20 , 22 ));
@@ -356,8 +356,8 @@ const { DynamicLibrary } = require('node:ffi');
356356
357357const lib = new DynamicLibrary (' ./mylib.so' );
358358const add = lib .getFunction (' add_i32' , {
359- parameters : [' i32' , ' i32' ],
360- result : ' i32' ,
359+ arguments : [' i32' , ' i32' ],
360+ return : ' i32' ,
361361});
362362
363363console .log (add (20 , 22 ));
@@ -407,7 +407,7 @@ const { DynamicLibrary } = require('node:ffi');
407407const lib = new DynamicLibrary (' ./mylib.so' );
408408
409409const callback = lib .registerCallback (
410- { parameters : [' i32' ], result : ' i32' },
410+ { arguments : [' i32' ], return : ' i32' },
411411 (value ) => value * 2 ,
412412);
413413```
@@ -417,7 +417,7 @@ Callbacks are subject to the following restrictions:
417417* They must be invoked on the same system thread where they were created.
418418* They must not throw exceptions.
419419* They must not return promises.
420- * They must return a value compatible with the declared result type.
420+ * They must return a value compatible with the declared return type.
421421* They must not call ` library.close() ` on their owning library while running.
422422* They must not unregister themselves while running.
423423
@@ -465,7 +465,7 @@ JavaScript `number` values that match the declared type.
465465
466466For 64-bit integer types (` i64 ` and ` u64 ` ), pass JavaScript ` bigint ` values.
467467
468- For pointer-like parameters :
468+ For pointer-like arguments :
469469
470470* ` null ` and ` undefined ` are passed as null pointers.
471471* ` string ` values are copied to temporary NUL-terminated UTF-8 strings for the
@@ -727,3 +727,4 @@ and keep callback and pointer lifetimes explicit on the native side.
727727[ `--allow-ffi` ] : cli.md#--allow-ffi
728728[ `ffi.toBuffer(pointer, length, copy)` ] : #ffitobufferpointer-length-copy
729729[ `using` ] : https://tc39.es/proposal-explicit-resource-management/#sec-using-declarations
730+ [ type names ] : #type-names
0 commit comments