diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-02-02 13:59:58 -0800 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-02-02 14:01:06 -0800 |
| commit | 513c721198b2256235a95c98d161ab1bb51e6671 (patch) | |
| tree | e5b57852739b3e80769cfb2bc3a1713cf4bb1cc7 /nomsu.lua | |
| parent | 75c6755d326097eb5b725dee46e7fb6377b01c88 (diff) | |
Updated 'use %' to support directories, and cleaned up action_metadata a
tiny bit.
Diffstat (limited to 'nomsu.lua')
| -rw-r--r-- | nomsu.lua | 29 |
1 files changed, 21 insertions, 8 deletions
@@ -1,3 +1,4 @@ +local lfs = require('lfs') local re = require('re') local lpeg = require('lpeg') local utils = require('utils') @@ -232,7 +233,7 @@ do arg_orders[stub] = arg_positions end end - self.action_metadata[fn] = { + self.environment.ACTION_METADATA[fn] = { fn = fn, source = source, aliases = stubs, @@ -243,7 +244,7 @@ do end, define_compile_action = function(self, signature, source, fn, src) self:define_action(signature, source, fn) - self.action_metadata[fn].compile_time = true + self.environment.ACTION_METADATA[fn].compile_time = true end, serialize_defs = function(self, scope, after) if scope == nil then @@ -406,10 +407,23 @@ do end, require_file = function(self, filename) local loaded = self.environment.LOADED - if not loaded[filename] then - loaded[filename] = self:run_file(filename) or true + local file_attributes = lfs.attributes(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 + if not loaded[full_filename] then + loaded[full_filename] = self:run_file(full_filename) or true + end + end + end + else + if not loaded[filename] then + loaded[filename] = self:run_file(filename) or true + end + return loaded[filename] end - return loaded[filename] end, run_lua = function(self, lua_code) local run_lua_fn, err = load(lua_code, nil, nil, self.environment) @@ -1420,10 +1434,9 @@ do return error("Attempt to run undefined action: " .. tostring(key), 0) end }) - self.action_metadata = setmetatable({ }, { + self.environment.ACTION_METADATA = setmetatable({ }, { __mode = "k" }) - self.environment.ACTION_METADATA = self.action_metadata self.environment.LOADED = { } return self:initialize_core() end, @@ -1590,7 +1603,7 @@ if arg and debug.getinfo(2).func ~= require then end local line = nil do - local metadata = nomsu.action_metadata[calling_fn.func] + local metadata = nomsu.environment.ACTION_METADATA[calling_fn.func] if metadata then local filename, start, stop = metadata.source:match("([^:]*):([0-9]*),([0-9]*)") if filename then |
