mirror of
https://github.com/TangentFoxy/etlua.git
synced 2025-07-28 11:02:17 +00:00
concat is done outside of compiled func
This commit is contained in:
14
etlua.lua
14
etlua.lua
@@ -175,7 +175,13 @@ do
|
|||||||
return nil, err
|
return nil, err
|
||||||
end
|
end
|
||||||
return function(...)
|
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
|
||||||
end,
|
end,
|
||||||
parse = function(self, str)
|
parse = function(self, str)
|
||||||
@@ -293,7 +299,7 @@ do
|
|||||||
error("unknown type " .. tostring(t))
|
error("unknown type " .. tostring(t))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
push("return _concat(_b)")
|
push("return _b")
|
||||||
return concat(buffer, "\n")
|
return concat(buffer, "\n")
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@@ -321,10 +327,10 @@ local compile = (function()
|
|||||||
end
|
end
|
||||||
end)()
|
end)()
|
||||||
local render
|
local render
|
||||||
render = function(str, env)
|
render = function(str, ...)
|
||||||
local fn, err = compile(str)
|
local fn, err = compile(str)
|
||||||
if fn then
|
if fn then
|
||||||
return fn(env)
|
return fn(...)
|
||||||
else
|
else
|
||||||
return nil, err
|
return nil, err
|
||||||
end
|
end
|
||||||
|
@@ -134,7 +134,12 @@ class Parser
|
|||||||
return nil, err unless success
|
return nil, err unless success
|
||||||
fn, err = @load @chunks_to_lua!
|
fn, err = @load @chunks_to_lua!
|
||||||
return nil, err unless fn
|
return nil, err unless fn
|
||||||
(...) -> @run fn, ...
|
(...) ->
|
||||||
|
buffer, err = @run fn, ...
|
||||||
|
if buffer
|
||||||
|
concat buffer
|
||||||
|
else
|
||||||
|
nil, err
|
||||||
|
|
||||||
parse: (@str) =>
|
parse: (@str) =>
|
||||||
assert type(@str) == "string", "expecting string for parse"
|
assert type(@str) == "string", "expecting string for parse"
|
||||||
@@ -228,7 +233,7 @@ class Parser
|
|||||||
else
|
else
|
||||||
error "unknown type #{t}"
|
error "unknown type #{t}"
|
||||||
|
|
||||||
push "return _concat(_b)"
|
push "return _b"
|
||||||
concat buffer, "\n"
|
concat buffer, "\n"
|
||||||
|
|
||||||
compile = Parser!\compile
|
compile = Parser!\compile
|
||||||
|
Reference in New Issue
Block a user