1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-24 22:23:21 +00:00
CC-Tweaked/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua
SquidDev 86e0330100 Lint bios and the rom (#321)
We now use illuaminate[1]'s linting facilities to check the rom and
bios.lua for a couple of common bugs and other problems.

Right now this doesn't detect any especially important bugs, though it
has caught lots of small things (unused variables, some noisy code). In
the future, the linter will grow in scope and features, which should
allow us to be stricter and catch most issues.

As a fun aside, we started off with ~150 bugs, and illuaminate was able
to fix all but 30 of them, which is pretty neat.

[1]: https://github.com/SquidDev/illuaminate
2019-12-03 23:26:13 +00:00

88 lines
1.7 KiB
Lua

local function isDrive( name )
if type( name ) ~= "string" then
error( "bad argument #1 (expected string, got " .. type( name ) .. ")", 3 )
end
return peripheral.getType( name ) == "drive"
end
function isPresent( name )
if isDrive( name ) then
return peripheral.call( name, "isDiskPresent" )
end
return false
end
function getLabel( name )
if isDrive( name ) then
return peripheral.call( name, "getDiskLabel" )
end
return nil
end
function setLabel( name, label )
if isDrive( name ) then
peripheral.call( name, "setDiskLabel", label )
end
end
function hasData( name )
if isDrive( name ) then
return peripheral.call( name, "hasData" )
end
return false
end
function getMountPath( name )
if isDrive( name ) then
return peripheral.call( name, "getMountPath" )
end
return nil
end
function hasAudio( name )
if isDrive( name ) then
return peripheral.call( name, "hasAudio" )
end
return false
end
function getAudioTitle( name )
if isDrive( name ) then
return peripheral.call( name, "getAudioTitle" )
end
return nil
end
function playAudio( name )
if isDrive( name ) then
peripheral.call( name, "playAudio" )
end
end
function stopAudio( name )
if not name then
for _,sName in ipairs( peripheral.getNames() ) do
stopAudio( sName )
end
else
if isDrive( name ) then
peripheral.call( name, "stopAudio" )
end
end
end
function eject( name )
if isDrive( name ) then
peripheral.call( name, "ejectDisk" )
end
end
function getID( name )
if isDrive( name ) then
return peripheral.call( name, "getDiskID" )
end
return nil
end