Advertisement
fatboychummy

littleSerial.lua

Feb 21st, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.53 KB | None | 0 0
  1. function littleSerial(tbl, spc)
  2.   spc = spc or 2
  3.  
  4.   local str = "{\n"
  5.   local function app(a)
  6.     str = str .. a
  7.   end
  8.   local last = 0
  9.  
  10.   local repStr = string.rep(' ', spc)
  11.  
  12.   for i, v in ipairs(tbl) do
  13.     if i ~= i + 1 then
  14.       app(string.format("%s[ %d ] = ", repStr, i))
  15.       last = math.huge
  16.     else
  17.       last = last + 1
  18.     end
  19.     if type(v) = "table" then
  20.       app(littleSerial(v, spc + 2) .. ",\n")
  21.     else
  22.       app(repStr .. tostring(v) .. ",\n")
  23.     end
  24.   end
  25.   app("}")
  26.  
  27.   return str
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement