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
05-11-14, 12:13 AM   #8
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
I suppose a file path could be mistaken for a url, but you could either strip chat hyperlinks out of the text first or do some post-processing on the suspected urls to make sure they conform with what you want.
  Reply With Quote
05-11-14, 12:20 AM   #9
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Well so far I appreciate your help... It got me seeing a few things.

I have it working on basic URLs and now my issue is that any address with the <word>-<word>.com for example or use the one above for like enjin links arent working. It grabs the ending <word>.com and i need it to grab all of it.

The problem is that my complete correct code doesnt work in WoW for some reason.
  Reply With Quote
05-11-14, 12:36 AM   #10
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
I should probably mention that you aren't using character classes correctly.

Something like "[www%.]" is the same as "[.w]" and matches a single character contained in the brackets, in this case either a "w" or a "." but not the literal string "www."
  Reply With Quote
05-11-14, 01:06 AM   #11
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Thats ok I think im just gonna go the long hard route. I will come back to regex later when I better understand it. Until then I am using my much bigger code that I know worked.
  Reply With Quote
05-11-14, 05:10 AM   #12
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Lua doesn't actually use regex, but a different thing described here:
http://wowpedia.org/Pattern_matching
http://www.lua.org/pil/20.1.html

Personally I just use this pattern for URL matching:
Code:
%l+://%S+
Should work for most situations where people are sensible enough to type out full links and separate it with spaces. I think this is also how it works on most forums and instant messengers and stuff. (they probably validate the protocol sometimes, I guess) I can see why one would want to quickly type out a address manually without using the whole format and have it get linkified, but for me at least, it wouldn't be worth the extra logic required.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
05-11-14, 09:38 AM   #13
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Yea I got help on StackOverflow and got a wonderful solution and I am sticking with it. I know of the difference of Luas Pattern matching vs Regex but dont 100% know how to deploy it. I am still learning.

I started LUA recently so I will get it over time though.
  Reply With Quote

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

Thread Tools
Display Modes

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