Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Usage: pastebin run Lqn82CnT side
- -- Where "side" is one of the block's sides
- args = {...}
- selected_side = args[1]
- sides = peripheral.getNames()
- -- This function reads a Lua function and returns its arguments
- function getFunctionArguments (fn)
- local args = {}
- -- Gets data about the function
- local info = debug.getinfo(fn)
- -- Processes each of the arguments (might not work for Peripherals though)
- for i = 1, info.nparams, 1 do
- table.insert(args, debug.getlocal(fn, i))
- end
- -- Done
- return args
- end
- -- Gets a list of methods pretty-printed and sorted
- function getPeripheralMethods (side)
- -- Gets methods
- local methods = peripheral.getMethods(side)
- -- Sorts
- table.sort(methods)
- -- Pretty-prints
- local results = {}
- for _, method in pairs(methods) do
- -- Gets the method
- local fn = selected_peripheral[method]
- -- Gets args list
- local args = getFunctionArguments(fn)
- -- Prints it
- table.insert(results, string.format('%s(%s)', method, table.concat(args, ', ')))
- end
- -- Done
- return results
- end
- -- Prints a formatted string
- function printf (format, ...)
- print(string.format(format, ...))
- end
- -- Lists available peripherals
- printf('Available Sides/Peripherals:')
- -- Side detection
- for _, side in pairs(sides) do
- -- Debug
- printf('-> %s', side)
- -- Check for a monitor on that side
- if (not monitor) and 'monitor' == peripheral.getType(side) then
- monitor = peripheral.wrap(side)
- end
- -- Check for connection with selected side
- if side == selected_side then
- -- Wrap the peripheral
- selected_peripheral = peripheral.wrap(side)
- end
- end
- -- Checks if a side was provided
- if not selected_side then
- printf('No side provided!')
- return 1
- elseif not selected_peripheral then
- printf('Invalid peripheral!')
- printf('Side: %s', selected_side)
- return 1
- end
- -- Route stdout to monitor
- if monitor then
- term.redirect(monitor)
- monitor.setTextScale(0.5)
- end
- -- Clears output and prepares to write
- term.clear()
- term.setCursorPos(1, 1)
- -- Starts getting info
- printf('Peripheral API Info')
- printf('Side: %s', selected_side)
- printf('Type: %s', peripheral.getType(selected_side))
- -- Gets available methods
- print('')
- print(table.concat(getPeripheralMethods(selected_side), '\n'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement