|
1 | 1 | --[[============================================================
|
2 | 2 | --=
|
3 |
| ---= LuaPreprocess v1.20-dev - preprocessing library |
| 3 | +--= LuaPreprocess v1.21 - preprocessing library |
4 | 4 | --= by Marcus 'ReFreezed' Thunström
|
5 | 5 | --=
|
6 | 6 | --= License: MIT (see the bottom of this file)
|
|
17 | 17 | - copyTable
|
18 | 18 | - escapePattern
|
19 | 19 | - getIndentation
|
| 20 | + - isProcessing |
20 | 21 | - pack
|
21 | 22 | - pairsSorted
|
22 | 23 | - printf
|
|
131 | 132 |
|
132 | 133 |
|
133 | 134 |
|
134 |
| -local PP_VERSION = "1.20.0-dev" |
| 135 | +local PP_VERSION = "1.21.0" |
135 | 136 |
|
136 | 137 | local MAX_DUPLICATE_FILE_INSERTS = 1000 -- @Incomplete: Make this a parameter for processFile()/processString().
|
137 | 138 | local MAX_CODE_LENGTH_IN_MESSAGES = 60
|
@@ -2258,24 +2259,39 @@ local function isCallable(v)
|
2258 | 2259 | end
|
2259 | 2260 |
|
2260 | 2261 | -- callMacro()
|
2261 |
| --- luaString = callMacro( macroName, argument1, ... ) |
2262 |
| --- Call a macro function (which must be a global in metaEnvironment). |
| 2262 | +-- luaString = callMacro( function|macroName, argument1, ... ) |
| 2263 | +-- Call a macro function (which must be a global in metaEnvironment if macroName is given). |
2263 | 2264 | -- The arguments should be Lua code strings.
|
2264 |
| -function metaFuncs.callMacro(name, ...) |
| 2265 | +function metaFuncs.callMacro(nameOrFunc, ...) |
2265 | 2266 | errorIfNotRunningMeta(2)
|
2266 | 2267 |
|
2267 |
| - local nameResult = current_parsingAndMeta_macroPrefix .. name .. current_parsingAndMeta_macroSuffix |
2268 |
| - local f = metaEnv[nameResult] |
| 2268 | + assertarg(1, nameOrFunc, "string","function") |
| 2269 | + local f |
2269 | 2270 |
|
2270 |
| - if not isCallable(f) then |
2271 |
| - if name == nameResult |
2272 |
| - then errorf(2, "'%s' is not a macro/global function. (Got %s)", name, type(f)) |
2273 |
| - else errorf(2, "'%s' (resolving to '%s') is not a macro/global function. (Got %s)", name, nameResult, type(f)) end |
| 2271 | + if type(nameOrFunc) == "string" then |
| 2272 | + local nameResult = current_parsingAndMeta_macroPrefix .. nameOrFunc .. current_parsingAndMeta_macroSuffix |
| 2273 | + f = metaEnv[nameResult] |
| 2274 | + |
| 2275 | + if not isCallable(f) then |
| 2276 | + if nameOrFunc == nameResult |
| 2277 | + then errorf(2, "'%s' is not a macro/global function. (Got %s)", nameOrFunc, type(f)) |
| 2278 | + else errorf(2, "'%s' (resolving to '%s') is not a macro/global function. (Got %s)", nameOrFunc, nameResult, type(f)) end |
| 2279 | + end |
| 2280 | + |
| 2281 | + else |
| 2282 | + f = nameOrFunc |
2274 | 2283 | end
|
2275 | 2284 |
|
2276 | 2285 | return (metaEnv.__M()(f(...)))
|
2277 | 2286 | end
|
2278 | 2287 |
|
| 2288 | +-- isProcessing() |
| 2289 | +-- bool = isProcessing( ) |
| 2290 | +-- Returns true if a file or string is currently being processed. |
| 2291 | +function metaFuncs.isProcessing() |
| 2292 | + return current_parsingAndMeta_isProcessing |
| 2293 | +end |
| 2294 | + |
2279 | 2295 | -- :PredefinedMacros
|
2280 | 2296 |
|
2281 | 2297 | -- ASSERT()
|
@@ -3816,7 +3832,7 @@ local pp = {
|
3816 | 3832 | -- logLevel = levelName -- [Optional] Maximum log level for the @@LOG() macro. Can be "off", "error", "warning", "info", "debug" or "trace". (Default: "trace", which enables all logging)
|
3817 | 3833 | --
|
3818 | 3834 | -- onInsert = function( name ) -- [Optional] Called for each @insert"name" instruction. It's expected to return a Lua code string. By default 'name' is a path to a file to be inserted.
|
3819 |
| - -- onBeforeMeta = function( luaString ) -- [Optional] Called before the metaprogram runs. luaString contains the metaprogram. |
| 3835 | + -- onBeforeMeta = function( luaString ) -- [Optional] Called before the metaprogram runs, if a metaprogram is generated. luaString contains the metaprogram. |
3820 | 3836 | -- onAfterMeta = function( luaString ) -- [Optional] Here you can modify and return the Lua code before it's written to 'pathOut'.
|
3821 | 3837 | -- onError = function( error ) -- [Optional] You can use this to get traceback information. 'error' is the same value as what is returned from processFile().
|
3822 | 3838 | --
|
@@ -3849,7 +3865,7 @@ local pp = {
|
3849 | 3865 | -- logLevel = levelName -- [Optional] Maximum log level for the @@LOG() macro. Can be "off", "error", "warning", "info", "debug" or "trace". (Default: "trace", which enables all logging)
|
3850 | 3866 | --
|
3851 | 3867 | -- onInsert = function( name ) -- [Optional] Called for each @insert"name" instruction. It's expected to return a Lua code string. By default 'name' is a path to a file to be inserted.
|
3852 |
| - -- onBeforeMeta = function( luaString ) -- [Optional] Called before the metaprogram runs. luaString contains the metaprogram. |
| 3868 | + -- onBeforeMeta = function( luaString ) -- [Optional] Called before the metaprogram runs, if a metaprogram is generated. luaString contains the metaprogram. |
3853 | 3869 | -- onError = function( error ) -- [Optional] You can use this to get traceback information. 'error' is the same value as the second returned value from processString().
|
3854 | 3870 | --
|
3855 | 3871 | processString = processString,
|
|
0 commit comments