Browse Source

api doc updates

pull/20/head
Sami Vaarala 11 years ago
parent
commit
469e4e18a3
  1. 4
      website/api/duk_get_int.txt
  2. 39
      website/api/duk_get_uint.txt
  3. 6
      website/api/duk_to_int.txt
  4. 20
      website/api/duk_to_uint.txt

4
website/api/duk_get_int.txt

@ -37,3 +37,7 @@ printf("int value: %d\n", duk_get_int(ctx, -3));
=tags
stack
=FIXME
The limits are actually DUK_INT_MIN and DUK_INT_MAX, which are almost always the same
as INT_MIN and INT_MAX.

39
website/api/duk_get_uint.txt

@ -0,0 +1,39 @@
=proto
unsigned int duk_get_uint(duk_context *ctx, int index);
=stack
[ ... val! ... ]
=summary
<p>Get the number at <code>index</code> and convert it to a C <code>unsigned int</code>
by first clamping the value between [0, 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>
<ul>
<li>-Infinity => 0</li>
<li>-1 => 0</li>
<li>-3.9 => 0</li>
<li>3.9 => 3</li>
<li>UINT_MAX + 1 => UINT_MAX</li>
<li>+Infinity => UINT_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>unsigned int</code>, which may have counterintuitive 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>unsigned int</code> is allowed, which is useful on platforms with a 64-bit
<code>unsigned int</code> type.
</div>
=example
printf("unsigned int value: %u\n", duk_get_uint(ctx, -3));
=tags
stack

6
website/api/duk_to_int.txt

@ -35,8 +35,12 @@ reflected on the value stack. For instance, if value stack contains the string
</div>
=example
printf("ToInteger() + int coercion: %d\n", duk_to_int(ctx, -3));
printf("ToInteger() + int coercion: %ld\n", (long) duk_to_int(ctx, -3));
printf("ToInteger() coercion: %lf\n", duk_get_number(ctx, -3));
=tags
stack
=FIXME
The limits are actually DUK_INT_MIN and DUK_INT_MAX, which are almost always the same
as INT_MIN and INT_MAX.

20
website/api/duk_to_uint.txt

@ -0,0 +1,20 @@
=proto
unsigned int duk_to_uint(duk_context *ctx, int index);
=stack
[ ... val! ... ] -> [ ... ToNumber(val)! ... ]
=summary
<p>Like <code><a href="#duk_to_int">duk_to_int()</a></code> but the return value
coercion is the same as in <code><a href="#duk_get_uint">duk_get_uint()</a></code>.</p>
=example
printf("ToInteger() + uint coercion: %ld\n", (long) duk_to_uint(ctx, -3));
printf("ToInteger() coercion: %lf\n", duk_get_number(ctx, -3));
=tags
stack
=FIXME
The limits are actually DUK_INT_MIN and DUK_INT_MAX, which are almost always the same
as INT_MIN and INT_MAX.
Loading…
Cancel
Save