Advertisement
Navatusein

Debuger

Feb 13th, 2025
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.84 KB | None | 0 0
  1. local component = require("component")
  2. local shell = require("shell")
  3.  
  4. local args, options = shell.parse(...)
  5.  
  6. local file = nil
  7.  
  8. local function objectToString(object, indent)
  9.   indent = indent or 0
  10.   local formatting = string.rep(" ", indent)
  11.   local result = "{\n"
  12.  
  13.   for k, v in pairs(object) do
  14.       local key = type(k) == "string" and ('"' .. k .. '"') or k
  15.       local value
  16.  
  17.       if type(v) == "table" then
  18.           value = objectToString(v, indent + 4)
  19.       elseif type(v) == "string" then
  20.           value = '"' .. v .. '"'
  21.       elseif type(v) == "number" or type(v) == "boolean" then
  22.           value = tostring(v)
  23.       elseif type(v) == "function" then
  24.           value = "<function>"
  25.       elseif type(v) == "userdata" then
  26.           value = "<userdata>"
  27.       elseif type(v) == "thread" then
  28.           value = "<thread>"
  29.       else
  30.           value = "<unknown>"
  31.       end
  32.  
  33.       result = result .. formatting .. "    [" .. key .. "] = " .. value .. ",\n"
  34.   end
  35.  
  36.   return result .. formatting .. "}"
  37. end
  38.  
  39. local function fileWriter(data)
  40.   if file == nil then
  41.     local fileName = "output.txt"
  42.     local fileMode = "w"
  43.  
  44.     if options["file"] ~= nil then
  45.       fileName = options["file"]
  46.     end
  47.  
  48.     if options["mode"] ~= nil then
  49.       fileMode = options["mode"]
  50.     end
  51.  
  52.     file = assert(io.open(fileName, fileMode))
  53.   end
  54.  
  55.   file:write(data.."\n")
  56. end
  57.  
  58. local function getComponentMethods(address)
  59.   address = component.get(address)
  60.   local proxy = component.proxy(address)
  61.  
  62.   local data = {}
  63.  
  64.   for key, value in pairs(proxy) do
  65.     data[key] = tostring(value)
  66.   end
  67.  
  68.   fileWriter(objectToString(data))
  69. end
  70.  
  71. local function main()
  72.   local command = args[1]
  73.  
  74.   if command == "methods" then
  75.     getComponentMethods(args[2])
  76.   end
  77.  
  78.   if file ~= nil then
  79.     file:close()
  80.   end
  81. end
  82.  
  83. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement