WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Problem Loading into game. (https://www.wowinterface.com/forums/showthread.php?t=49283)

TULOA 05-10-14 10:00 PM

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?

semlar 05-10-14 10:05 PM

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.

TULOA 05-10-14 10:06 PM

Quote:

Originally Posted by TULOA (Post 292703)
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?

TULOA 05-10-14 10:09 PM

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

TULOA 05-10-14 10:50 PM

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


semlar 05-10-14 11:35 PM

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

TULOA 05-10-14 11:54 PM

Quote:

Originally Posted by semlar (Post 292708)
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.

semlar 05-11-14 12:13 AM

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.

TULOA 05-11-14 12:20 AM

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.

semlar 05-11-14 12:36 AM

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."

TULOA 05-11-14 01:06 AM

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.

Lombra 05-11-14 05:10 AM

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.

TULOA 05-11-14 09:38 AM

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.


All times are GMT -6. The time now is 03:41 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI