more correct absolute path detection
This commit is contained in:
parent
511db8cffd
commit
9a41c7c176
17
file.lua
17
file.lua
|
@ -180,3 +180,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
|
||||
|
|
5
run.lua
5
run.lua
|
@ -141,9 +141,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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue