Skip to content

Commit 36f28e2

Browse files
committed
Added getCurrentPathIn() and getCurrentPathOut().
1 parent 947e41f commit 36f28e2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

preprocess.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- tokenize, newToken, concatTokens, removeUselessTokens, eachToken, isToken, getNextUsefulToken
2323
- toLua, serialize
2424
Only during processing:
25+
- getCurrentPathIn, getCurrentPathOut
2526
- outputValue, outputLua
2627
Search this file for 'EnvironmentTable' for more info.
2728
@@ -182,6 +183,8 @@ local isDebug = false
182183
local currentErrorHandler = _error
183184

184185
local isRunningMeta = false
186+
local currentPathIn = ""
187+
local currentPathOut = ""
185188
local metaPathForErrorMessages = ""
186189
local outputFromMeta = nil
187190

@@ -1049,6 +1052,20 @@ function metaFuncs.outputLua(...)
10491052
end
10501053
end
10511054

1055+
-- getCurrentPathIn()
1056+
-- Get what file is currently being processed, if any.
1057+
-- path = getCurrentPathIn( )
1058+
function metaFuncs.getCurrentPathIn()
1059+
return currentPathIn
1060+
end
1061+
1062+
-- getCurrentPathOut()
1063+
-- Get what file the currently processed file will be written to, if any.
1064+
-- path = getCurrentPathOut( )
1065+
function metaFuncs.getCurrentPathOut()
1066+
return currentPathOut
1067+
end
1068+
10521069
-- tokenize()
10531070
-- Convert Lua code to tokens. Returns nil and a message on error. (See newToken() for token types.)
10541071
-- tokens, error = tokenize( luaString [, allowPreprocessorTokens=false ] )
@@ -1324,6 +1341,9 @@ local function _processFileOrString(params, isFile)
13241341
errorline("Could not read file: "..err)
13251342
end
13261343

1344+
currentPathIn = params.pathIn
1345+
currentPathOut = params.pathOut
1346+
13271347
else
13281348
pathIn = "<code>"
13291349
luaUnprocessed = params.code
@@ -1749,6 +1769,9 @@ local function _processFileOrString(params, isFile)
17491769

17501770
if params.onDone then params.onDone(info) end
17511771

1772+
currentPathIn = ""
1773+
currentPathOut = ""
1774+
17521775
if isFile then
17531776
return info
17541777
else
@@ -1786,6 +1809,8 @@ local function processFileOrString(params, isFile)
17861809

17871810
-- Cleanup in case an error happened.
17881811
isRunningMeta = false
1812+
currentPathIn = ""
1813+
currentPathOut = ""
17891814
metaPathForErrorMessages = ""
17901815
outputFromMeta = nil
17911816

0 commit comments

Comments
 (0)