Browse Source

api docs for duk_put_prop_{index,string} and duk_has_prop_{index,string}

pull/1/head
Sami Vaarala 11 years ago
parent
commit
e39388ee25
  1. 23
      website/api/duk_has_prop_index.txt
  2. 17
      website/api/duk_has_prop_string.txt
  3. 21
      website/api/duk_put_prop_index.txt
  4. 15
      website/api/duk_put_prop_string.txt

23
website/api/duk_has_prop_index.txt

@ -0,0 +1,23 @@
=proto
int duk_has_prop_index(duk_context *ctx, int obj_index, unsigned int arr_index);
=stack
[ ... obj! ... ] -> [ ... obj! ... ]
=summary
<p>Like <tt><a href="#duk_has_prop">duk_has_prop()</a></tt>,
but the property name is given as an unsigned integer
<tt>arr_index</tt>. This is especially useful for checking
existence of array elements (but is not limited to that).</p>
<p>Conceptually the number is coerced to a string for property
existence check, e.g. <tt>123</tt> would be equivalent to a property
name <tt>"123"</tt>. Duktape avoids an explicit coercion whenever
possible.</p>
=example
if (duk_has_prop_index(ctx, -3, 123)) {
printf("obj has index 123\n");
} else {
printf("obj does not have index 123\n");
}

17
website/api/duk_has_prop_string.txt

@ -0,0 +1,17 @@
=proto
int duk_has_prop_string(duk_context *ctx, int obj_index, const char *key);
=stack
[ ... obj! ... ] -> [ ... obj! ... ]
=summary
<p>Like <tt><a href="#duk_has_prop">duk_has_prop()</a></tt>,
but the property name is given as a NUL-terminated C string
<tt>key</tt>.</p>
=example
if (duk_has_prop(ctx, -3, "myProperty")) {
printf("obj has 'myProperty'\n");
} else {
printf("obj does not have 'myProperty'\n");
}

21
website/api/duk_put_prop_index.txt

@ -0,0 +1,21 @@
=proto
int duk_put_prop_index(duk_context *ctx, int obj_index, unsigned int arr_index);
=stack
[ ... obj! ... val! ] -> [ ... obj! ... ]
=summary
<p>Like <tt><a href="#duk_put_prop">duk_put_prop()</a></tt>,
but the property name is given as an unsigned integer
<tt>arr_index</tt>. This is especially useful for writing to
array elements (but is not limited to that).</p>
<p>Conceptually the number is coerced to a string for the property
write, e.g. <tt>123</tt> would be equivalent to a property
name <tt>"123"</tt>. Duktape avoids an explicit coercion whenever
possible.</p>
=example
duk_push_string(ctx, "value");
rc = duk_put_prop_index(ctx, -3, 123); /* write to obj[123] */
printf("rc=%d\n", rc);

15
website/api/duk_put_prop_string.txt

@ -0,0 +1,15 @@
=proto
int duk_put_prop_string(duk_context *ctx, int obj_index, const char *key);
=stack
[ ... obj! ... val! ] -> [ ... obj! ... ]
=summary
<p>Like <tt><a href="#duk_put_prop">duk_put_prop()</a></tt>,
but the property name is given as a NUL-terminated C string
<tt>key</tt>.</p>
=example
duk_push_string(ctx, "value");
rc = duk_put_prop_string(ctx, -3, "key");
printf("rc=%d\n", rc);
Loading…
Cancel
Save