init.lua 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. digilines = {}
  2. -- Backwards compatibility code.
  3. -- We define a proxy table whose methods can be called with the
  4. -- `foo:bar` notation, and it will redirect the call to the
  5. -- real function, dropping the first implicit argument.
  6. local digiline; digiline = setmetatable({}, {
  7. __index = function(_, k)
  8. -- Get method from real table.
  9. local v = digilines[k]
  10. if type(v) == "function" then
  11. -- We need to wrap functions in order to ignore
  12. -- the implicit `self` argument.
  13. local f = v
  14. return function(self, ...)
  15. -- Trap invalid calls of the form `digiline.foo(...)`.
  16. assert(self == digiline)
  17. return f(...)
  18. end
  19. end
  20. return v
  21. end,
  22. })
  23. rawset(_G, "digiline", digiline)
  24. -- Let's test our proxy table.
  25. function digilines._testproxy(x)
  26. return x
  27. end
  28. -- Test using old `digiline:foobar` form.
  29. assert(digiline:_testproxy("foobar") == "foobar")
  30. -- Test using new `digilines.foobar` form.
  31. assert(digilines._testproxy("foobar") == "foobar")
  32. -- Test calling incorrect form raises an error.
  33. assert(not pcall(function() digiline._testproxy("foobar") end))
  34. local modpath = minetest.get_modpath("digilines")
  35. dofile(modpath .. "/presetrules.lua")
  36. dofile(modpath .. "/util.lua")
  37. dofile(modpath .. "/internal.lua")
  38. dofile(modpath .. "/wires_common.lua")
  39. dofile(modpath .. "/wire_std.lua")
  40. function digilines.receptor_send(pos, rules, channel, msg)
  41. local checked = {}
  42. checked[minetest.hash_node_position(pos)] = true -- exclude itself
  43. for _,rule in ipairs(rules) do
  44. if digilines.rules_link(pos, digilines.addPosRule(pos, rule)) then
  45. digilines.transmit(digilines.addPosRule(pos, rule), channel, msg, checked)
  46. end
  47. end
  48. end
  49. minetest.register_craft({
  50. output = 'digilines:wire_std_00000000 2',
  51. recipe = {
  52. {'mesecons_materials:fiber', 'mesecons_materials:fiber', 'mesecons_materials:fiber'},
  53. {'mesecons_insulated:insulated_off', 'mesecons_insulated:insulated_off', 'default:gold_ingot'},
  54. {'mesecons_materials:fiber', 'mesecons_materials:fiber', 'mesecons_materials:fiber'},
  55. }
  56. })
  57. -- For minetest 0.4 support returned nil are also tested: ~= false
  58. if minetest.settings:get_bool("digilines_enable_inventory", true) ~= false then
  59. dofile(modpath .. "/inventory.lua")
  60. end
  61. if minetest.settings:get_bool("digilines_enable_lcd", true) ~= false then
  62. dofile(modpath .. "/lcd.lua")
  63. end
  64. if minetest.settings:get_bool("digilines_enable_lightsensor", true) ~= false then
  65. dofile(modpath .. "/lightsensor.lua")
  66. end
  67. if minetest.settings:get_bool("digilines_enable_rtc", true) ~= false then
  68. dofile(modpath .. "/rtc.lua")
  69. end