=proto void duk_to_primitive(duk_context *ctx, int index, int hint); =stack [ ... val! ... ] -> [ ... ToPrimitive(val)! ] =summary
Replace the object at index
with an Ecmascript
ToPrimitive()
coerced value. The hint
argument affects coercion of an object into a
primitive type, and indicates preference for a string (DUK_HINT_STRING
),
a number (DUK_HINT_NUMBER
), or neither (DUK_HINT_NONE
).
DUK_HINT_NONE
causes a preference to a number, unless the input value
is a Date
instance, in which case a string is preferred (the exact
coercion behavior is described in the Ecmascript specification). If index
is invalid, throws an error.
Custom type coercion:
In other words, custom types are considered primitive.
=example duk_to_primitive(ctx, -3, DUK_HINT_NUMBER); =tags stack