name: duk_get_int proto: | duk_int_t duk_get_int(duk_context *ctx, duk_idx_t index); stack: | [ ... val! ... ] summary: |
Get the number at index
and convert it to a C duk_int_t
by first clamping the value between [DUK_INT_MIN, DUK_INT_MAX] and then
truncating towards zero. The value on the stack is not modified.
If the value is a NaN, is not a number, or the index is invalid,
returns 0.
Conversion examples:
Input | Output |
---|---|
-Infinity | DUK_INT_MIN |
DUK_INT_MIN - 1 | DUK_INT_MIN |
-3.9 | -3 |
3.9 | 3 |
DUK_INT_MAX + 1 | DUK_INT_MAX |
+Infinity | DUK_INT_MAX |
NaN | 0 |
"123" | 0 (non-number) |
double
to
integer, which may have counterintuitive (and non-portable) behavior like coercing
NaN to DUK_INT_MIN
. The coercion is also different from Ecmascript
ToInt32()
coercion because the full range of the native
duk_int_t
is allowed (which may be more than 32 bits).