Skip to content

Fix document for returnType and argTypes of cwrap #23981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions site/source/docs/api_reference/preamble.js.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ Calling compiled C functions from JavaScript
my_func(12)

:param ident: The name of the C function to be called.
:param returnType: The return type of the function. This can be ``"number"``, ``"string"`` or ``"array"``, which correspond to the appropriate JavaScript types (use ``"number"`` for any C pointer, and ``"array"`` for JavaScript arrays and typed arrays; note that arrays are 8-bit), or for a void function it can be ``null`` (note: the JavaScript ``null`` value, not a string containing the word "null").
:param argTypes: An array of the types of arguments for the function (if there are no arguments, this can be omitted). Types are as in ``returnType``, except that ``array`` is not supported as there is no way for us to know the length of the array).
:param returnType: The return type of the function. This can be ``"number"`` or ``"string"``, which correspond to the appropriate JavaScript types (use ``"number"`` for any C pointer), or for a void function it can be ``null`` (note: the JavaScript ``null`` value, not a string containing the word "null"). ``array`` is not supported as there is no way for us to know the length of the array.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code it looks like we support "string", "pointer" and "boolean".

I'm not sure we need to spell out where why array is not a valid return type, or rather I'm not sure exactly what the rational is so maybe better to leave it out.

Copy link
Author

@wakairo wakairo Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation for array was simply carried over from what originally existed, so I don't think it's essential, and it can be removed.

That aside, the following description for ":param argTypes:" has disappeared; is this acceptable? I added array to the list of acceptable argument types.

  :param argTypes: An array of the types of arguments for the function (if there are no arguments, this can be omitted). Types can be ``"number"``, ``"string"`` or ``"array"``, which correspond to the appropriate JavaScript types (use ``"number"`` for any C pointer, and ``"array"`` for JavaScript arrays and typed arrays; note that arrays are 8-bit)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should still have some argTypes documentation. I did't realize the rational was part of the original docs here.

:param argTypes: An array of the types of arguments for the function (if there are no arguments, this can be omitted). Types can be ``"number"``, ``"string"`` or ``"array"``, which correspond to the appropriate JavaScript types (use ``"number"`` for any C pointer, and ``"array"`` for JavaScript arrays and typed arrays; note that arrays are 8-bit)
:param opts: An optional options object, see :js:func:`ccall`.
:returns: A JavaScript function that can be used for running the C function.

Expand Down