aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--files.lua21
-rw-r--r--files.moon10
-rw-r--r--lib/os.nom6
3 files changed, 11 insertions, 26 deletions
diff --git a/files.lua b/files.lua
index 3f80cfb..d346945 100644
--- a/files.lua
+++ b/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
- do
- local file_contents = _FILE_CACHE[filename]
- if file_contents then
- return file_contents or nil
- end
+Files.read = function(filename)
+ do
+ 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
diff --git a/files.moon b/files.moon
index 477e51e..b277120 100644
--- a/files.moon
+++ b/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
diff --git a/lib/os.nom b/lib/os.nom
index 3445e8d..916f18c 100644
--- a/lib/os.nom
+++ b/lib/os.nom
@@ -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