638
edits
(→Conversions: elaborate on that) |
(→Calling types: Add auto-sizing ctypes.jschar.array(10)("hello") and ctypes.char.array(10)("hello")) |
||
Line 192: | Line 192: | ||
:If ''t'' is an array type of unspecified length and ''val'' is a size value (defined above): Let ''u'' = <code>ArrayType(''t''.elementType, ''val'')</code> and return <code>new ''u''</code>. | :If ''t'' is an array type of unspecified length and ''val'' is a size value (defined above): Let ''u'' = <code>ArrayType(''t''.elementType, ''val'')</code> and return <code>new ''u''</code>. | ||
:If <code>SameType(''t'', ArrayType(ctypes.jschar))</code> and ''val'' is a string: Return a new <code>CData</code> object of type <code>ArrayType(ctypes.jschar, ''val''.length + 1)</code> containing the contents of ''val'' followed by a null character. | |||
:If ''t'' is an array type of unspecified length, <code>''t''.elementType</code> is an 8-bit character type, and ''val'' is a string: If ''val'' is not a well-formed UTF-16 string, throw a <code>TypeError</code>. Otherwise, let ''s'' = a sequence of bytes, the result of converting ''val'' from UTF-16 to UTF-8, and let ''n'' = the number of bytes in ''s''. Return a new <code>CData</code> object of type <code>ArrayType(''t''.elementType, ''n'' + 1)</code> containing the bytes in ''s'' followed by a null character. | |||
:If ''t'' is an array type of unspecified length and ''val'' is not a size value: If ''val'' is not an object, or it does not have a <code>.length</code> property whose value is a nonnegative integer, throw a <code>TypeError</code>. Otherwise, let ''u'' = <code>ArrayType(''t''.elementType, ''val''.length)</code> and return <code>new ''u''(''val'')</code>. | :If ''t'' is an array type of unspecified length and ''val'' is not a size value: If ''val'' is not an object, or it does not have a <code>.length</code> property whose value is a nonnegative integer, throw a <code>TypeError</code>. Otherwise, let ''u'' = <code>ArrayType(''t''.elementType, ''val''.length)</code> and return <code>new ''u''(''val'')</code>. |
edits