[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Moving an element on the stack
- From: Ignacio Burgueño <ignaciob@...>
- Date: Wed, 3 Mar 2010 10:43:25 -0200
Hi. I'd like to know which method would be best to do the following.
I have something like this in the stack (from bottom to top)
{ aTable, aFunction, aValue1, ... aValueN }
What I want is to put aFunction below aTable.
Should I:
1) Push the function, remove it from the original position and insert it (now on top of the stack) below 'aTable'
pushvalue(L, 2)
remove(L, 2)
insert(L, 1)
or
2) Save the top, set it to point at the function, insert it below 'aTable' and restore the top.
top = gettop(L)
settop(L, 2)
insert(L, 1)
settop(L, top)
#2 seems cheaper but is it possible that after changing the top, those elements could be collected?
What would be the best way to do that? (maybe there is a third, more obvious way that I´m missing).
Thanks in advance