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.
34 lines
900 B
34 lines
900 B
name: duk_insert
|
|
|
|
proto: |
|
|
void duk_insert(duk_context *ctx, duk_idx_t to_idx);
|
|
|
|
stack: |
|
|
[ ... old(to_idx)! ... val! ] -> [ ... val(to_idx)! old! ... ]
|
|
|
|
summary: |
|
|
<p>Insert a value at <code>to_idx</code> with a value popped from the
|
|
stack top. The previous value at <code>to_idx</code> and any values
|
|
above it are moved up the stack by a step. If <code>to_idx</code> is
|
|
an invalid index, throws an error.</p>
|
|
|
|
<div class="note">
|
|
Negative indices are evaluated prior to popping the value at the stack
|
|
top. This is also illustrated by the example.
|
|
</div>
|
|
|
|
example: |
|
|
duk_push_int(ctx, 123);
|
|
duk_push_int(ctx, 234);
|
|
duk_push_int(ctx, 345); /* -> [ 123 234 345 ] */
|
|
duk_push_string(ctx, "foo"); /* -> [ 123 234 345 "foo" ] */
|
|
duk_insert(ctx, -3); /* -> [ 123 "foo" 234 345 ] */
|
|
|
|
tags:
|
|
- stack
|
|
|
|
seealso:
|
|
- duk_pull
|
|
- duk_replace
|
|
|
|
introduced: 1.0.0
|
|
|