Advertisement
AMisspelledUsernaem

table print lua

Apr 19th, 2023 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | Help | 0 0
  1.  
  2. function tostringV2(any,ind)
  3.     if type(any)=="string" then
  4.         return '"'..any:gsub("\n"," ")..'"'
  5.     elseif type(any)=="number" then
  6.         return tostring(any)
  7.     elseif type(any)=="table" then
  8.         return tableToString(any,ind+1)
  9.     elseif typeof(any)=="Instance" then
  10.         return any:GetFullName()
  11.     elseif typeof(any)=="function" then
  12.         return tostring(any)
  13.     elseif typeof(any)=="RBXScriptConnection" then --robloc lol
  14.         return "RBXConnection"
  15.     elseif type(any)=="boolean" then
  16.         return tostring(any)
  17.     elseif any==nil then
  18.         return "nil"
  19.     end
  20. end
  21. function tableToString(t,ind)
  22.     local str="{\n"
  23.     for i,v in pairs(t) do
  24.         if type(i)=="string" then
  25.             str=str..(" "):rep(ind or 1)..'["'..i..'"] = '..tostringV2(v,ind)..",\n"
  26.         elseif type(i)=="number" then
  27.             str=str..(" "):rep(ind or 1).."["..i.."] = "..tostringV2(v,ind)..",\n"
  28.         end
  29.     end
  30.     str=str..(" "):rep(ind-1 or 1).."}"
  31.     return str
  32. end
  33.  
  34. print(tableToString({{{4*2,{{"g",67}}},{(10)},{"hi"}}},1))
  35.  
  36. --[[
  37. {
  38.     [1] = {
  39.         [1] = {
  40.             [1] = 8,
  41.             [2] = {
  42.                 [1] = {
  43.                     [1] = "g",
  44.                     [2] = 67,
  45.                 },
  46.             },
  47.         },
  48.         [2] = {
  49.             [1] = 10,
  50.         },
  51.         [3] = {
  52.             [1] = "hi",
  53.         },
  54.     },
  55. }
  56. ]]
Tags: tables
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement