Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local shell = require("shell")
- local args, options = shell.parse(...)
- local file = nil
- local function objectToString(object, indent)
- indent = indent or 0
- local formatting = string.rep(" ", indent)
- local result = "{\n"
- for k, v in pairs(object) do
- local key = type(k) == "string" and ('"' .. k .. '"') or k
- local value
- if type(v) == "table" then
- value = objectToString(v, indent + 4)
- elseif type(v) == "string" then
- value = '"' .. v .. '"'
- elseif type(v) == "number" or type(v) == "boolean" then
- value = tostring(v)
- elseif type(v) == "function" then
- value = "<function>"
- elseif type(v) == "userdata" then
- value = "<userdata>"
- elseif type(v) == "thread" then
- value = "<thread>"
- else
- value = "<unknown>"
- end
- result = result .. formatting .. " [" .. key .. "] = " .. value .. ",\n"
- end
- return result .. formatting .. "}"
- end
- local function fileWriter(data)
- if file == nil then
- local fileName = "output.txt"
- local fileMode = "w"
- if options["file"] ~= nil then
- fileName = options["file"]
- end
- if options["mode"] ~= nil then
- fileMode = options["mode"]
- end
- file = assert(io.open(fileName, fileMode))
- end
- file:write(data.."\n")
- end
- local function getComponentMethods(address)
- address = component.get(address)
- local proxy = component.proxy(address)
- local data = {}
- for key, value in pairs(proxy) do
- data[key] = tostring(value)
- end
- fileWriter(objectToString(data))
- end
- local function main()
- local command = args[1]
- if command == "methods" then
- getComponentMethods(args[2])
- end
- if file ~= nil then
- file:close()
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement