chiliui icon indicating copy to clipboard operation
chiliui copied to clipboard

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

Open Tumulten opened this issue 10 years ago • 0 comments

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

Tumulten avatar Mar 05 '14 22:03 Tumulten