concat is done outside of compiled func

This commit is contained in:
leaf corcoran
2014-02-01 12:07:43 -08:00
parent 761ee03fbd
commit fe504d3d25
2 changed files with 17 additions and 6 deletions

View File

@@ -175,7 +175,13 @@ do
return nil, err
end
return function(...)
return self:run(fn, ...)
local buffer
buffer, err = self:run(fn, ...)
if buffer then
return concat(buffer)
else
return nil, err
end
end
end,
parse = function(self, str)
@@ -293,7 +299,7 @@ do
error("unknown type " .. tostring(t))
end
end
push("return _concat(_b)")
push("return _b")
return concat(buffer, "\n")
end
}
@@ -321,10 +327,10 @@ local compile = (function()
end
end)()
local render
render = function(str, env)
render = function(str, ...)
local fn, err = compile(str)
if fn then
return fn(env)
return fn(...)
else
return nil, err
end

View File

@@ -134,7 +134,12 @@ class Parser
return nil, err unless success
fn, err = @load @chunks_to_lua!
return nil, err unless fn
(...) -> @run fn, ...
(...) ->
buffer, err = @run fn, ...
if buffer
concat buffer
else
nil, err
parse: (@str) =>
assert type(@str) == "string", "expecting string for parse"
@@ -228,7 +233,7 @@ class Parser
else
error "unknown type #{t}"
push "return _concat(_b)"
push "return _b"
concat buffer, "\n"
compile = Parser!\compile