11--[[ ============================================================
22--=
3- --= LuaPreprocess v1.20 - preprocessing library
3+ --= LuaPreprocess v1.20-dev - preprocessing library
44--= by Marcus 'ReFreezed' Thunström
55--=
66--= License: MIT (see the bottom of this file)
131131
132132
133133
134- local PP_VERSION = " 1.20.0"
134+ local PP_VERSION = " 1.20.0-dev "
135135
136136local MAX_DUPLICATE_FILE_INSERTS = 1000 -- @Incomplete: Make this a parameter for processFile()/processString().
137137
@@ -1755,23 +1755,28 @@ function metaFuncs.getOutputSoFar(bufferOrAsTable)
17551755 end
17561756end
17571757
1758+ local lineFragments = {}
1759+
17581760local function getOutputSoFarOnLine ()
17591761 errorIfNotRunningMeta (2 )
17601762
1761- local lineFragments = {} -- @Memory
1763+ local len = 0
17621764
17631765 -- Should there be a way to get the contents of current_meta_output etc.? :GetMoreOutputFromStack
17641766 for i = # current_meta_outputStack [1 ], 1 , - 1 do
17651767 local fragment = current_meta_outputStack [1 ][i ]
17661768
17671769 if fragment :find (" \n " , 1 , true ) then
1768- tableInsert (lineFragments , (fragment :gsub (" .*\n " , " " )))
1770+ len = len + 1
1771+ lineFragments [len ] = fragment :gsub (" .*\n " , " " )
17691772 break
17701773 end
1771- tableInsert (lineFragments , fragment )
1774+
1775+ len = len + 1
1776+ lineFragments [len ] = fragment
17721777 end
17731778
1774- return table.concat (lineFragments )
1779+ return table.concat (lineFragments , 1 , len )
17751780end
17761781
17771782-- getOutputSoFarOnLine()
@@ -2153,14 +2158,17 @@ function metaFuncs.concatTokens(tokens)
21532158 return (_concatTokens (tokens , nil , false , nil , nil ))
21542159end
21552160
2161+ local recycledArrays = {}
2162+
21562163-- startInterceptingOutput()
21572164-- startInterceptingOutput( )
21582165-- Start intercepting output until stopInterceptingOutput() is called.
21592166-- The function can be called multiple times to intercept interceptions.
21602167function metaFuncs .startInterceptingOutput ()
21612168 errorIfNotRunningMeta (2 )
21622169
2163- current_meta_output = {} -- @Memory (Especially if lots of macro calls are used!)
2170+ current_meta_output = tableRemove (recycledArrays ) or {}
2171+ for i = 1 , # current_meta_output do current_meta_output [i ] = nil end
21642172 tableInsert (current_meta_outputStack , current_meta_output )
21652173end
21662174
@@ -2169,6 +2177,7 @@ local function _stopInterceptingOutput(errLevel)
21692177
21702178 local interceptedLua = tableRemove (current_meta_outputStack )
21712179 current_meta_output = current_meta_outputStack [# current_meta_outputStack ] or error (" Called stopInterceptingOutput() before calling startInterceptingOutput()." , 1 + errLevel )
2180+ tableInsert (recycledArrays , interceptedLua )
21722181
21732182 return table.concat (interceptedLua )
21742183end
@@ -2246,7 +2255,11 @@ function metaFuncs.LOG(logLevelCode, valueOrFormatCode, ...)
22462255
22472256 if ... then
22482257 tableInsert (current_meta_output , " string.format(" )
2249- tableInsert (current_meta_output , table.concat ({valueOrFormatCode , ... }, " , " )) -- @Memory
2258+ tableInsert (current_meta_output , valueOrFormatCode )
2259+ for i = 1 , select (" #" , ... ) do
2260+ tableInsert (current_meta_output , " , " )
2261+ tableInsert (current_meta_output , (select (i , ... )))
2262+ end
22502263 tableInsert (current_meta_output , " )" )
22512264 else
22522265 tableInsert (current_meta_output , valueOrFormatCode )
0 commit comments