Thread Tools Display Modes
05-10-14, 10:00 PM   #1
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Problem Loading into game.

With my code changed to a repl.it tested URL Detection code the following function seems to be causing WoW to not get past the loading screen:

Code:
function URLFind(str)
    local _results = {}
    local _x = 0
    local isFound = false
    while _x <= #str do
        
        url = ""
        pos = 0
        url =  string.match(str, "https?://[%w-_%.%?%.:/%+=&]+", _x)
        pos = string.find(str, "https?://[%w-_%.%?%.:/%+=&]+", _x)
        --print(url)
        if url == nil then
            --Didnt find fully matched URL so lets try a shorter one.
            --url = string.match(str, "[^\.][^\s].*\.\.".."com".."[/]*\s?", _x)
            url = string.match(str, "[%w-_%.%?%.:/%+=&]+", _x)
            pos = string.find(str, "[%w-_%.%?%.:/%+=&]+", _x)
            
        end
        if url ~= nil then
            if url:sub(1,1) == " " then
                url = url:sub(2, #str)
                pos = pos + 1
            end
            tinsert(_results, {url, pos})
            --print(url.." | "..pos)
            _x = pos + #url
            --print("Adding. Next X: ".._x)
			isFound = true
        end
    end
    return isFound, _results
end
Anyone have an idea of why it would be doing that?
  Reply With Quote
05-10-14, 10:05 PM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You have an infinite loop, likely caused by "url" being nil and continuing to be nil.

I'm not sure what your goal is, but this is insane for a url detection function.

Last edited by semlar : 05-10-14 at 10:08 PM.
  Reply With Quote
05-10-14, 10:06 PM   #3
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Originally Posted by TULOA View Post
With my code changed to a repl.it tested URL Detection code the following function seems to be causing WoW to not get past the loading screen:

Code:
function URLFind(str)
    local _results = {}
    local _x = 0
    local isFound = false
    while _x <= #str do
        
        url = ""
        pos = 0
        url =  string.match(str, "https?://[%w-_%.%?%.:/%+=&]+", _x)
        pos = string.find(str, "https?://[%w-_%.%?%.:/%+=&]+", _x)
        --print(url)
        if url == nil then
            --Didnt find fully matched URL so lets try a shorter one.
            --url = string.match(str, "[^\.][^\s].*\.\.".."com".."[/]*\s?", _x)
            url = string.match(str, "[%w-_%.%?%.:/%+=&]+", _x)
            pos = string.find(str, "[%w-_%.%?%.:/%+=&]+", _x)
            
        end
        if url ~= nil then
            if url:sub(1,1) == " " then
                url = url:sub(2, #str)
                pos = pos + 1
            end
            tinsert(_results, {url, pos})
            --print(url.." | "..pos)
            _x = pos + #url
            --print("Adding. Next X: ".._x)
			isFound = true
        end
    end
    return isFound, _results
end
Anyone have an idea of why it would be doing that?
Edit:Hangon... Maybe inf. loop?
  Reply With Quote
05-10-14, 10:09 PM   #4
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Im going to see soon. I think its the While loop. But it still seems to be hanging.

Edit: Sigh... It was an infinite loop... It was because I converted a For Loop.

Do you have a better way to detect the following URL types?:
http://www.test.com/folder/subfolder/
www.test.com/folder/subfolder/
test.com/folder/subfolder/
test.com

Last edited by TULOA : 05-10-14 at 10:14 PM.
  Reply With Quote
05-10-14, 10:50 PM   #5
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Ok I got it... I dont understand how but it was caused by a combo of the infinite loop and the regex match pattern. I am new to it and didnt realise normal regex's from other luas wouldnt neccesarily work.

Below is my modified working code.

Code:
function URLFind(str)
    local _results = {}
    local _x = 0
    local isFound = false
    while _x <= #str do
        
        url = ""
        pos = 0
        url = string.match(str, "[https?://]*[www%.]*%w+%.%w+[%w+/]+", _x)
         pos = string.find(str, "[https?://]*[www%.]*%w+%.%w+[%w+/]+", _x)
        --print(url)
        
        if url ~= nil then
            if url:sub(1,1) == " " then
                url = url:sub(2, #str)
                pos = pos + 1
            end
            table.insert(_results, {url, pos})
            --print(url.." | "..pos)
            _x = pos + #url
            --print("Adding. Next X: ".._x)
			isFound = true
        end
		
		_x = _x + 1
    end
	
    return isFound, _results
end

Last edited by TULOA : 05-10-14 at 11:34 PM.
  Reply With Quote
05-10-14, 11:35 PM   #6
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Given how broad your definition of a url is, you could probably try something like this..
Lua Code:
  1. for url in str:gmatch('[.%w-_:/]+%.%a%a+%f[%A]%S*') do print(url) end
  Reply With Quote
05-10-14, 11:54 PM   #7
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Originally Posted by semlar View Post
Given how broad your definition of a url is, you could probably try something like this..
Lua Code:
  1. for url in str:gmatch('[.%w-_:/]+%.%a%a+%f[%A]%S*') do print(url) end
now how does that get along with the hidden links for icons and such?

I came up with this code:
url = string.match(str, "[https?://]*[www%.]*[%w+]*[%w+%-]?[%w+%.]+%w+%"..URIs[cURL].."[/w%w+/]+", _x)
pos = string.find(str, "[https?://]*[www%.]*[%w+]*[%w+%-]?[%w+%.]+%w+%"..URIs[cURL].."[/%w+/]+", _x)

But for some reason it wont work in WoW. It works on Repl.it for lua to find an example address of www.cc-test.test.com

It gets stuck on the loading screen. I return my function and it loads but will not detect that address. Or rather just part of it.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Problem Loading into game.


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off