Advertisement
9_cVv

tableToString

Jul 17th, 2021 (edited)
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.79 KB | None | 0 0
  1. function fullname(input)
  2.     if input then
  3.         if input.Parent == game then
  4.             return 'game:GetService"'..input.ClassName..'"'
  5.         end
  6.         local result = input.Name
  7.         input = input.Parent
  8.         repeat wait()
  9.             if input then
  10.                 if input.Parent == game then
  11.                     result = "game:GetService'"..input.Name.."'." .. result
  12.                 else
  13.                     result = input.Name .. '.' .. result
  14.                 end
  15.                 input = input.Parent
  16.             end
  17.         until input == game
  18.         return result
  19.     end
  20. end
  21.  
  22. local tableToString
  23. local datatypes = {}
  24. datatypes.string = function(input)
  25.     return '"' .. tostring(input) .. '"'
  26. end
  27. datatypes.number = function(input)
  28.     return tostring(input)
  29. end
  30. datatypes.boolean = function(input)
  31.     return datatypes.number(input)
  32. end
  33. datatypes.EnumItem = function(input)
  34.     return datatypes.number(input)
  35. end
  36. datatypes.table = function(input)
  37.     return tableToString(input)
  38. end
  39. datatypes.Color3 = function(input)
  40.     local r = tostring(input.R*255)
  41.     local g = tostring(input.G*255)
  42.     local b = tostring(input.B*255)
  43.     return 'Color3.fromRGB(' .. r .. ', ' .. g .. ', ' .. b .. ')'
  44. end
  45. datatypes.ColorSequenceKeypoint = function(input)
  46.     return 'ColorSequenceKeypoint.new(' .. input.Time .. ', ' .. datatypes.Color3(input.Value) .. ')'
  47. end
  48. datatypes.ColorSequence = function(input)
  49.     local output = 'ColorSequence.new({'
  50.     local keypoints = input.Keypoints
  51.     for a,keypoint in pairs(keypoints) do
  52.         output = output .. datatypes.ColorSequenceKeypoint(keypoint)
  53.         if #keypoints > 1 and a < #keypoints then
  54.             output = output .. ', '
  55.         end
  56.     end
  57.     output = output .. '})'
  58.     return output
  59. end
  60. datatypes.NumberSequenceKeypoint = function(input)
  61.     return 'NumberSequenceKeypoint.new(' .. input.Time .. ', ' .. input.Value .. ')'
  62. end
  63. datatypes.NumberSequence = function(input)
  64.     local output = 'NumberSequence.new({'
  65.     local keypoints = input.Keypoints
  66.     for a,keypoint in pairs(keypoints) do
  67.         output = output .. datatypes.NumberSequenceKeypoint(keypoint)
  68.         if #keypoints > 1 and a < #keypoints then
  69.             output = output .. ', '
  70.         end
  71.     end
  72.     output = output .. '})'
  73.     return output
  74. end
  75. datatypes.NumberRange = function(input)
  76.     return 'NumberRange.new('..input.Min..', '..input.Max..')'
  77. end
  78. datatypes.UDim = function(input)
  79.     return 'UDim.new(' .. tostring(input.Scale) .. ', ' .. tostring(input.Offset) .. ')'
  80. end
  81. datatypes.UDim2 = function(input)
  82.     return 'UDim2.new(' .. tostring(input.X) .. ', ' .. tostring(input.Y) .. ')'
  83. end
  84. datatypes.Vector2 = function(input)
  85.     return 'Vector2.new(' .. tostring(input) .. ')'
  86. end
  87. datatypes.Vector3 = function(input)
  88.     return 'Vector3.new(' .. tostring(input) .. ')'
  89. end
  90. datatypes.Rect = function(input)
  91.     return 'Rect.new(' .. tostring(input) .. ')'
  92. end
  93. datatypes.CFrame = function(input)
  94.     return 'CFrame.new(' .. tostring(input) .. ')'
  95. end
  96. datatypes.BrickColor = function(input)
  97.     return 'BrickColor.new("'..tostring(input)..'")'
  98. end
  99. datatypes.Faces = function(input)
  100.     local output = 'Faces.new('
  101.     input = tostring(input)
  102.     local ids = {'Back', 'Front', 'Top', 'Bottom', 'Left',' Right'}
  103.  
  104.     for a,id in pairs(ids) do
  105.         input = input:gsub(id, 'Enum.NormalId'..id)
  106.     end
  107.     output = output .. input .. ')'
  108.     return output
  109. end
  110. datatypes.Instance = function(input)
  111.     return fullname(input)
  112. end
  113.  
  114. function x1(value)
  115.     local tof = typeof(value)
  116.     if datatypes[tof] then
  117.         return datatypes[tof](value)
  118.     else
  119.         return tostring(value)
  120.     end
  121. end
  122. tableToString = function(t, bool)
  123.     local result = '' if not bool then result = '{' end
  124.    
  125.     for a,b in pairs(t) do
  126.         if a and b then
  127.             result ..= x1(b)
  128.             if #t > 1 and a < #t then
  129.                 result ..= ', '
  130.             end
  131.         end
  132.     end
  133.     if not bool then result ..= '}' end
  134.    
  135.     return result
  136. end
  137.  
  138. return tableToString
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement