Removed automatic file caching.
This commit is contained in:
parent
1d2bd858fd
commit
1f47f1aa28
19
files.lua
19
files.lua
@ -20,9 +20,6 @@ run_cmd = function(cmd)
|
||||
return lines
|
||||
end
|
||||
local _SPOOFED_FILES = { }
|
||||
local _FILE_CACHE = setmetatable({ }, {
|
||||
__index = _SPOOFED_FILES
|
||||
})
|
||||
local _BROWSE_CACHE = { }
|
||||
local _anon_number = 0
|
||||
Files.spoof = function(filename, contents)
|
||||
@ -33,16 +30,11 @@ Files.spoof = function(filename, contents)
|
||||
_SPOOFED_FILES[filename] = contents
|
||||
return filename
|
||||
end
|
||||
Files.read = function(filename, skip_cache)
|
||||
if skip_cache == nil then
|
||||
skip_cache = nil
|
||||
end
|
||||
if not (skip_cache) then
|
||||
Files.read = function(filename)
|
||||
do
|
||||
local file_contents = _FILE_CACHE[filename]
|
||||
if file_contents then
|
||||
return file_contents or nil
|
||||
end
|
||||
local contents = _SPOOFED_FILES[filename]
|
||||
if contents then
|
||||
return contents
|
||||
end
|
||||
end
|
||||
if filename == 'stdin' or filename == '-' then
|
||||
@ -57,9 +49,6 @@ Files.read = function(filename, skip_cache)
|
||||
end
|
||||
local contents = file:read("*a")
|
||||
file:close()
|
||||
if not (skip_cache) then
|
||||
_FILE_CACHE[filename] = contents
|
||||
end
|
||||
return contents or nil
|
||||
end
|
||||
local match, gsub
|
||||
|
10
files.moon
10
files.moon
@ -10,7 +10,6 @@ run_cmd = (cmd)->
|
||||
return lines
|
||||
|
||||
_SPOOFED_FILES = {}
|
||||
_FILE_CACHE = setmetatable {}, __index:_SPOOFED_FILES
|
||||
_BROWSE_CACHE = {}
|
||||
|
||||
-- Create a fake file and put it in the cache
|
||||
@ -23,10 +22,9 @@ Files.spoof = (filename, contents)->
|
||||
return filename
|
||||
|
||||
-- Read a file's contents
|
||||
Files.read = (filename, skip_cache=nil)->
|
||||
unless skip_cache
|
||||
if file_contents = _FILE_CACHE[filename]
|
||||
return file_contents or nil
|
||||
Files.read = (filename)->
|
||||
if contents = _SPOOFED_FILES[filename]
|
||||
return contents
|
||||
if filename == 'stdin' or filename == '-'
|
||||
contents = io.read('*a')
|
||||
Files.spoof('stdin', contents)
|
||||
@ -36,8 +34,6 @@ Files.read = (filename, skip_cache=nil)->
|
||||
return nil unless file
|
||||
contents = file\read("*a")
|
||||
file\close!
|
||||
unless skip_cache
|
||||
_FILE_CACHE[filename] = contents
|
||||
return contents or nil
|
||||
|
||||
{:match, :gsub} = string
|
||||
|
@ -30,7 +30,7 @@ external $(sh> $) = $os.execute
|
||||
test:
|
||||
read file "lib/os.nom"
|
||||
|
||||
externally (read file $filename) means (=lua "Files.read(\$filename, true)")
|
||||
external $(read file $filename) = $Files.read
|
||||
externally [
|
||||
write to file $filename $text, to file $filename write $text
|
||||
write $text to file $filename
|
||||
@ -54,5 +54,5 @@ externally (source lines of $tree) means:
|
||||
..: add ($file, line $)
|
||||
], joined with "\n"
|
||||
|
||||
externally (spoof file $text) means ($Files.spoof $text)
|
||||
externally (spoof file $filename = $text) means ($Files.spoof $filename $text)
|
||||
external $(spoof file $text) = $Files.spoof
|
||||
external $(spoof file $filename = $text) = $Files.spoof
|
||||
|
Loading…
Reference in New Issue
Block a user