name: duk_get_int proto: | duk_int_t duk_get_int(duk_context *ctx, duk_idx_t idx); stack: | [ ... val! ... ] summary: |

Get the number at idx 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:

InputOutput
-InfinityDUK_INT_MIN
DUK_INT_MIN - 1DUK_INT_MIN
-3.9-3
3.93
DUK_INT_MAX + 1DUK_INT_MAX
+InfinityDUK_INT_MAX
NaN0
"123"0 (non-number)
The coercion is different from a basic C cast from 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).
example: | printf("int value: %ld\n", (long) duk_get_int(ctx, -3)); tags: - stack seealso: - duk_get_int_default introduced: 1.0.0