diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2017-09-21 00:10:26 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2017-09-21 00:10:26 -0700 |
| commit | 371548150618d5b3501f388972077b5d035f7d8a (patch) | |
| tree | 8a1cdf99dc25536e21a5a571e5d54607a50848f4 /utils.moon | |
| parent | 0750d642624b2262afdb4dd17b275a16e96971b5 (diff) | |
Another overhaul, this time pulling all the chunks of the core lib into
their own files.
Diffstat (limited to 'utils.moon')
| -rw-r--r-- | utils.moon | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -7,22 +7,20 @@ utils = { i += 1 return true - repr: (x, add_quotes=false)-> + repr: (x)-> switch type(x) when 'table' mt = getmetatable(x) if mt and mt.__tostring mt.__tostring(x) elseif utils.is_list x - "{#{table.concat([utils.repr(i, true) for i in *x], ", ")}}" + "{#{table.concat([utils.repr(i) for i in *x], ", ")}}" else - "{#{table.concat(["[#{utils.repr(k, true)}]= #{utils.repr(v, true)}" for k,v in pairs x], ", ")}}" + "{#{table.concat(["[#{utils.repr(k)}]= #{utils.repr(v)}" for k,v in pairs x], ", ")}}" when 'string' - if not add_quotes - x - elseif not x\find[["]] and not x\find"\n" + if not x\find[["]] and not x\find"\n" and not x\find"\\" "\""..x.."\"" - elseif not x\find[[']] and not x\find"\n" + elseif not x\find[[']] and not x\find"\n" and not x\find"\\" "\'"..x.."\'" else for i=0,math.huge @@ -36,6 +34,10 @@ utils = { else tostring(x) + repr_if_not_string: (x)-> + if type(x) == 'string' then x + else utils.repr(x) + split: (str, sep="%s")-> [chunk for chunk in str\gmatch("[^#{sep}]+")] |
