Merge text.love
This commit is contained in:
commit
b407a2e4b8
57
app.lua
57
app.lua
|
@ -256,17 +256,6 @@ end
|
|||
-- various Lua and LÖVE helpers, tests will be able to check the results of
|
||||
-- file operations inside the App.filesystem table.
|
||||
|
||||
function App.open_for_writing(filename)
|
||||
App.filesystem[filename] = ''
|
||||
return {
|
||||
write = function(self, s)
|
||||
App.filesystem[filename] = App.filesystem[filename]..s
|
||||
end,
|
||||
close = function(self)
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
function App.open_for_reading(filename)
|
||||
if App.filesystem[filename] then
|
||||
return {
|
||||
|
@ -282,6 +271,26 @@ function App.open_for_reading(filename)
|
|||
end
|
||||
end
|
||||
|
||||
function App.read_file(filename)
|
||||
return App.filesystem[filename]
|
||||
end
|
||||
|
||||
function App.open_for_writing(filename)
|
||||
App.filesystem[filename] = ''
|
||||
return {
|
||||
write = function(self, s)
|
||||
App.filesystem[filename] = App.filesystem[filename]..s
|
||||
end,
|
||||
close = function(self)
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
function App.write_file(filename, contents)
|
||||
App.filesystem[filename] = contents
|
||||
return --[[status]] true
|
||||
end
|
||||
|
||||
function App.mkdir(dirname)
|
||||
-- nothing in test mode
|
||||
end
|
||||
|
@ -418,6 +427,19 @@ function App.disable_tests()
|
|||
return ok, err
|
||||
end
|
||||
end
|
||||
App.read_file =
|
||||
function(path)
|
||||
if not is_absolute_path(path) then
|
||||
return --[[status]] false, 'Please use an unambiguous absolute path.'
|
||||
end
|
||||
local f, err = App.open_for_reading(path)
|
||||
if err then
|
||||
return --[[status]] false, err
|
||||
end
|
||||
local contents = f:read()
|
||||
f:close()
|
||||
return contents
|
||||
end
|
||||
App.open_for_writing =
|
||||
function(filename)
|
||||
local result = nativefs.newFile(filename)
|
||||
|
@ -428,6 +450,19 @@ function App.disable_tests()
|
|||
return ok, err
|
||||
end
|
||||
end
|
||||
App.write_file =
|
||||
function(path, contents)
|
||||
if not is_absolute_path(path) then
|
||||
return --[[status]] false, 'Please use an unambiguous absolute path.'
|
||||
end
|
||||
local f, err = App.open_for_writing(path)
|
||||
if err then
|
||||
return --[[status]] false, err
|
||||
end
|
||||
f:write(contents)
|
||||
f:close()
|
||||
return --[[status]] true
|
||||
end
|
||||
App.files = nativefs.getDirectoryItems
|
||||
App.mkdir = nativefs.createDirectory
|
||||
App.remove = nativefs.remove
|
||||
|
|
Loading…
Reference in New Issue