Search DlistView, infinite loop error

Two questions here with DlistView. One, I have a long list of data I want to load, none of it is repeating, and after about… 300 or so entries, it gives me an infinite loop error. Is there any way to stop this? Also, I have the data loading into a table so it doesn’t have to keep grabbing the file and whatnot. I made a search function using this code:

[LUA]
function SearchList(Value)
DlistWindow:Clear()
for k,v in pairs(DlistList) do
if string.find(string.lower(v),string.lower(Value)) != nil then
local Explode = string.Explode("|", v)
local Explode2 = string.Explode("-",Explode[1])
local ExplodeT = string.Explode(":",Explode[2])
if(Explode and table.Count(Explode) >1) then
local Name = string.Trim(Explode2[2])
local Steam = string.Trim(Explode2[1])
local Unique = string.Trim(ExplodeT[1])
local Point = string.Trim(ExplodeT[2])

				if(Name != "" and Steam != "" and Unique != "" and Point != "") then
					DlistWindow:AddLine(Name,Steam,Unique,Point)
					DlistWindow:SortByColumn(1)
				end
			end
end
end

end[/LUA]

I changed some stuff in the code, but this is called every time I type a letter in the text box, and this starts to delay a LOT when there’s a lot of entries. Is there a better way of doing this?

[lua]local h_a, h_b, h_c = debug.gethook()
debug.sethook()
//code here
debug.sethook(h_a, h_b, h_c) [/lua] This prevents infinite loop errors (thanks Deco).

That worked. Thanks, and does nobody know how to make a less-laggy search? That’s all I need to figure out before I can add the script to my server =[

Super bump on the searching question. I want it to essentially hide the rows that don’t have the value entered in the text box.

Just keep the results in a table and when the text in the box changes, refill the DListView from the table.

It’s not that it doesn’t work, It’s that it gets laggy at around 500 entries. Running a for loop on the table. Or are you suggesting I take the first letter typed into a table, and keep searching from that temporary table? The only issue I see with that is when they backspace.

What kind of data is in the listview?

You could save a temporary table for each. Would be inefficiant but would work.

It’s actually for the music player I’ve been coding. I’ll be releasing it soon, but I want the search function to work first. So they’ll be searching through the artist and the name of the song.

Edit: I assume I’ll have to end up making a custom DListView for this. With a hide function or something, so it’s not clearing the list, and readding.

I’m pretty sure that’s equally lagging, since you’re still looping through all the items.

[LUA]
function SearchList(Value)
MusicWindow:Clear()
Prawr = 0
for k,v in pairs(SongList) do
if string.find(string.lower(v),string.lower(Value)) != nil then
local Explode = string.Explode("|", v)
local Explode2 = string.Explode("-",Explode[1])
local ExplodeT = string.Explode(":",Explode[2])
if(Explode and table.Count(Explode) >1) then
local Name = string.Trim(Explode2[2])
local Artist = string.Trim(Explode2[1])
local Min = string.Trim(ExplodeT[1])
local Sec = string.Trim(ExplodeT[2])
local Name = string.gsub(Name,".mp3","")
if(Name != “” and Artist != “” and Min != “” and Sec != “”) then
MusicWindow:AddLine(Name,Artist,Min…":"…Sec)
MusicWindow:SortByColumn(2)
end
end
end
end
end
[/LUA]

This is the code I used. Keep in mind that I coded this quite some time ago. But I really want to get this working now.

Try formatting the table numerically ( if its not already ) and using ipairs. Its much faster than pairs. Another thing that might help would be to cut back on using string.Explode so much. Locally defining globals that you’re using may also help.

[lua]
// Add this to the top of your script.
// Globals are slower to call than locals
local string = string
local table = table //etc

// Format the table like so if it isn’t already.
t = { “a”, “b”, “c” }

// Use ipairs
for _, v in ipairs( t ) do

end
[/lua]

[lua]
local SongTable = {}
local name, artist, min, sec
for k, song in pairs(SongList) do
name, artist, min, sec = string.match(song, “^%s*(.-)%.?m?p?3?%s*%-%s*(.-)%s*|%s*(%d+)%s*:%s*(%d+)%s*$”)
if name then
SongTable[string.lower(name…" “…artist)] = {
name = name,
artist = artist,
min = min,
sec = sec,
length_str = min…”:"…sec
length = min*60+sec,
}
end
end

function SearchList(str)
str = string.lower(str)
for search_str, song in pairs(SongTable) do
if string.find(search_str, str, nil, true) then
MusicWindow:AddLine(song.name, song.artist, song.length_str)
end
end
MusicWindow:SortByColumn(2)
end
[/lua]

Should work. I tested the pattern:


> song = "Holy shit I'm on _FIRE_!.mp3 - The Someones | 3 : 59  "
> = string.match(song, "^%s*(.-)%.?m?p?3?%s*%-%s*(.-)%s*|%s*(%d+)%s*:%s*(%d+)%s*
$")
Holy shit I'm on _FIRE_!        The Someones    3       59
>

Have fun!

Honestly deco, I’m pretty confused by that. I’m clueless with string.match, if I could possibly pm you with my code and you could replace that with what I have, I’d be so grateful lol. If not, I’ll figure it out. Thanks for the help guys :smiley: