1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 11:10:29 +00:00

Make the peripheral API examples a little clearer

This commit is contained in:
Jonathan Coates 2021-04-07 18:34:55 +01:00
parent c3f5700494
commit 17b5bca443

View File

@ -161,7 +161,9 @@ end
-- @tparam string name The name of the peripheral to wrap. -- @tparam string name The name of the peripheral to wrap.
-- @treturn table|nil The table containing the peripheral's methods, or `nil` if -- @treturn table|nil The table containing the peripheral's methods, or `nil` if
-- there is no peripheral present with the given name. -- there is no peripheral present with the given name.
-- @usage peripheral.wrap("top").open(1) -- @usage Open the modem on the top of this computer.
--
-- peripheral.wrap("top").open(1)
function wrap(name) function wrap(name)
expect(1, name, "string") expect(1, name, "string")
@ -183,16 +185,25 @@ function wrap(name)
return result return result
end end
--- Find all peripherals of a specific type, and return the --[[- Find all peripherals of a specific type, and return the
-- @{peripheral.wrap|wrapped} peripherals. @{peripheral.wrap|wrapped} peripherals.
--
-- @tparam string ty The type of peripheral to look for. @tparam string ty The type of peripheral to look for.
-- @tparam[opt] function(name:string, wrapped:table):boolean filter A @tparam[opt] function(name:string, wrapped:table):boolean filter A
-- filter function, which takes the peripheral's name and wrapped table filter function, which takes the peripheral's name and wrapped table
-- and returns if it should be included in the result. and returns if it should be included in the result.
-- @treturn table... 0 or more wrapped peripherals matching the given filters. @treturn table... 0 or more wrapped peripherals matching the given filters.
-- @usage { peripheral.find("monitor") } @usage Find all monitors and store them in a table, writing "Hello" on each one.
-- @usage peripheral.find("modem", rednet.open)
local monitors = { peripheral.find("monitor") }
for _, monitor in pairs(monitors) do
monitor.write("Hello")
end
@usage This abuses the `filter` argument to call @{rednet.open} on every modem.
peripheral.find("modem", rednet.open)
]]
function find(ty, filter) function find(ty, filter)
expect(1, ty, "string") expect(1, ty, "string")
expect(2, filter, "function", "nil") expect(2, filter, "function", "nil")