wonkey_monkey
19th February 2022, 17:18
Download: shebang_mod.zip (https://horman.net/avisynth/download/shebang_mod.zip)
Now based on Avisynth+ 3.7.2
As mentioned here (https://forum.doom9.org/showthread.php?p=1963678), I had an idea to add a script pre-processor to AviSynth to allow for plugins that could free up the grammar a bit, or perform other tricks, while maximising backwards compatability and not putting any new restrictions on script writers or AviSynth itself.
I've managed to make it work with a short modification to scriptparser.cpp. Compiled AviSynth DLLs (based on 3.7.2 from https://github.com/AviSynth/AviSynthPlus) are in the zip file above along with an example preprocessing plugin (ScriptMonkey.dll) and a couple of example scripts, as well as the modified scriptparser.cpp and a diff file.
Preprocessing is triggered by a shebang (https://en.wikipedia.org/wiki/Shebang_(Unix)) ("#!") as the first characters of the first (and any immediately following) lines of the script, followed by the name of any function which takes a string as input and returns a string (the function name can be optionally followed by comments, as below):
#!revstr <- this internal AviSynth function reverses the characters of the script (including the order of lines)
21VYoTtrevnoC
srabroloC
As a more useful example, the included ScriptMonkey plugin reformats scripts so you no longer need to use backslashes to continue lines (within function parameter lists only), and allows inter-parameter # comments and trailing commas, so function parameters can be quickly and easily commented out:
#!ScriptMonkey <- this line enables the script
# The ScriptMonkey plugin function allows multi-line parameters without
# requiring backslashes (\) for line continuation, # comments in the middle of
# multi-line parameters, and trailing commas in parameter lists.
ColorBarsHD
ConvertToYV12(
interlaced = true,
matrix = "rec709", # this trailing comma is now allowed
# chromaresample = "point" # this parameter is commented out
)
I put it together pretty quickly so if anyone wants to look at the source code and see if I've made any mistakes I'd appreciate it.
Now based on Avisynth+ 3.7.2
As mentioned here (https://forum.doom9.org/showthread.php?p=1963678), I had an idea to add a script pre-processor to AviSynth to allow for plugins that could free up the grammar a bit, or perform other tricks, while maximising backwards compatability and not putting any new restrictions on script writers or AviSynth itself.
I've managed to make it work with a short modification to scriptparser.cpp. Compiled AviSynth DLLs (based on 3.7.2 from https://github.com/AviSynth/AviSynthPlus) are in the zip file above along with an example preprocessing plugin (ScriptMonkey.dll) and a couple of example scripts, as well as the modified scriptparser.cpp and a diff file.
Preprocessing is triggered by a shebang (https://en.wikipedia.org/wiki/Shebang_(Unix)) ("#!") as the first characters of the first (and any immediately following) lines of the script, followed by the name of any function which takes a string as input and returns a string (the function name can be optionally followed by comments, as below):
#!revstr <- this internal AviSynth function reverses the characters of the script (including the order of lines)
21VYoTtrevnoC
srabroloC
As a more useful example, the included ScriptMonkey plugin reformats scripts so you no longer need to use backslashes to continue lines (within function parameter lists only), and allows inter-parameter # comments and trailing commas, so function parameters can be quickly and easily commented out:
#!ScriptMonkey <- this line enables the script
# The ScriptMonkey plugin function allows multi-line parameters without
# requiring backslashes (\) for line continuation, # comments in the middle of
# multi-line parameters, and trailing commas in parameter lists.
ColorBarsHD
ConvertToYV12(
interlaced = true,
matrix = "rec709", # this trailing comma is now allowed
# chromaresample = "point" # this parameter is commented out
)
I put it together pretty quickly so if anyone wants to look at the source code and see if I've made any mistakes I'd appreciate it.