Skip to content

Commit 9c23577

Browse files
committed
Command line: Exposed params.backtickStrings and params.canOutputNil through --backtickstrings and --nonil options.
1 parent 8a58d2f commit 9c23577

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

preprocess-cl.lua

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ exec lua "$0" "$@"
2727
lua preprocess-cl.lua --outputpaths --linenumbers src/main.lua2p output/main.lua src/network.lua2p output/network.lua
2828
2929
Options:
30+
--backtickstrings
31+
Enable the backtick (`) to be used as string literal delimiters.
32+
Backtick strings don't interpret any escape sequences and can't
33+
contain other backticks.
34+
3035
--data|-d="Any data."
3136
A string with any data. If the option is present then the value
3237
will be available through the global 'dataFromCommandLine' in the
@@ -49,6 +54,9 @@ exec lua "$0" "$@"
4954
if an error happens in the metaprogram. This file is removed if
5055
there's no error and --debug isn't enabled.
5156
57+
--nonil
58+
Disallow !() and outputValue() to output nil.
59+
5260
--outputextension=fileExtension
5361
Specify what file extension generated files should have. The
5462
default is "lua". If any input files end in .lua then you must
@@ -141,15 +149,17 @@ if not args[0] then error("Expected to run from the Lua interpreter.") end
141149
local pp = dofile((args[0]:gsub("[^/\\]+$", "preprocess.lua")))
142150

143151
-- From args:
144-
local addLineNumbers = false
145-
local customData = nil
146-
local hasOutputExtension = false
147-
local hasOutputPaths = false
148-
local isDebug = false
149-
local outputExtension = "lua"
150-
local outputMeta = false
151-
local processingInfoPath = ""
152-
local silent = false
152+
local addLineNumbers = false
153+
local allowBacktickStrings = false
154+
local canOutputNil = true
155+
local customData = nil
156+
local hasOutputExtension = false
157+
local hasOutputPaths = false
158+
local isDebug = false
159+
local outputExtension = "lua"
160+
local outputMeta = false
161+
local processingInfoPath = ""
162+
local silent = false
153163

154164
--==============================================================
155165
--= Local Functions ============================================
@@ -233,6 +243,9 @@ for _, arg in ipairs(args) do
233243
elseif arg:find"^%-%-data=" or arg:find"^%-d=" then
234244
customData = arg:match"^%-%-data=(.*)$" or arg:match"^%-d=(.*)$"
235245

246+
elseif arg == "--backtickstrings" then
247+
allowBacktickStrings = true
248+
236249
elseif arg == "--debug" then
237250
isDebug = true
238251
outputMeta = true
@@ -246,6 +259,9 @@ for _, arg in ipairs(args) do
246259
elseif arg == "--meta" then
247260
outputMeta = true
248261

262+
elseif arg == "--nonil" then
263+
canOutputNil = false
264+
249265
elseif arg:find"^%-%-outputextension=" then
250266
if hasOutputPaths then
251267
errorline("Cannot specify both --outputextension and --outputpaths")
@@ -410,12 +426,15 @@ for i, pathIn in ipairs(pathsIn) do
410426
end
411427

412428
local info = pp.processFile{
413-
pathIn = pathIn,
414-
pathMeta = pathMeta,
415-
pathOut = pathOut,
429+
pathIn = pathIn,
430+
pathMeta = pathMeta,
431+
pathOut = pathOut,
432+
433+
debug = isDebug,
434+
addLineNumbers = addLineNumbers,
416435

417-
debug = isDebug,
418-
addLineNumbers = addLineNumbers,
436+
backtickStrings = allowBacktickStrings,
437+
canOutputNil = canOutputNil,
419438

420439
onInsert = (hasMessageHandler("insert") or nil) and function(name)
421440
local lua = sendMessage("insert", pathIn, name)

preprocess.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,7 @@ local lib = {
21302130
-- addLineNumbers = boolean -- [Optional] Add comments with line numbers to the output.
21312131
-- debug = boolean -- [Optional] Debug mode. The metaprogram file is formatted more nicely and does not get deleted automatically.
21322132
--
2133-
-- backtickStrings = boolean -- [Optional] Enable the backtick (`) to be used as string literal delimiters. Backtick strings don't interpret any escape sequences and can't contain backticks. (Default: false)
2133+
-- backtickStrings = boolean -- [Optional] Enable the backtick (`) to be used as string literal delimiters. Backtick strings don't interpret any escape sequences and can't contain other backticks. (Default: false)
21342134
-- canOutputNil = boolean -- [Optional] Allow !() and outputValue() to output nil. (Default: true)
21352135
--
21362136
-- onInsert = function( name ) -- [Optional] Called for each @insert statement. It's expected to return a Lua string. By default 'name' is a path to a file to be inserted.
@@ -2153,7 +2153,7 @@ local lib = {
21532153
-- addLineNumbers = boolean -- [Optional] Add comments with line numbers to the output.
21542154
-- debug = boolean -- [Optional] Debug mode. The metaprogram file is formatted more nicely and does not get deleted automatically.
21552155
--
2156-
-- backtickStrings = boolean -- [Optional] Enable the backtick (`) to be used as string literal delimiters. Backtick strings don't interpret any escape sequences and can't contain backticks. (Default: false)
2156+
-- backtickStrings = boolean -- [Optional] Enable the backtick (`) to be used as string literal delimiters. Backtick strings don't interpret any escape sequences and can't contain other backticks. (Default: false)
21572157
-- canOutputNil = boolean -- [Optional] Allow !() and outputValue() to output nil. (Default: true)
21582158
--
21592159
-- onInsert = function( name ) -- [Optional] Called for each @insert statement. It's expected to return a Lua string. By default 'name' is a path to a file to be inserted.

0 commit comments

Comments
 (0)