View previous topic :: View next topic |
Author |
Message |
akumakuja28 Master Cheater Reputation: 16
Joined: 28 Jun 2015 Posts: 432
|
Posted: Sun Jun 26, 2016 1:09 pm Post subject: Moving Index in Address List |
|
|
Is a way possible to Move the position(Index) of an Address List Entry in Lua?
_________________
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sun Jun 26, 2016 4:57 pm Post subject: |
|
|
Move your entries as a child under a single one.
Then you can call appendToEntry() to rearrange those.
?
|
|
Back to top |
|
|
akumakuja28 Master Cheater Reputation: 16
Joined: 28 Jun 2015 Posts: 432
|
Posted: Sun Jun 26, 2016 5:00 pm Post subject: |
|
|
Zanzer wrote: | Move your entries as a child under a single one.
Then you can call appendToEntry() to rearrange those.
? |
Ok ill try that
_________________
|
|
Back to top |
|
|
akumakuja28 Master Cheater Reputation: 16
Joined: 28 Jun 2015 Posts: 432
|
Posted: Tue Jun 28, 2016 1:55 pm Post subject: |
|
|
Thanks Zanzer. The child grouping seemed to be the only way to do the sort.
Is it possible to remove the Child entry from the Parent?
I have tried A couple different ways and went over the main.lua again and thr doesnt appear to be a way to remove the parent. Glad i can get the index(position) to change. I have tried
op = getAddressList().getMemoryRecordByID(4)
yep = getAddressList().getMemoryRecordByID(5)
op.appendToEntry(yep.Parent)
_________________
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Tue Jun 28, 2016 6:55 pm Post subject: |
|
|
I couldn't find a way.
|
|
Back to top |
|
|
akumakuja28 Master Cheater Reputation: 16
Joined: 28 Jun 2015 Posts: 432
|
Posted: Tue Jun 28, 2016 9:10 pm Post subject: |
|
|
Zanzer wrote: | I couldn't find a way. |
Thanks for trying Zanzer, appreciate it.
_________________
|
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Tue Jun 28, 2016 9:27 pm Post subject: |
|
|
mr.Destroy() or move under a dummy parent, mr.appendToEntry(dummyParent) ?
btw, here a mr sorting function:
Code: | function mrsort(parent,cmp,...)-- sort under a parent
if cmp==nil then cmp = function(a,b)return a.Description:lower()<b.Description:lower() end end
local index,al = {},GetAddressList()
for i=1,parent.Count do index[i]=parent[i-1].ID end
table.sort(index,function(ia,ib)return cmp(al.getMemoryRecordByID(ia),al.getMemoryRecordByID(ib)) end)
for i=1,#index do
local mr = al.getMemoryRecordByID(index[i])
mr.appendToEntry(parent)
local nxtCmp = ...
if mr.Count>0 and nil~=nxtCmp then-- recursive to next level
if true==nxtCmp then-- repeatly use previous cmp
mrsort(mr,cmp,true)
elseif type(nxtCmp)=='function' then
mrsort(mr,...)
end
end
end
end
-- sample cmp function
mrsort(root,function(a,b)
-- sort by offset or address, grouped?
local at,bt = a.Type==vtAutoAssembler,b.Type==vtAutoAssembler
if at or bt then -- script type have no meaningful Address
if at==bt then
return a.Description:lower()<b.Description:lower()
else
return at or not bt -- for moving up script type
end
end
local ao,ax = a.Address:match("^(.-)([%+%-]%x+)$")
local bo,bx = b.Address:match("^(.-)([%+%-]%x+)$")
if ax==nil or bx==nil then
ao,ax = a.Address:match("^(.-)([%+%-]?%x+)[^%x]*$")
bo,bx = b.Address:match("^(.-)([%+%-]?%x+)[^%x]*$")
end
ax,bx = tonumber(ax or '',16),tonumber(bx or '',16)
if ax~=nil and bx~=nil then
if ao==bo then
if ax~=bx then
return ax<bx
end
else
return ao<bo
end
end
return a.Index<b.Index
end)
-- recursive usage
mrsort(root,nil,true) -- recursive sort by case-insensitive description (default cmp)
mrsort(root,cmp1,cmp2) -- sort 2 level, 1st by cmp1 then its children with cmp2
|
bye~
_________________
- Retarded. |
|
Back to top |
|
|
|