diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-09-19 00:58:19 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-09-19 00:58:19 -0700 |
commit | 2e433b773ab122caf261738e553d58462e32fac3 (patch) | |
tree | 716c3a3c6e0c6517a77e2fd732851fa17e956770 /source_file.lua | |
parent | c57f2c812b5ccc1d73235167aa5a916a249ba7fb (diff) | |
parent | 1c49f74c8d4ae7e2b3657e1eb11bb4d36063e50d (diff) | |
download | view.love-2e433b773ab122caf261738e553d58462e32fac3.tar.gz |
Merge text.love
Diffstat (limited to 'source_file.lua')
-rw-r--r-- | source_file.lua | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/source_file.lua b/source_file.lua index 8dd8832..54624b9 100644 --- a/source_file.lua +++ b/source_file.lua @@ -216,3 +216,39 @@ end function is_relative_path(path) return not is_absolute_path(path) end + +function dirname(path) + local os_path_separator = package.config:sub(1,1) + if os_path_separator == '/' then + -- POSIX systems permit backslashes in filenames + return path:match('.*/') or './' + elseif os_path_separator == '\\' then + return path:match('.*[/\\]') or './' + else + error('What OS is this? LÖVE reports that the path separator is "'..os_path_separator..'"') + end +end + +function test_dirname() + check_eq(dirname('a/b'), 'a/', 'F - test_dirname') + check_eq(dirname('x'), './', 'F - test_dirname/current') +end + +function basename(path) + local os_path_separator = package.config:sub(1,1) + if os_path_separator == '/' then + -- POSIX systems permit backslashes in filenames + return string.gsub(path, ".*/(.*)", "%1") + elseif os_path_separator == '\\' then + return string.gsub(path, ".*[/\\](.*)", "%1") + else + error('What OS is this? LÖVE reports that the path separator is "'..os_path_separator..'"') + end +end + +function empty(h) + for _,_ in pairs(h) do + return false + end + return true +end |