mirror of https://github.com/svaarala/duktape.git
Sami Vaarala
11 years ago
4 changed files with 76 additions and 0 deletions
@ -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"); |
|||
} |
@ -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"); |
|||
} |
@ -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); |
@ -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…
Reference in new issue