summaryrefslogtreecommitdiff
path: root/digilines/init.lua
diff options
context:
space:
mode:
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>2017-03-17 16:53:18 -0400
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>2017-03-17 16:53:18 -0400
commit907e8bf6a64215a516fdf16869dd81248aeaa2f6 (patch)
treed199282e5764c7ab5183fe0d78ed0412dbb0b89f /digilines/init.lua
parent06d9243586cecb1abed74550ce2544b436572a35 (diff)
downloaddreambuilder_modpack-907e8bf6a64215a516fdf16869dd81248aeaa2f6.tar
dreambuilder_modpack-907e8bf6a64215a516fdf16869dd81248aeaa2f6.tar.gz
dreambuilder_modpack-907e8bf6a64215a516fdf16869dd81248aeaa2f6.tar.bz2
dreambuilder_modpack-907e8bf6a64215a516fdf16869dd81248aeaa2f6.tar.xz
dreambuilder_modpack-907e8bf6a64215a516fdf16869dd81248aeaa2f6.zip
update digilines, technic, unified inventory,
and switched castles to the new modpack form
Diffstat (limited to 'digilines/init.lua')
-rw-r--r--digilines/init.lua46
1 files changed, 42 insertions, 4 deletions
diff --git a/digilines/init.lua b/digilines/init.lua
index bffd4e7..21c1c8e 100644
--- a/digilines/init.lua
+++ b/digilines/init.lua
@@ -1,4 +1,42 @@
-digiline = {}
+
+digilines = {}
+
+-- Backwards compatibility code.
+-- We define a proxy table whose methods can be called with the
+-- `foo:bar` notation, and it will redirect the call to the
+-- real function, dropping the first implicit argument.
+local digiline; digiline = setmetatable({}, {
+ __index = function(_, k)
+ -- Get method from real table.
+ local v = digilines[k]
+ if type(v) == "function" then
+ -- We need to wrap functions in order to ignore
+ -- the implicit `self` argument.
+ local f = v
+ return function(self, ...)
+ -- Trap invalid calls of the form `digiline.foo(...)`.
+ assert(self == digiline)
+ return f(...)
+ end
+ end
+ return v
+ end,
+})
+rawset(_G, "digiline", digiline)
+
+-- Let's test our proxy table.
+function digilines._testproxy(x)
+ return x
+end
+
+-- Test using old `digiline:foobar` form.
+assert(digiline:_testproxy("foobar") == "foobar")
+
+-- Test using new `digilines.foobar` form.
+assert(digilines._testproxy("foobar") == "foobar")
+
+-- Test calling incorrect form raises an error.
+assert(not pcall(function() digiline._testproxy("foobar") end))
local modpath = minetest.get_modpath("digilines")
dofile(modpath .. "/presetrules.lua")
@@ -7,12 +45,12 @@ dofile(modpath .. "/internal.lua")
dofile(modpath .. "/wires_common.lua")
dofile(modpath .. "/wire_std.lua")
-function digiline:receptor_send(pos, rules, channel, msg)
+function digilines.receptor_send(pos, rules, channel, msg)
local checked = {}
checked[minetest.hash_node_position(pos)] = true -- exclude itself
for _,rule in ipairs(rules) do
- if digiline:rules_link(pos, digiline:addPosRule(pos, rule)) then
- digiline:transmit(digiline:addPosRule(pos, rule), channel, msg, checked)
+ if digilines.rules_link(pos, digilines.addPosRule(pos, rule)) then
+ digilines.transmit(digilines.addPosRule(pos, rule), channel, msg, checked)
end
end
end