@@ -1713,7 +1713,7 @@ function metaFuncs.outputLuaTemplate(lua, ...)
17131713 errorIfNotRunningMeta (2 )
17141714 assertarg (1 , lua , " string" )
17151715
1716- local args = {... }
1716+ local args = {... } -- @Memory
17171717 local n = 0
17181718 local v , err
17191719
@@ -1733,20 +1733,32 @@ end
17331733
17341734-- getOutputSoFar()
17351735-- luaString = getOutputSoFar( [ asTable=false ] )
1736+ -- getOutputSoFar( buffer )
17361737-- Get Lua code that's been outputted so far.
17371738-- If asTable is false then the full Lua code string is returned.
17381739-- If asTable is true then an array of Lua code segments is returned. (This avoids allocating, possibly large, strings.)
1740+ -- If a buffer array is given then Lua code segments are added to it.
17391741-- Raises an error if no file or string is being processed.
1740- function metaFuncs .getOutputSoFar (asTable )
1742+ function metaFuncs .getOutputSoFar (bufferOrAsTable )
17411743 errorIfNotRunningMeta (2 )
1744+
17421745 -- Should there be a way to get the contents of current_meta_output etc.? :GetMoreOutputFromStack
1743- return asTable and copyArray (current_meta_outputStack [1 ]) or table.concat (current_meta_outputStack [1 ])
1746+
1747+ if type (bufferOrAsTable ) == " table" then
1748+ for _ , lua in ipairs (current_meta_outputStack [1 ]) do
1749+ tableInsert (bufferOrAsTable , lua )
1750+ end
1751+ -- Return nothing!
1752+
1753+ else
1754+ return bufferOrAsTable and copyArray (current_meta_outputStack [1 ]) or table.concat (current_meta_outputStack [1 ])
1755+ end
17441756end
17451757
17461758local function getOutputSoFarOnLine ()
17471759 errorIfNotRunningMeta (2 )
17481760
1749- local lineFragments = {}
1761+ local lineFragments = {} -- @Memory
17501762
17511763 -- Should there be a way to get the contents of current_meta_output etc.? :GetMoreOutputFromStack
17521764 for i = # current_meta_outputStack [1 ], 1 , - 1 do
@@ -2148,7 +2160,7 @@ end
21482160function metaFuncs .startInterceptingOutput ()
21492161 errorIfNotRunningMeta (2 )
21502162
2151- current_meta_output = {}
2163+ current_meta_output = {} -- @Memory (Especially if lots of macro calls are used!)
21522164 tableInsert (current_meta_outputStack , current_meta_output )
21532165end
21542166
@@ -2234,7 +2246,7 @@ function metaFuncs.LOG(logLevelCode, valueOrFormatCode, ...)
22342246
22352247 if ... then
22362248 tableInsert (current_meta_output , " string.format(" )
2237- tableInsert (current_meta_output , table.concat ({valueOrFormatCode , ... }, " , " ))
2249+ tableInsert (current_meta_output , table.concat ({valueOrFormatCode , ... }, " , " )) -- @Memory
22382250 tableInsert (current_meta_output , " )" )
22392251 else
22402252 tableInsert (current_meta_output , valueOrFormatCode )
0 commit comments