diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-11-17 14:38:05 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-11-17 14:39:08 -0800 |
| commit | 7f47d4204039258cec78c767f489b7809b4257ff (patch) | |
| tree | c8533068b75ab453accfe1f688705e9e94c9e279 /importer.lua | |
| parent | 34a3dd22a4e132bd4e0fe3ce89831c3fe761d3d9 (diff) | |
In-progress (but working) overhaul of some elements including: function
calls, lib/thing.nom API, multi-assignments, varargs, etc.
Diffstat (limited to 'importer.lua')
| -rw-r--r-- | importer.lua | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/importer.lua b/importer.lua index 9b2c936..0d45db8 100644 --- a/importer.lua +++ b/importer.lua @@ -1,15 +1,27 @@ local import_to_1_from -import_to_1_from = function(host, to_import) +import_to_1_from = function(host, to_import, prefix) + if prefix == nil then + prefix = nil + end do local host_mt = getmetatable(host) if host_mt then if host_mt.__import then - host_mt.__import(host, to_import) + host_mt.__import(host, to_import, prefix) return end end end for k, v in pairs(to_import) do + if k == to_import then + k = host + end + if v == to_import then + v = host + end + if prefix and type(k) == 'string' then + k = prefix .. k + end host[k] = v end end @@ -20,19 +32,30 @@ local Importer = setmetatable({ __index = function(self, key) return _imports[self][key] end, - __import = function(self, to_import) + __import = function(self, to_import, prefix) + if prefix == nil then + prefix = nil + end local imports = assert(_imports[self]) for k, v in pairs(to_import) do local _continue_0 = false repeat + if prefix and type(k) == 'string' then + k = prefix .. k + end imports[k] = v if v == to_import then _continue_0 = true break end local conflict = self[k] - if type(conflict) == 'table' then - import_to_1_from(conflict, v) + do + local conflict_mt = getmetatable(host) + if conflict_mt then + if conflict_mt.__import then + conflict_mt.__import(conflict, v, prefix) + end + end end _continue_0 = true until true @@ -49,8 +72,8 @@ local Importer = setmetatable({ end }) local _1_forked -_1_forked = function(self) - local f = Importer({ }) +_1_forked = function(self, t) + local f = Importer(t or { }) _imports[f] = assert(_imports[self]) import_to_1_from(f, self) return f |
