From 371548150618d5b3501f388972077b5d035f7d8a Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 21 Sep 2017 00:10:26 -0700 Subject: Another overhaul, this time pulling all the chunks of the core lib into their own files. --- utils.moon | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'utils.moon') diff --git a/utils.moon b/utils.moon index b46bf44..3b3573c 100644 --- a/utils.moon +++ b/utils.moon @@ -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}]+")] -- cgit v1.2.3