@@ -116,16 +116,16 @@ local ESCAPE_SEQUENCES = {
116116
117117local ERROR_UNFINISHED_VALUE = 1
118118
119- local _error = error
119+ local _error = error
120120
121- local metaEnv = nil
121+ local metaEnv = nil
122122
123- local isDebug = false
124- local onError = _error
123+ local isDebug = false
124+ local onError = _error
125125
126- local isRunningMeta = false
127- local currentMetaPath = " "
128- local outputFromMeta = nil
126+ local isRunningMeta = false
127+ local metaPathForErrorMessages = " "
128+ local outputFromMeta = nil
129129
130130-- ==============================================================
131131-- = Local Functions ============================================
@@ -740,7 +740,7 @@ function metaFuncs.outputValue(...)
740740 if argCount == 0 then
741741 error (" No values to output." , 2 )
742742 -- local ln = debug.getinfo(2, "l").currentline
743- -- errorOnLine(currentMetaPath , ln, "MetaProgram", "No values to output.")
743+ -- errorOnLine(metaPathForErrorMessages , ln, "MetaProgram", "No values to output.")
744744 end
745745
746746 for i = 1 , argCount do
@@ -749,7 +749,7 @@ function metaFuncs.outputValue(...)
749749
750750 if not ok then
751751 local ln = debug.getinfo (2 , " l" ).currentline
752- errorOnLine (currentMetaPath , ln , " MetaProgram" , " %s" , err )
752+ errorOnLine (metaPathForErrorMessages , ln , " MetaProgram" , " %s" , err )
753753 end
754754 end
755755end
@@ -764,7 +764,7 @@ function metaFuncs.outputLua(...)
764764 if argCount == 0 then
765765 error (" No Lua code to output." , 2 )
766766 -- local ln = debug.getinfo(2, "l").currentline
767- -- errorOnLine(currentMetaPath , ln, "MetaProgram", "No Lua code to output.")
767+ -- errorOnLine(metaPathForErrorMessages , ln, "MetaProgram", "No Lua code to output.")
768768 end
769769
770770 for i = 1 , argCount do
@@ -936,9 +936,8 @@ metaEnv.__LUA = metaEnv.outputLua
936936
937937
938938local function _processFile (params )
939- if not params .pathIn then error (" Missing 'pathIn' in params." , 2 ) end
940- if not params .pathMeta then error (" Missing 'pathMeta' in params." , 2 ) end
941- if not params .pathOut then error (" Missing 'pathOut' in params." , 2 ) end
939+ if not params .pathIn then error (" Missing 'pathIn' in params." , 2 ) end
940+ if not params .pathOut then error (" Missing 'pathOut' in params." , 2 ) end
942941
943942 local luaUnprocessed , err = getFileContents (params .pathIn )
944943 if not luaUnprocessed then
@@ -1205,17 +1204,19 @@ local function _processFile(params)
12051204 print("====================================")
12061205 --]]
12071206
1208- currentMetaPath = params .pathMeta
1207+ metaPathForErrorMessages = params .pathMeta or " <meta> "
12091208 outputFromMeta = {}
12101209
1211- local file = assert (io.open (currentMetaPath , " wb" ))
1212- file :write (luaMeta )
1213- file :close ()
1210+ if params .pathMeta then
1211+ local file = assert (io.open (params .pathMeta , " wb" ))
1212+ file :write (luaMeta )
1213+ file :close ()
1214+ end
12141215
1215- local chunk , err = loadstring (luaMeta , currentMetaPath )
1216+ local chunk , err = loadstring (luaMeta , metaPathForErrorMessages )
12161217 if not chunk then
12171218 local ln , err = err :match ' ^%[string ".-"%]:(%d+): (.*)'
1218- errorOnLine (currentMetaPath , tonumber (ln ), nil , " %s" , err )
1219+ errorOnLine (metaPathForErrorMessages , tonumber (ln ), nil , " %s" , err )
12191220 end
12201221 setfenv (chunk , metaEnv )
12211222
@@ -1232,8 +1233,8 @@ local function _processFile(params)
12321233 end )
12331234 isRunningMeta = false
12341235
1235- if not isDebug then
1236- os.remove (currentMetaPath )
1236+ if not isDebug and params . pathMeta then
1237+ os.remove (params . pathMeta )
12371238 end
12381239
12391240 local lua = table.concat (outputFromMeta )
@@ -1243,8 +1244,8 @@ local function _processFile(params)
12431244 print("====================================")
12441245 --]]
12451246
1246- currentMetaPath = " "
1247- outputFromMeta = nil
1247+ metaPathForErrorMessages = " "
1248+ outputFromMeta = nil
12481249
12491250 if params .onAfterMeta then params .onAfterMeta (lua ) end
12501251
@@ -1295,9 +1296,9 @@ local function processFile(params)
12951296 onError = _error
12961297
12971298 -- Cleanup in case an error happened.
1298- isRunningMeta = false
1299- currentMetaPath = " "
1300- outputFromMeta = nil
1299+ isRunningMeta = false
1300+ metaPathForErrorMessages = " "
1301+ outputFromMeta = nil
13011302
13021303 return info , err
13031304end
@@ -1319,7 +1320,7 @@ local lib = {
13191320 --
13201321 -- params: Table with these fields:
13211322 -- pathIn = pathToInputFile -- [Required]
1322- -- pathMeta = pathForMetaprogram -- [Required ] You can inspect this temporary output file if an error ocurrs in the metaprogram.
1323+ -- pathMeta = pathForMetaprogram -- [Optional ] You can inspect this temporary output file if an error ocurrs in the metaprogram.
13231324 -- pathOut = pathToOutputFile -- [Required]
13241325 --
13251326 -- addLineNumbers = boolean -- [Optional] Add comments with line numbers to the output.
0 commit comments