Log in

View Full Version : How to handle optional parameters in Avisynth plugins?


Mini-Me
23rd July 2012, 23:41
I'm writing a C++ Avisynth plugin, and I haven't been able to find any references to optional parameters in the Filter SDK. What mechanism does Avisynth provide for checking whether the user actually passed in a value for an optional named parameter?

I know that you can pass a default value into AsInt(), AsString(), etc., but what about AsClip()? I suppose you can use the PClip() constructor to create a default clip, but what's the best way to differentiate that empty clip from a real one that was actually passed in? Would [clip].vi.HasVideo() work?

IanB
24th July 2012, 00:04
The parser calls your registered create routine with an AVSValue args. This will be an array variant of AVSValue, each array element maps ordinally to your argument definition string. Optional arguments that were not included in the script are an AVSValue of the variant type Undefined.

So to test if the 2nd argument was provided :-...
if (args[1].Defined()) {
// code for yes
fred = args[1].AsClip();
}
else {
// code for no
fred = some other default clip;
}
...

Mini-Me
24th July 2012, 00:11
The parser calls your registered create routine with an AVSValue args. This will be an array variant of AVSValue, each array element maps ordinally to your argument definition string. Optional arguments that were not included in the script are an AVSValue of the variant type Undefined.

So to test if the 2nd argument was provided :-...
if (args[1].Defined()) {
// code for yes
fred = args[1].AsClip();
}
else {
// code for no
fred = some other default clip;
}
...

Perfect. Thanks, Ian!