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.
39 lines
1.1 KiB
39 lines
1.1 KiB
=proto
|
|
int duk_get_int(duk_context *ctx, int index);
|
|
|
|
=stack
|
|
[ ... val! ... ]
|
|
|
|
=summary
|
|
<p>Get the number at <code>index</code> and convert it to a C <code>int</code>
|
|
by first clamping the value between [INT_MIN, 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.</p>
|
|
|
|
<p>Conversion examples:</p>
|
|
<ul>
|
|
<li>-Infinity => INT_MIN</li>
|
|
<li>INT_MIN - 1 => INT_MIN</li>
|
|
<li>-3.9 => -3</li>
|
|
<li>3.9 => 3</li>
|
|
<li>INT_MAX + 1 => INT_MAX</li>
|
|
<li>+Infinity => INT_MAX</li>
|
|
<li>NaN => 0</li>
|
|
<li>"123" => 0 (non-number)</li>
|
|
</ul>
|
|
|
|
<div class="note">
|
|
The coercion is different from a basic C cast from <code>double</code> to
|
|
<code>int</code>, which may have counterintuitive behavior like coercing
|
|
NaN to INT_MIN. The coercion is also different from Ecmascript
|
|
<code>ToInt32()</code> coercion because the full range of the native
|
|
<code>int</code> is allowed, which is useful on platforms with a 64-bit
|
|
<code>int</code> type.
|
|
</div>
|
|
|
|
=example
|
|
printf("int value: %d\n", duk_get_int(ctx, -3));
|
|
|
|
=tags
|
|
stack
|
|
|