PtokaX forum

Development Section => Your Developing Problems => Topic started by: NightLitch on 10 December, 2003, 22:44:26

Title: How do I sort this sort of table...
Post by: NightLitch on 10 December, 2003, 22:44:26
Accociative I think... (can't spell)

How do I sort it...


for vRANGE,vNET in Table do
local _,_,RANGE1,RANGE2 = strfind(vRANGE, "(%S+)-(%S+)")
curUser:sendmessage(BOTNAME," Range: "..RANGE1.." - "..RANGE2.."\t\tNetwork: "..vNET)
end

plz help me...

/NL
Title:
Post by: plop on 10 December, 2003, 23:52:55
not 2 sure but this might work.
local temp = {}
for vRANGE,vNET in Table do
   tinsert(temp, vRANGE)
end
sort(temp)
for i=1,getn(temp) do
local _,_,RANGE1,RANGE2 = strfind(temp[i], "(%S+)-(%S+)")
curUser:sendmessage(BOTNAME," Range: "..RANGE1.." - "..RANGE2.."\t\tNetwork: "..Table[temp[i]])
end

plop
Title:
Post by: c h i l l a on 11 December, 2003, 00:24:51
nightlitch... it depends if you have IP s to sort then you will need to use the sort func of the logger.
if you sort it with LUA sort function...  tings could get mixed up  like  230.0.0.0  above 32.0.0.0  but if you sort it by name then plops idea is the one, in any case you will need to first creat a non associative table  like plop did.

tinsert(temp,value)

the sort func of the logger,  computes the IP and compares it with the next one

ends up something like this

sort(table, function(a,b) return(Compute(a) < Compute(b)) end)

you need the the compute function.