From 23022dc88c5a2df0cb3415720a8f3a8c479d6b92 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 28 Apr 2018 15:20:48 -0700 Subject: Re-added (..), which is necessary for long expressions as first arg to an action. --- nomsu.lua | 64 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 31 deletions(-) (limited to 'nomsu.lua') diff --git a/nomsu.lua b/nomsu.lua index 0730724..242d7a6 100644 --- a/nomsu.lua +++ b/nomsu.lua @@ -1,4 +1,3 @@ -local lfs = require('lfs') local re = require('re') local lpeg = require('lpeg') lpeg.setmaxstack(10000) @@ -41,7 +40,7 @@ FILE_CACHE = setmetatable({ }, { if not (file) then return nil end - local contents = file:read("a"):sub(1, -2) + local contents = file:read("a"):sub(1, -1) file:close() self[filename] = contents return contents @@ -362,41 +361,44 @@ do end return self:run_lua(lua) end, - run_file = function(self, filename, compile_fn) + run_file = function(self, path, compile_fn) if compile_fn == nil then compile_fn = nil end - local file_attributes = assert(lfs.attributes(filename), "File not found: " .. tostring(filename)) - if file_attributes.mode == "directory" then - for short_filename in lfs.dir(filename) do - local full_filename = filename .. '/' .. short_filename - local attr = lfs.attributes(full_filename) - if attr.mode ~= "directory" and short_filename:match(".*%.nom") then - self:run_file(full_filename, compile_fn) - end - end - return - end - if filename:match(".*%.lua") then - local file = assert(FILE_CACHE[filename], "Could not find file: " .. tostring(filename)) - return self:run_lua(Lua(Source(filename), file)) - end - if filename:match(".*%.nom") then - if not self.skip_precompiled then - local lua_filename = filename:gsub("%.nom$", ".lua") - local file = FILE_CACHE[lua_filename] - if file then - return self:run_lua(Lua(Source(filename), file)) + local ret = nil + for filename in io.popen("find " .. path .. " -type f"):lines() do + local _continue_0 = false + repeat + if filename:match("%.lua$") then + local file = assert(FILE_CACHE[filename], "Could not find file: " .. tostring(filename)) + ret = self:run_lua(Lua(Source(filename), file)) + elseif filename:match("%.nom$") then + if not self.skip_precompiled then + local lua_filename = filename:gsub("%.nom$", ".lua") + local file = FILE_CACHE[lua_filename] + if file then + ret = self:run_lua(Lua(Source(filename), file)) + _continue_0 = true + break + end + end + local file = file or FILE_CACHE[filename] + if not file then + error("File does not exist: " .. tostring(filename), 0) + end + ret = self:run(Nomsu(Source(filename), file), compile_fn) + _continue_0 = true + break + else + error("Invalid filetype for " .. tostring(filename), 0) end + _continue_0 = true + until true + if not _continue_0 then + break end - local file = file or FILE_CACHE[filename] - if not file then - error("File does not exist: " .. tostring(filename), 0) - end - return self:run(Nomsu(Source(filename), file), compile_fn) - else - return error("Invalid filetype for " .. tostring(filename), 0) end + return ret end, use_file = function(self, filename) local loaded = self.environment.LOADED -- cgit v1.2.3