Mercurial Hosting > luan
diff core/src/luan/modules/Io.luan @ 591:790d5de23042
add "strict" param to Io.repr();
add Lucene.index.ensure_open();
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 30 Aug 2015 11:37:39 -0600 |
parents | 97c8ae330efe |
children | 35dde32c02ab |
line wrap: on
line diff
--- a/core/src/luan/modules/Io.luan Thu Aug 27 08:35:03 2015 -0600 +++ b/core/src/luan/modules/Io.luan Sun Aug 30 11:37:39 2015 -0600 @@ -72,10 +72,11 @@ -- repr -local function do_repr(obj,done) +local function do_repr(obj,strict,done) local tp = type(obj) if tp == "table" then if done[obj] == true then + strict and error "circular reference" %><circular reference><% return end @@ -85,7 +86,7 @@ local in_list = {} for key, value in ipairs(obj) do if is_first then is_first = false else %>, <% end - do_repr(value,done) + do_repr(value,strict,done) in_list[key] = true end for key, value in pairs(obj) do @@ -96,9 +97,9 @@ elseif type(key) == "table" then %>[<<%=key%>>]<% else - %>[<%do_repr(key,done)%>]<% + %>[<%do_repr(key,strict,done)%>]<% end - %>=<% do_repr(value,done) + %>=<% do_repr(value,strict,done) end end %>}<% @@ -107,12 +108,13 @@ elseif tp == "nil" or tp == "boolean" or tp == "number" then %><%=obj%><% else + strict and error("can't repr type '"..tp.."' of "..obj) %><<%=obj%>><% end end -function M.repr(obj) - return M.output_of(do_repr,obj,{}) +function M.repr(obj,strict) + return M.output_of(do_repr,obj,strict or false,{}) end