diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-09-11 08:36:33 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-09-11 08:36:33 -0700 |
commit | f2c8f06819658084ec2f585d0721af345fb9af7d (patch) | |
tree | 0f5d7a0b2c1b675a321076c6e1a1ef6d1a0f597e | |
parent | b23269f3e03b69e914f8f6311e9c873508619949 (diff) | |
parent | 9a41c7c176aa571f5270747f690e9b4a37e27529 (diff) | |
download | view.love-f2c8f06819658084ec2f585d0721af345fb9af7d.tar.gz |
Merge lines.love
-rw-r--r-- | file.lua | 17 | ||||
-rw-r--r-- | run.lua | 5 | ||||
-rw-r--r-- | source.lua | 5 | ||||
-rw-r--r-- | source_file.lua | 17 |
4 files changed, 38 insertions, 6 deletions
diff --git a/file.lua b/file.lua index 98311da..12bd5a1 100644 --- a/file.lua +++ b/file.lua @@ -58,3 +58,20 @@ function load_array(a) end return result end + +function is_absolute_path(path) + local os_path_separator = package.config:sub(1,1) + if os_path_separator == '/' then + -- POSIX systems permit backslashes in filenames + return path:sub(1,1) == '/' + elseif os_path_separator == '\\' then + local f = path:sub(1,1) + return f == '/' or f == '\\' + else + error('What OS is this? LÖVE reports that the path separator is "'..os_path_separator..'"') + end +end + +function is_relative_path(path) + return not is_absolute_path(path) +end diff --git a/run.lua b/run.lua index 16857f9..e395978 100644 --- a/run.lua +++ b/run.lua @@ -136,9 +136,8 @@ function run.settings() Settings.x, Settings.y, Settings.displayindex = love.window.getPosition() end local filename = Editor_state.filename - local os_path_separator = package.config:sub(1,1) - if filename:sub(1,1) ~= os_path_separator then - filename = love.filesystem.getWorkingDirectory()..os_path_separator..filename + if is_relative_path(filename) then + filename = love.filesystem.getWorkingDirectory()..'/'..filename -- '/' should work even on Windows end return { x=Settings.x, y=Settings.y, displayindex=Settings.displayindex, diff --git a/source.lua b/source.lua index f4527ca..843a244 100644 --- a/source.lua +++ b/source.lua @@ -257,9 +257,8 @@ function source.settings() Settings.source.x, Settings.source.y, Settings.source.displayindex = love.window.getPosition() end local filename = Editor_state.filename - local os_path_separator = package.config:sub(1,1) - if filename:sub(1,1) ~= os_path_separator then - filename = love.filesystem.getWorkingDirectory()..os_path_separator..filename + if is_relative_path(filename) then + filename = love.filesystem.getWorkingDirectory()..'/'..filename -- '/' should work even on Windows end --? print('saving source settings', Settings.source.x, Settings.source.y, Settings.source.displayindex) return { diff --git a/source_file.lua b/source_file.lua index 6552667..8dd8832 100644 --- a/source_file.lua +++ b/source_file.lua @@ -199,3 +199,20 @@ function load_drawing_from_array(iter, a, i) end return i, drawing end + +function is_absolute_path(path) + local os_path_separator = package.config:sub(1,1) + if os_path_separator == '/' then + -- POSIX systems permit backslashes in filenames + return path:sub(1,1) == '/' + elseif os_path_separator == '\\' then + local f = path:sub(1,1) + return f == '/' or f == '\\' + else + error('What OS is this? LÖVE reports that the path separator is "'..os_path_separator..'"') + end +end + +function is_relative_path(path) + return not is_absolute_path(path) +end |