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.
46 lines
1.4 KiB
46 lines
1.4 KiB
name: duk_get_uint
|
|
|
|
proto: |
|
|
duk_uint_t duk_get_uint(duk_context *ctx, duk_idx_t idx);
|
|
|
|
stack: |
|
|
[ ... val! ... ]
|
|
|
|
summary: |
|
|
<p>Get the number at <code>idx</code> and convert it to a C <code>duk_uint_t</code>
|
|
by first clamping the value between [0, DUK_UINT_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>
|
|
<table>
|
|
<tr><th>Input</th><th>Output</th></tr>
|
|
<tr><td>-Infinity</td><td>0</td></tr>
|
|
<tr><td>-1</td><td>0</td></tr>
|
|
<tr><td>-3.9</td><td>0</td></tr>
|
|
<tr><td>3.9</td><td>3</td></tr>
|
|
<tr><td>DUK_UINT_MAX + 1</td><td>DUK_UINT_MAX</td></tr>
|
|
<tr><td>+Infinity</td><td>DUK_UINT_MAX</td></tr>
|
|
<tr><td>NaN</td><td>0</td></tr>
|
|
<tr><td>"123"</td><td>0 (non-number)</td></tr>
|
|
</table>
|
|
|
|
<div class="note">
|
|
The coercion is different from a basic C cast from <code>double</code> to
|
|
unsigned integer, which may have counterintuitive (and non-portable) behavior
|
|
for e.g. NaN values. The coercion is also different from ECMAScript
|
|
<code>ToUint32()</code> coercion because the full range of the native
|
|
<code>duk_uint_t</code> is allowed (which may be more than 32 bits).
|
|
</div>
|
|
|
|
example: |
|
|
printf("unsigned int value: %lu\n", (unsigned long) duk_get_uint(ctx, -3));
|
|
|
|
tags:
|
|
- stack
|
|
|
|
seealso:
|
|
- duk_get_uint_default
|
|
|
|
introduced: 1.0.0
|
|
|