aboutsummaryrefslogtreecommitdiff
path: root/files.moon
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-11-08 15:23:22 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-11-08 15:24:15 -0800
commit652c29bdef1f0991cc13bef59d6dc78b657ae9a4 (patch)
tree8e335399e77b1893657b9fa985db0738034daac3 /files.moon
parent1f3660f393c1a17988a15b89f18686b28e51a9e7 (diff)
Major overhaul, splitting nomsu_compiler into nomsu_environment,
nomsu_compiler, and nomsu_decompiler. Also added comprehensions.
Diffstat (limited to 'files.moon')
-rw-r--r--files.moon10
1 files changed, 8 insertions, 2 deletions
diff --git a/files.moon b/files.moon
index 738c5f8..ca50290 100644
--- a/files.moon
+++ b/files.moon
@@ -16,16 +16,22 @@ _FILE_CACHE = setmetatable {}, __index:_SPOOFED_FILES
_BROWSE_CACHE = {}
-- Create a fake file and put it in the cache
+_anon_number = 0
Files.spoof = (filename, contents)->
+ if not contents
+ filename, contents = "<anonymous file ##{_anon_number}>", filename
+ _anon_number += 1
_SPOOFED_FILES[filename] = contents
- return contents
+ return filename
-- Read a file's contents (searching first locally, then in the nomsupath)
Files.read = (filename)->
if file_contents = _FILE_CACHE[filename]
return file_contents
if filename == 'stdin'
- return Files.spoof('stdin', io.read('*a'))
+ contents = io.read('*a')
+ Files.spoof('stdin', contents)
+ return contents
file = io.open(filename)
return nil unless file
contents = file\read("*a")