From 27d1cf641ce3bbfe96e6fe18f24dd46f95efbe5e Mon Sep 17 00:00:00 2001 From: s-ol Date: Mon, 29 Oct 2018 19:35:53 +1100 Subject: better conversion inverence for mmmfs --- lib/component.client.moon | 1 + lib/init.client.moon | 21 +++++++++++++++++++-- lib/init.server.moon | 22 ++++++++++++++++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/component.client.moon b/lib/component.client.moon index 617deb5..af0b38a 100644 --- a/lib/component.client.moon +++ b/lib/component.client.moon @@ -102,6 +102,7 @@ class ReactiveElement @node.style[k] = v return + print "setting attr #{attr}" @node[attr] = value append: (child, last) => diff --git a/lib/init.client.moon b/lib/init.client.moon index c1aea07..d39143d 100644 --- a/lib/init.client.moon +++ b/lib/init.client.moon @@ -5,8 +5,25 @@ window = js.global { :document, :console } = window MODE = 'CLIENT' -print = console\log -warn = console\warn + +deep_tostring = (tbl, space='') -> + buf = space .. tostring tbl + + return buf unless 'table' == type tbl + + buf = buf .. ' {\n' + for k,v in pairs tbl + buf = buf .. "#{space} [#{k}]: #{deep_tostring v, space .. ' '}\n" + buf = buf .. "#{space}}" + buf + +print = (...) -> + contents = [deep_tostring v for v in *{ ... } ] + console\log table.unpack contents + +warn = (...) -> + contents = [deep_tostring v for v in *{ ... } ] + console\warn table.unpack contents package.path = '/?.shared.moon.lua;/?.client.moon.lua;/?.moon.lua;/?/init.moon.lua;/?.lua;/?/init.lua' diff --git a/lib/init.server.moon b/lib/init.server.moon index a91bd52..f81a2dc 100644 --- a/lib/init.server.moon +++ b/lib/init.server.moon @@ -1,9 +1,27 @@ -export MODE, warn, relative, append, on_client +export MODE, print, warn, relative, append, on_client MODE = 'SERVER' +deep_tostring = (tbl, space='') -> + buf = space .. tostring tbl + + return buf unless 'table' == type tbl + + buf = buf .. ' {\n' + for k,v in pairs tbl + buf = buf .. "#{space} [#{k}]: #{deep_tostring v, space .. ' '}\n" + buf = buf .. "#{space}}" + buf + +print = do + _print = print + (...) -> + contents = [deep_tostring v for v in *{ ... } ] + _print table.unpack contents + -- warning messages warn = (...) -> - io.stderr\write table.concat { ... }, '\t' + contents = [deep_tostring v for v in *{ ... } ] + io.stderr\write table.concat contents, '\t' io.stderr\write '\n' -- relative imports -- cgit v1.2.3