32 lines
717 B
Lua
32 lines
717 B
Lua
-- vi: ft=lua
|
|
|
|
--lua module "utils" for random utilities
|
|
if utils then return end --avoid loading twice
|
|
utils = {}
|
|
|
|
function utils.getSideOf(name) --get which side, if any, a peripheral p is connected to
|
|
local sides = peripheral.getNames()
|
|
for i = 1, #sides do
|
|
if peripheral.getType(sides[i]) == name then
|
|
--found it!
|
|
return sides[i]
|
|
end
|
|
end
|
|
end
|
|
|
|
function utils.printToMon(mon, text)
|
|
local x, y = mon.getCursorPos()
|
|
mon.write(text)
|
|
mon.setCursorPos(x, y+1)
|
|
end
|
|
|
|
function utils.setupMonitor(side, textScale)
|
|
local mon = peripheral.wrap(side)
|
|
mon.clear()
|
|
mon.setTextScale(textScale)
|
|
mon.setCursorPos(1, 1)
|
|
return mon
|
|
end
|
|
|
|
return utils
|