aboutsummaryrefslogtreecommitdiff
path: root/importer.lua
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 /importer.lua
parent1f3660f393c1a17988a15b89f18686b28e51a9e7 (diff)
Major overhaul, splitting nomsu_compiler into nomsu_environment,
nomsu_compiler, and nomsu_decompiler. Also added comprehensions.
Diffstat (limited to 'importer.lua')
-rw-r--r--importer.lua62
1 files changed, 62 insertions, 0 deletions
diff --git a/importer.lua b/importer.lua
new file mode 100644
index 0000000..9b2c936
--- /dev/null
+++ b/importer.lua
@@ -0,0 +1,62 @@
+local import_to_1_from
+import_to_1_from = function(host, to_import)
+ do
+ local host_mt = getmetatable(host)
+ if host_mt then
+ if host_mt.__import then
+ host_mt.__import(host, to_import)
+ return
+ end
+ end
+ end
+ for k, v in pairs(to_import) do
+ host[k] = v
+ end
+end
+local _imports = setmetatable({ }, {
+ __mode = "k"
+})
+local Importer = setmetatable({
+ __index = function(self, key)
+ return _imports[self][key]
+ end,
+ __import = function(self, to_import)
+ local imports = assert(_imports[self])
+ for k, v in pairs(to_import) do
+ local _continue_0 = false
+ repeat
+ 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)
+ end
+ _continue_0 = true
+ until true
+ if not _continue_0 then
+ break
+ end
+ end
+ end
+}, {
+ __call = function(self, t)
+ _imports[t] = { }
+ setmetatable(t, self)
+ return t
+ end
+})
+local _1_forked
+_1_forked = function(self)
+ local f = Importer({ })
+ _imports[f] = assert(_imports[self])
+ import_to_1_from(f, self)
+ return f
+end
+return {
+ Importer = Importer,
+ import_to_1_from = import_to_1_from,
+ _1_forked = _1_forked
+}