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.
 
 
 
 
 
 

30 lines
928 B

name: duk_set_top
proto: |
void duk_set_top(duk_context *ctx, duk_idx_t index);
stack: |
[ ...! ] -> [ ...! ]
summary: |
<p>Set stack top (stack size) to match the argument <code>index</code>,
normalizing negative index values. If the value stack shrinks,
values above the new stack top are dropped; if the value stack grows,
<code>undefined</code> values are pushed to the new stack slots.</p>
<p>Negative index values are interpreted relative to the current
stack top as in other API calls. For example, index -1 would
decrease the stack top by one.</p>
example: |
/* Assume stack is empty initially. */
duk_push_int(ctx, 123); /* -> top=1, stack: [ 123 ] */
duk_set_top(ctx, 3); /* -> top=3, stack: [ 123 undefined undefined ] */
duk_set_top(ctx, -1); /* -> top=2, stack: [ 123 undefined ] */
duk_set_top(ctx, 0); /* -> top=0, stack: [ ] */
tags:
- stack
introduced: 1.0.0