Jsctypes/api: Difference between revisions

Jump to navigation Jump to search
(Make char/signed_char/unsigned_char autoconvert to JS numbers, not strings)
Line 462: Line 462:
:::* The result is an array of type ''t'' whose first ''n'' elements are the 8-bit values in ''s''. If <code>''t''.length &gt; ''n''</code>, then element ''n'' of the result is 0. The values of the rest of the array elements are unspecified.
:::* The result is an array of type ''t'' whose first ''n'' elements are the 8-bit values in ''s''. If <code>''t''.length &gt; ''n''</code>, then element ''n'' of the result is 0. The values of the rest of the array elements are unspecified.
::* Otherwise fail.
::* Otherwise fail.
:* If ''val'' is a JavaScript array object:
:* If ''val'' is a JavaScript array object:
::* If <code>''val''.length</code> is not a nonnegative integer, fail.
::* If <code>''val''.length</code> is not a nonnegative integer, fail.
::* If <code>''val''.length !== ''t''.length</code>, fail.
::* If <code>''val''.length !== ''t''.length</code>, fail.
::* Otherwise, the result is a C/C++ array of <code>''val''.length</code> elements of type <code>''t''.elementType</code>. Element ''i'' of the result is <code>ImplicitConvert(''val''[''i''], ''t''.elementType)</code>.
::* Otherwise, the result is a C/C++ array of <code>''val''.length</code> elements of type <code>''t''.elementType</code>. Element ''i'' of the result is <code>ImplicitConvert(''val''[''i''], ''t''.elementType)</code>.
:* Otherwise fail.
:* Otherwise fail. ''(Rationale: The clause "If ''val'' is a JavaScript array object" requires some justification. If we allowed arbitrary JavaScript objects that resemble arrays, that would include CData objects of array type. Consequently, <code>arr1.value = arr2</code> where <code>arr1</code> is of type <code>ctypes.uint8_t.array(30)</code> and <code>arr2</code> is of type <code>ctypes.int.array(30)</code> would work as long as the values in <code>arr2</code> are small enough. We considered this conversion too astonishing and too error-prone.)''


* Otherwise ''t'' is a struct type.
* Otherwise ''t'' is a struct type.
638

edits

Navigation menu