Reference/Exch: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Created page with "=Exch= [user_var | stack_index] When no parameter is specified, exchanges the top two elements of the stack. When a parameter is specified and is a user variable, exchanges th...") |
Stritch000 (talk | contribs) m (→Exch) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 5: | Line 5: | ||
When no parameter is specified, exchanges the top two elements of the stack. When a parameter is specified and is a user variable, exchanges the top element of the stack with the parameter. When a parameter is specified and is a positive integer, Exch will swap the item on the top of the stack with the item that is specified by the offset from the top of the stack in the parameter. If there are not enough items on the stack to accomplish the exchange, a fatal error will occur (to help you debug your code :). | When no parameter is specified, exchanges the top two elements of the stack. When a parameter is specified and is a user variable, exchanges the top element of the stack with the parameter. When a parameter is specified and is a positive integer, Exch will swap the item on the top of the stack with the item that is specified by the offset from the top of the stack in the parameter. If there are not enough items on the stack to accomplish the exchange, a fatal error will occur (to help you debug your code :). | ||
<highlight-nsis>Push 1 | <highlight-nsis>Push 1 # Stack == [1] | ||
Push 2 | Push 2 # Stack == [1 2] | ||
Exch | Exch # Stack == [2 1] | ||
Pop $0 # = 1 | Pop $0 # $0 == 1; Stack == [2] | ||
Push | Push 3 # Stack == [2 3] | ||
Push 2 | Push 4 # Stack == [2 3 4] | ||
Push 3 | Push 5 # Stack == [2 3 4 5] | ||
Exch 2 | Exch 2 # Stack == [2 5 4 3] | ||
Pop $ | Pop $1 # $1 == 3; # Stack == [2 5 4] | ||
StrCpy $ | StrCpy $2 6 # $2 == 6 | ||
Push 2 | Push 7 # Stack == [2 5 4 7] | ||
Exch $ | Exch $2 # $2 == 7; # Stack == [2 5 4 6] | ||
Pop $ | Pop $3 # $3 == 6; # Stack == [2 5 4]</highlight-nsis> | ||
''Command introduced with NSIS v1.58'' | |||
Latest revision as of 04:24, 30 December 2024
Exch
[user_var | stack_index]
When no parameter is specified, exchanges the top two elements of the stack. When a parameter is specified and is a user variable, exchanges the top element of the stack with the parameter. When a parameter is specified and is a positive integer, Exch will swap the item on the top of the stack with the item that is specified by the offset from the top of the stack in the parameter. If there are not enough items on the stack to accomplish the exchange, a fatal error will occur (to help you debug your code :).
Push 1 # Stack == [1] Push 2 # Stack == [1 2] Exch # Stack == [2 1] Pop $0 # $0 == 1; Stack == [2] Push 3 # Stack == [2 3] Push 4 # Stack == [2 3 4] Push 5 # Stack == [2 3 4 5] Exch 2 # Stack == [2 5 4 3] Pop $1 # $1 == 3; # Stack == [2 5 4] StrCpy $2 6 # $2 == 6 Push 7 # Stack == [2 5 4 7] Exch $2 # $2 == 7; # Stack == [2 5 4 6] Pop $3 # $3 == 6; # Stack == [2 5 4]
Command introduced with NSIS v1.58