Skip to content

Commit 659d6d0

Browse files
committed
Command line: Added --data option.
1 parent 36f28e2 commit 659d6d0

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

misc/runTest.cmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ CD /D "%~dp0.."
33

44
IF NOT EXIST local MD local
55

6-
lua preprocess-cl.lua --debug --saveinfo=local/info.lua misc/test.lua2p
7-
REM lua preprocess-cl.lua --debug --saveinfo=local/info.lua misc/test.lua2p --linenumbers
6+
lua preprocess-cl.lua --debug --saveinfo=local/info.lua --data="Hello, world!" misc/test.lua2p
7+
REM lua preprocess-cl.lua --debug --saveinfo=local/info.lua --data="Hello, world!" misc/test.lua2p --linenumbers

misc/test.lua2p

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ print(s:match(ident)) -- "hello5"
5858
print(s:match(num)) -- "2"
5959
print(s:match(funcCall)) -- "hello5( foo )"
6060

61+
print(!("dataFromCommandLine: "..tostring(dataFromCommandLine)))
6162
print("The end.")
6263

6364
!(

preprocess-cl.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ exec lua "$0" "$@"
1818
lua preprocess-cl.lua [options] [--] filepath1 [filepath2 ...]
1919
2020
Options:
21+
--data="Any data."
22+
A string with any data. If the option is present then the value
23+
will be available through the global 'dataFromCommandLine' in the
24+
processed files (and the message handler, if you have one).
25+
2126
--handler=pathToMessageHandler
2227
Path to a Lua file that's expected to return a function or a
2328
table of functions. If it returns a function then it will be
@@ -121,6 +126,7 @@ local outputExtension = "lua"
121126
local processingInfoPath = ""
122127
local silent = false
123128
local outputMeta = false
129+
local customData = nil
124130

125131
--==============================================================
126132
--= Local Functions ============================================
@@ -216,6 +222,9 @@ for _, arg in ipairs(args) do
216222
elseif arg:find"^%-%-outputextension=" then
217223
outputExtension = arg:match"^%-%-outputextension=(.*)$"
218224

225+
elseif arg:find"^%-%-data=" then
226+
customData = arg:match"^%-%-data=(.*)$"
227+
219228
elseif arg == "--meta" then
220229
outputMeta = true
221230

@@ -239,6 +248,11 @@ printfNoise(("="):rep(#header))
239248

240249

241250

251+
-- Prepare metaEnvironment.
252+
pp.metaEnvironment.dataFromCommandLine = customData -- May be nil.
253+
254+
255+
242256
-- Load message handler.
243257
local messageHandler = nil
244258

0 commit comments

Comments
 (0)