Log in

View Full Version : Help with (“$Plugin!Functionname!Param$“)


Ebobtron
13th November 2005, 18:22
Hello,
I could use some more help, please.

Trying to collect the data returned by the statement.

AVSValue myobject = env->GetVar(“$Plugin!Functionname!Param$“)

So far, for each "!Functionname!" I use, “IsDefined()” and “IsString()” return TRUE;

Using “myobject.AsString()” crashes.

The other “AsString(const char* def)” is beyond me, I do not understand what argument should be passed to AsString(???).

Can some one please explain or provide an example.

I have a alpha demo of FilmCutter with an external function pick list you can find here:http://forum.doom9.org/showthread.php?p=737073#post737073


Thanks a lot in advance.

Eobtron
http://members.aol.com/avsfilmcutter

Fizick
14th November 2005, 00:07
It seems,
this works for internal functions only. :(

const char * myobject = env->GetVar("$Plugin!ConverttoYV12!Param$").AsString()
env->ThrowError(myobject);

Fizick
14th November 2005, 17:12
My question about this:

http://forum.doom9.org/showthread.php?p=729098#post729098

Internal and external (plugin) functions are exported as AviSynth Variables.

$InternalFunctions$ Should contain function names of all internal functions.
$InternalFunctions!Functionname!Param$ Should contain all parameters for each internal function.
$PluginFunctions$ Should contain all plugins.
$Plugin!Functionname!Param$ Should contain all parameters.

Use env->GetVar() to access them.

Can somebody fixed this bug in Avisynth 2.5.7 ?

Fizick
14th November 2005, 20:05
I found the bug in avisynth.cpp. Here is part of the code.
I commented old code and adde new.


char temp[1024] = "$Plugin!";
strcat(temp, name);
strcat(temp, "!Param$");
// env->SetGlobalVar(env->SaveString(temp, 8+strlen(name)+7+1), AVSValue(params));
// it does not work (null param)
env->SetGlobalVar(env->SaveString(temp, 8+strlen(name)+7+1), AVSValue(f->param_types)); // Fizick
if (alt_name) {
strcpy(temp, "$Plugin!");
strcat(temp, alt_name);
strcat(temp, "!Param$");
env->SetGlobalVar(env->SaveString(temp, 8+strlen(alt_name)+7+1), AVSValue(f->param_types));
}


Here is fixed avisyth.dll (temporary). Ebobtron, try it.
http://www.avisynth.org/fizick/temp/avisynth.dll

IanB, please put the fix to 2.5.7 alpha (after checking my code)
I am still afraid put anything to CVS. :)

Ebobtron
14th November 2005, 21:13
Hi all,

Fizick,
You fixed it, ( $Plugin!Functionname!Param$ ) returns Function params for both internal and external functions.

See here:http://members.aol.com/avsfilmcutter/External_Function_Params.html
Above link broken

@Fizick, what is up with all the caps?

Did I miss 2.5.6 going final I have been very busy.

Fantastic Fizick, great catch. Now I can work on params helper, for externals too.

Ebobtron
http://members.aol.com/avsfilmcutter

Fizick
14th November 2005, 21:46
Ebobtron,
Go ahead,
Internal functions are work in 2.5.6 release right now,
I hope my bugfix will be in 2.5.7 for external plugins too.

I see in your list, that my functions params are longest, but Peach is not short too. :)

Fizick
14th November 2005, 21:50
And please remember alternative function names,
such as "defreq_DeFreq"

Ebobtron
14th November 2005, 22:02
Ebobtron,
I see in your list, that my functions params are longest, but Peach is not short too. :)
Would not be so long if they where smaller. :rolleyes:

And please remember alternative function names,
such as "defreq_DeFreq"Da.

ebt
http://members.aol.com/avsfilmcutter

Fizick
14th November 2005, 22:12
Uppercase names is not important, you may use lowcase instead.
avisynth is not case-sensetive.

IanB
15th November 2005, 05:56
@Fizick,

Nice one, I will upload the fix in my next batch to CVS

Gavino
17th April 2010, 01:00
I know this thread is several years old, but it holds the key to a mysterious problem affecting AvsP (and potentially other applications too).

It turns out Fizick's code in post #4 above (incorporated in FunctionTable::AddFunction) has a subtle error.
When writing a plugin function's parameter types to the corresponding AVS variable, a copy of the string pointer in f->param_types is saved. However, the string addressed by this pointer is freed the first time a function in the plugin is called (when FunctionTable::Lookup calls RemovePlugin after reloading the plugin), so the value of the AVS variable is likely to be corrupted soon afterwards. If an application processes the string after this point, it will see garbage.

With AvsP, this can occur if a function from an auto-loaded plugin is called from an auto-loaded .avsi file, eg
global AviSynthPluginsDir = GetWorkingDir()
It shows up as AvsP producing an error message "Error parsing <xxx> plugin parameters: unknown character <x>".
The symptoms have been reported several times in the past (eg here, here, and just recently here), but never properly understood till now.

The solution (as usual!) is to use SaveString when writing the parameter string to the AVS variable, ie
env->SetGlobalVar(env->SaveString(temp, 8+strlen(name)+7+1), AVSValue(f->param_types)); // Fizick
should be
env->SetGlobalVar(env->SaveString(temp, 8+strlen(name)+7+1),
AVSValue(env->SaveString(f->param_types))); // Gavino ;)
and similarly for f2->param_types.

Incidentally, it seems to me that this entire scheme has a basic flaw in it. Avisynth allows overloaded function names (two or more functions with the same name, but different parameters). However, the $Plugin!name!Param$ string can only store one set of parameters, the last one processed for a given function name overwrites any previous one. Is this intended?

(Another puzzling thing during auto-loading is that LoadPluginsMatching("*.vdf") is called, but this only ever calls LoadPlugin, not LoadVirtualdubPlugin. :confused:)

IanB
17th April 2010, 03:26
Well spotted. I got rid of all the _strdups/frees so all the names and arglists are now SaveString'd.

Yes function list and args exporting is pretty gross. Maybe we can define a new better one.

The LoadPluginsMatching("*.vdf") is probably a leftover from someone's misguided attempt to autoload VDub plugins. Maybe I should remove it. When loading VFAPI and VDub plugins you need to provide a function name. Doh!

Gavino
17th April 2010, 09:55
Yes function list and args exporting is pretty gross.
Another oddity is that, as well as saving plugin function names in $PluginFunctions$, internal function names are saved in $InternalFunctions$, but their parameter types are saved in $Plugin!name!Param$, contradicting post#3 above.