Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api_chili.lua GetDirectory returns the path with the file in it #22

Open
Tumulten opened this issue Mar 5, 2014 · 0 comments
Open

api_chili.lua GetDirectory returns the path with the file in it #22

Tumulten opened this issue Mar 5, 2014 · 0 comments

Comments

@Tumulten
Copy link

Tumulten commented Mar 5, 2014

GetDirectory only works if source path is for example "LuaUI/Widgets/"
and not if it is for example "LuaUI\Widgets"
Not sure about Linux but on Windows debug and debug.getinfo(1).source will have backslash ( \ )

local source = debug and debug.getinfo(1).source
local DIR = GetDirectory(source)
local function GetDirectory(filepath)
    return filepath and filepath:gsub("(.*/)(.*)", "%1") 
end

Possible fix:

local function GetDirectory(filepath)
    local split,isFSlash =  filepath:gsub("(.*/)(.*)", "%2")
    if isFSlash == 0 then
        return filepath:gsub("(.*\\)(.*)", "%1")
    end
    return filepath:gsub(split,"")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant