mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.1 KiB
30 lines
1.1 KiB
=proto
|
|
void duk_to_primitive(duk_context *ctx, int index, int hint);
|
|
|
|
=stack
|
|
[ ... val! ... ] -> [ ... ToPrimitive(val)! ]
|
|
|
|
=summary
|
|
<p>Replace the object at <code>index</code> with an Ecmascript
|
|
<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-9.1">ToPrimitive()</a>
|
|
coerced value. The <code>hint</code> argument affects coercion of an object into a
|
|
primitive type, and indicates preference for a string (<code>DUK_HINT_STRING</code>),
|
|
a number (<code>DUK_HINT_NUMBER</code>), or neither (<code>DUK_HINT_NONE</code>).
|
|
<code>DUK_HINT_NONE</code> causes a preference to a number, unless the input value
|
|
is a <code>Date</code> instance, in which case a string is preferred (the exact
|
|
coercion behavior is described in the Ecmascript specification). If <code>index</code>
|
|
is invalid, throws an error.</p>
|
|
|
|
<p>Custom type coercion:</p>
|
|
<ul>
|
|
<li>Buffer: keep existing value (no coercion)</li>
|
|
<li>Pointer: keep existing value (no coercion)</li>
|
|
</ul>
|
|
|
|
<p>In other words, custom types are considered primitive.</p>
|
|
|
|
=example
|
|
duk_to_primitive(ctx, -3, DUK_HINT_NUMBER);
|
|
|
|
=tags
|
|
stack
|
|
|