Skip to content

Instantly share code, notes, and snippets.

@yann2192
Created July 10, 2014 09:58
Show Gist options
  • Save yann2192/1f422c8a8814deb594fd to your computer and use it in GitHub Desktop.
Save yann2192/1f422c8a8814deb594fd to your computer and use it in GitHub Desktop.
-- Copyright (c) 2013 The Chromium Authors. All rights reserved.
-- Use of this source code is governed by a BSD-style license that can be
-- found in the LICENSE file.
--- Path manipulation utility functions.
local path = {}
function path.dirname(filename)
while true do
if filename == "" or string.sub(filename, -1) == "/" then
break
end
filename = string.sub(filename, 1, -2)
end
if filename == "" then
filename = "."
end
return filename
end
function path.join(dirname, basename)
if string.sub(dirname, -1) ~= "/" then
dirname = dirname .. "/"
end
return dirname .. basename
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment