BluAxolotl

Untitled

Oct 28th, 2021 (edited)
247
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function serializeTable(val, name, skipnewlines, depth)
  2.     skipnewlines = skipnewlines or false
  3.     depth = depth or 0
  4.  
  5.     local tmp = string.rep(" ", depth)
  6.  
  7.     if name then tmp = tmp .. name .. " = " end
  8.  
  9.     if type(val) == "table" then
  10.         tmp = tmp .. "{" .. (not skipnewlines and "\n" or "")
  11.  
  12.         for k, v in pairs(val) do
  13.             tmp =  tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "")
  14.         end
  15.  
  16.         tmp = tmp .. string.rep(" ", depth) .. "}"
  17.     elseif type(val) == "number" then
  18.         tmp = tmp .. tostring(val)
  19.     elseif type(val) == "string" then
  20.         tmp = tmp .. string.format("%q", val)
  21.     elseif type(val) == "boolean" then
  22.         tmp = tmp .. (val and "true" or "false")
  23.     else
  24.         tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\""
  25.     end
  26.  
  27.     return tmp
  28. end
RAW Paste Data