2424 - toLua, serialize
2525 Only during processing:
2626 - getCurrentPathIn, getCurrentPathOut
27+ - getOutputSoFar, getOutputSizeSoFar, getCurrentLineNumberInOutput
2728 - outputValue, outputLua, outputLuaTemplate
2829 Search this file for 'EnvironmentTable' for more info.
2930
122123
123124
124125
125- local PP_VERSION = " 1.14.0"
126+ local PP_VERSION = " 1.14.0-dev "
126127
127128local MAX_DUPLICATE_FILE_INSERTS = 1000 -- @Incomplete: Make this a parameter for processFile()/processString().
128129
@@ -201,7 +202,7 @@ local _concatTokens
201202local _tokenize
202203local assertarg
203204local cleanError
204- local copyTable
205+ local copyArray , copyTable
205206local countString , countSubString
206207local errorf , errorLine , errorfLine , errorOnLine , errorInFile , errorAtToken , errorAfterToken
207208local errorIfNotRunningMeta
@@ -1089,6 +1090,14 @@ end
10891090
10901091
10911092
1093+ function copyArray (t )
1094+ local copy = {}
1095+ for i , v in ipairs (table_name ) do
1096+ copy [i ] = v
1097+ end
1098+ return copy
1099+ end
1100+
10921101-- copy = copyTable( table [, deep=false ] )
10931102do
10941103 local function deepCopy (t , copy , tableCopies )
@@ -1371,7 +1380,8 @@ end
13711380
13721381-- outputValue()
13731382-- Output one or more values, like strings or tables, as literals.
1374- -- outputValue( value1, ... )
1383+ -- outputValue( value )
1384+ -- outputValue( value1, value2, ... ) -- Outputted values will be separated by commas.
13751385function metaFuncs .outputValue (...)
13761386 errorIfNotRunningMeta (2 )
13771387
@@ -1388,6 +1398,10 @@ function metaFuncs.outputValue(...)
13881398 errorOnLine (metaPathForErrorMessages , ln , " MetaProgram" , " Trying to output nil which is disallowed through params.canOutputNil ." )
13891399 end
13901400
1401+ if i > 1 then
1402+ tableInsert (outputFromMeta , (isDebug and " , " or " ," ))
1403+ end
1404+
13911405 local ok , err = serialize (outputFromMeta , v )
13921406
13931407 if not ok then
@@ -1444,6 +1458,46 @@ function metaFuncs.outputLuaTemplate(lua, ...)
14441458 tableInsert (outputFromMeta , lua )
14451459end
14461460
1461+ -- getOutputSoFar() @Doc
1462+ -- Get Lua code that's been outputted so far.
1463+ -- output = getOutputSoFar( [ asTable=false ] )
1464+ -- If asTable is false then the full Lua code string is returned.
1465+ -- If asTable is true then an array of Lua code segments is returned. (This avoids allocating, possibly large, strings.)
1466+ function metaFuncs .getOutputSoFar (asTable )
1467+ errorIfNotRunningMeta (2 )
1468+ return asTable and copyArray (outputFromMeta ) or table.concat (outputFromMeta )
1469+ end
1470+
1471+ -- getOutputSizeSoFar() @Doc
1472+ -- Get the amount of bytes outputted so far.
1473+ -- size = getOutputSizeSoFar( )
1474+ function metaFuncs .getOutputSizeSoFar ()
1475+ errorIfNotRunningMeta (2 )
1476+
1477+ local size = 0
1478+
1479+ for _ , lua in ipairs (outputFromMeta ) do
1480+ size = size + # lua
1481+ end
1482+
1483+ return size
1484+ end
1485+
1486+ -- getCurrentLineNumberInOutput() @Doc
1487+ -- Get the current line number in the output.
1488+ -- lineNumber = getCurrentLineNumberInOutput( )
1489+ function metaFuncs .getCurrentLineNumberInOutput ()
1490+ errorIfNotRunningMeta (2 )
1491+
1492+ local ln = 1
1493+
1494+ for _ , lua in ipairs (outputFromMeta ) do
1495+ ln = ln + countString (lua , " \n " , true )
1496+ end
1497+
1498+ return ln
1499+ end
1500+
14471501-- getCurrentPathIn()
14481502-- Get what file is currently being processed, if any.
14491503-- path = getCurrentPathIn( )
0 commit comments