name: duk_to_int proto: | duk_int_t duk_to_int(duk_context *ctx, duk_int_t index); stack: | [ ... val! ... ] -> [ ... ToNumber(val)! ... ] summary: |

Replace the value at index with an Ecmascript ToInteger() coerced value. Returns an duk_int_t further coerced from the ToInteger() result using the algorithm described in duk_get_int() (this second coercion is not reflected in the new stack value). If index is invalid, throws an error.

If you want the double version of the ToInteger() coerced value, use:

  double d;

  (void) duk_to_int(ctx, -3);
  d = (double) duk_get_number(ctx, -3);
  
duk_get_int() int coercion is applied only to the return value, it is not reflected on the value stack. For instance, if value stack contains the string "Infinity", the value on the stack will be coerced to the number Infinity and DUK_INT_MAX will be returned from the API call.
example: | printf("ToInteger() + int coercion: %ld\n", (long) duk_to_int(ctx, -3)); printf("ToInteger() coercion: %lf\n", (double) duk_get_number(ctx, -3)); tags: - stack introduced: 1.0.0