Skip to content

Commit 1e8d9a6

Browse files
committed
Updated documentation and changelog.
1 parent f7d5749 commit 1e8d9a6

File tree

3 files changed

+46
-28
lines changed

3 files changed

+46
-28
lines changed

Changelog.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
LuaPreprocess
33

4+
v1.15 (2021-08-01)
5+
Library:
6+
- Added functions: getOutputSoFar(), getOutputSizeSoFar(), getCurrentLineNumberInOutput().
7+
- outputValue() with multiple values will now output commas between the values.
8+
- Added '@insert func!(...)' as syntax sugar for '@insert func(!(...))'.
9+
- Added '@insert func!!(...)' as syntax sugar for '@insert func(!!(...))'.
10+
Command line program:
11+
- Added --nogc option.
12+
413
v1.14 (2021-07-13)
514
Library:
615
- !(), !!() and @insert now work in macros.

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ and [preprocess.lua](preprocess.lua), for the options and more documentation.
179179
## Help
180180

181181
Got a question?
182-
Look if someone has asked the question in the [issue tracker](https://github.com/ReFreezed/LuaPreprocess/issues?q=is%3Aissue),
182+
If the [documentation](http://luapreprocess.refreezed.com/docs/) doesn't have the answer,
183+
look if someone has asked the question in the [issue tracker](https://github.com/ReFreezed/LuaPreprocess/issues?q=is%3Aissue),
183184
or [create a new issue](https://github.com/ReFreezed/LuaPreprocess/issues/new).
184185

186+
Also check out the online [syntax highlighter](http://luapreprocess.refreezed.com/highlight/) tool to help visualize errors in code.
187+
185188

preprocess.lua

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123

124124

125125

126-
local PP_VERSION = "1.14.0-dev"
126+
local PP_VERSION = "1.15.0"
127127

128128
local MAX_DUPLICATE_FILE_INSERTS = 1000 -- @Incomplete: Make this a parameter for processFile()/processString().
129129

@@ -1312,45 +1312,46 @@ metaEnv._G = metaEnv
13121312
local metaFuncs = {}
13131313

13141314
-- printf()
1315-
-- Print a formatted string.
13161315
-- printf( format, value1, ... )
1316+
-- Print a formatted string.
13171317
metaFuncs.printf = printf
13181318

13191319
-- getFileContents()
1320-
-- Get the entire contents of a binary file or text file. Returns nil and a message on error.
13211320
-- contents = getFileContents( path [, isTextFile=false ] )
1321+
-- Get the entire contents of a binary file or text file. Returns nil and a message on error.
13221322
metaFuncs.getFileContents = getFileContents
13231323

13241324
-- fileExists()
1325-
-- Check if a file exists.
13261325
-- bool = fileExists( path )
1326+
-- Check if a file exists.
13271327
metaFuncs.fileExists = fileExists
13281328

13291329
-- toLua()
1330+
-- luaString = toLua( value )
13301331
-- Convert a value to a Lua literal. Does not work with certain types, like functions or userdata.
13311332
-- Returns nil and a message on error.
1332-
-- luaString = toLua( value )
13331333
metaFuncs.toLua = toLua
13341334

13351335
-- serialize()
1336-
-- Same as toLua() except adds the result to an array instead of returning the Lua code as a string.
13371336
-- success, error = serialize( buffer, value )
1337+
-- Same as toLua() except adds the result to an array instead of returning the Lua code as a string.
1338+
-- This could avoid allocating unnecessary strings.
13381339
metaFuncs.serialize = serialize
13391340

13401341
-- escapePattern()
1341-
-- Escape a string so it can be used in a pattern as plain text.
13421342
-- escapedString = escapePattern( string )
1343+
-- Escape a string so it can be used in a pattern as plain text.
13431344
metaFuncs.escapePattern = escapePattern
13441345

13451346
-- isToken()
1346-
-- Check if a token is of a specific type, optionally also check it's value.
13471347
-- bool = isToken( token, tokenType [, tokenValue=any ] )
1348+
-- Check if a token is of a specific type, optionally also check it's value.
13481349
metaFuncs.isToken = isToken
13491350

13501351
-- copyTable()
1352+
-- copy = copyTable( table [, deep=false ] )
13511353
-- Copy a table, optionally recursively (deep copy).
13521354
-- Multiple references to the same table and self-references are preserved during deep copying.
1353-
-- copy = copyTable( table [, deep=false ] )
13541355
metaFuncs.copyTable = copyTable
13551356

13561357
-- unpack()
@@ -1365,8 +1366,8 @@ metaFuncs.unpack = unpack
13651366
metaFuncs.pack = pack
13661367

13671368
-- run()
1368-
-- Execute a Lua file. Similar to dofile().
13691369
-- returnValue1, ... = run( path [, arg1, ... ] )
1370+
-- Execute a Lua file. Similar to dofile().
13701371
function metaFuncs.run(path, ...)
13711372
assertarg(1, path, "string")
13721373

@@ -1379,9 +1380,10 @@ function metaFuncs.run(path, ...)
13791380
end
13801381

13811382
-- outputValue()
1382-
-- Output one or more values, like strings or tables, as literals.
13831383
-- outputValue( value )
13841384
-- outputValue( value1, value2, ... ) -- Outputted values will be separated by commas.
1385+
-- Output one or more values, like strings or tables, as literals.
1386+
-- Raises an error if no file or string is being processed.
13851387
function metaFuncs.outputValue(...)
13861388
errorIfNotRunningMeta(2)
13871389

@@ -1412,8 +1414,9 @@ function metaFuncs.outputValue(...)
14121414
end
14131415

14141416
-- outputLua()
1415-
-- Output one or more strings as raw Lua code.
14161417
-- outputLua( luaString1, ... )
1418+
-- Output one or more strings as raw Lua code.
1419+
-- Raises an error if no file or string is being processed.
14171420
function metaFuncs.outputLua(...)
14181421
errorIfNotRunningMeta(2)
14191422

@@ -1430,9 +1433,10 @@ function metaFuncs.outputLua(...)
14301433
end
14311434

14321435
-- outputLuaTemplate()
1436+
-- outputLuaTemplate( luaStringTemplate, value1, ... )
14331437
-- Use a string as a template for outputting Lua code with values.
14341438
-- Question marks (?) are replaced with the values.
1435-
-- outputLuaTemplate( luaStringTemplate, value1, ... )
1439+
-- Raises an error if no file or string is being processed.
14361440
-- Examples:
14371441
-- outputLuaTemplate("local name, age = ?, ?", "Harry", 48)
14381442
-- outputLuaTemplate("dogs[?] = ?", "greyhound", {italian=false, count=5})
@@ -1458,19 +1462,21 @@ function metaFuncs.outputLuaTemplate(lua, ...)
14581462
tableInsert(outputFromMeta, lua)
14591463
end
14601464

1461-
-- getOutputSoFar() @Doc
1465+
-- getOutputSoFar()
1466+
-- luaString = getOutputSoFar( [ asTable=false ] )
14621467
-- Get Lua code that's been outputted so far.
1463-
-- output = getOutputSoFar( [ asTable=false ] )
14641468
-- If asTable is false then the full Lua code string is returned.
14651469
-- If asTable is true then an array of Lua code segments is returned. (This avoids allocating, possibly large, strings.)
1470+
-- Raises an error if no file or string is being processed.
14661471
function metaFuncs.getOutputSoFar(asTable)
14671472
errorIfNotRunningMeta(2)
14681473
return asTable and copyArray(outputFromMeta) or table.concat(outputFromMeta)
14691474
end
14701475

1471-
-- getOutputSizeSoFar() @Doc
1472-
-- Get the amount of bytes outputted so far.
1476+
-- getOutputSizeSoFar()
14731477
-- size = getOutputSizeSoFar( )
1478+
-- Get the amount of bytes outputted so far.
1479+
-- Raises an error if no file or string is being processed.
14741480
function metaFuncs.getOutputSizeSoFar()
14751481
errorIfNotRunningMeta(2)
14761482

@@ -1483,9 +1489,9 @@ function metaFuncs.getOutputSizeSoFar()
14831489
return size
14841490
end
14851491

1486-
-- getCurrentLineNumberInOutput() @Doc
1487-
-- Get the current line number in the output.
1492+
-- getCurrentLineNumberInOutput()
14881493
-- lineNumber = getCurrentLineNumberInOutput( )
1494+
-- Get the current line number in the output.
14891495
function metaFuncs.getCurrentLineNumberInOutput()
14901496
errorIfNotRunningMeta(2)
14911497

@@ -1499,27 +1505,27 @@ function metaFuncs.getCurrentLineNumberInOutput()
14991505
end
15001506

15011507
-- getCurrentPathIn()
1502-
-- Get what file is currently being processed, if any.
15031508
-- path = getCurrentPathIn( )
1509+
-- Get what file is currently being processed, if any.
15041510
function metaFuncs.getCurrentPathIn()
15051511
return currentPathIn
15061512
end
15071513

15081514
-- getCurrentPathOut()
1509-
-- Get what file the currently processed file will be written to, if any.
15101515
-- path = getCurrentPathOut( )
1516+
-- Get what file the currently processed file will be written to, if any.
15111517
function metaFuncs.getCurrentPathOut()
15121518
return currentPathOut
15131519
end
15141520

15151521
-- tokenize()
1516-
-- Convert Lua code to tokens. Returns nil and a message on error. (See newToken() for token types.)
15171522
-- tokens = tokenize( luaString [, allowPreprocessorCode=false ] )
15181523
-- token = {
15191524
-- type=tokenType, representation=representation, value=value,
15201525
-- line=lineNumber, lineEnd=lineNumber, position=bytePosition, file=filePath,
15211526
-- ...
15221527
-- }
1528+
-- Convert Lua code to tokens. Returns nil and a message on error. (See newToken() for token types.)
15231529
function metaFuncs.tokenize(lua, allowPpCode)
15241530
local ok, errOrTokens = pcall(_tokenize, lua, "<string>", allowPpCode, allowPpCode, true) -- @Incomplete: Make allowJitSyntax a parameter to tokenize()?
15251531
if not ok then
@@ -1529,8 +1535,8 @@ function metaFuncs.tokenize(lua, allowPpCode)
15291535
end
15301536

15311537
-- removeUselessTokens()
1532-
-- Remove whitespace and comment tokens.
15331538
-- removeUselessTokens( tokens )
1539+
-- Remove whitespace and comment tokens.
15341540
function metaFuncs.removeUselessTokens(tokens)
15351541
local len = #tokens
15361542
local offset = 0
@@ -1549,8 +1555,8 @@ function metaFuncs.removeUselessTokens(tokens)
15491555
end
15501556

15511557
-- eachToken()
1552-
-- Loop through tokens.
15531558
-- for index, token in eachToken( tokens [, ignoreUselessTokens=false ] ) do
1559+
-- Loop through tokens.
15541560
local function nextUsefulToken(tokens, i)
15551561
while true do
15561562
i = i+1
@@ -1568,8 +1574,8 @@ function metaFuncs.eachToken(tokens, ignoreUselessTokens)
15681574
end
15691575

15701576
-- getNextUsefulToken()
1571-
-- Get the next token that isn't a whitespace or comment. Returns nil if no more tokens are found.
15721577
-- token, index = getNextUsefulToken( tokens, startIndex [, steps=1 ] )
1578+
-- Get the next token that isn't a whitespace or comment. Returns nil if no more tokens are found.
15731579
-- Specify a negative steps value to get an earlier token.
15741580
function metaFuncs.getNextUsefulToken(tokens, i1, steps)
15751581
steps = (steps or 1)
@@ -1611,8 +1617,8 @@ local numberFormatters = {
16111617
}
16121618

16131619
-- newToken()
1614-
-- Create a new token. Different token types take different arguments.
16151620
-- token = newToken( tokenType, ... )
1621+
-- Create a new token. Different token types take different arguments.
16161622
--
16171623
-- commentToken = newToken( "comment", contents [, forceLongForm=false ] )
16181624
-- identifierToken = newToken( "identifier", identifier )
@@ -1780,8 +1786,8 @@ function metaFuncs.newToken(tokType, ...)
17801786
end
17811787

17821788
-- concatTokens()
1783-
-- Concatinate tokens by their representations.
17841789
-- luaString = concatTokens( tokens )
1790+
-- Concatenate tokens by their representations.
17851791
function metaFuncs.concatTokens(tokens)
17861792
return _concatTokens(tokens, nil, false, nil, nil)
17871793
end

0 commit comments

Comments
 (0)