Log in

View Full Version : Function string <-> int/float


WarpEnterprises
11th August 2002, 22:03
Wouldn't it be nice to have a conversion function between string and number in Avisynth? (mainly for script debugging=
e.g. it is not possible to display a number variable via Subtitle.
(Or did I miss something?)

dividee
11th August 2002, 22:08
I think you can do string --> number with eval, though I never really tried. Can't see a way to do number --> string, however. If nobody else can find it either, I'll add the function to avisynth.

Richard Berg
11th August 2002, 23:25
Also interesting might be string <-> array, i.e. make it where this kind of stuff (http://forum.doom9.org/showthread.php?s=&threadid=31081) would work with just one extra function call, e.g. Crop(ArrStr("string-of-args")).

If we can get a 'standard library' of functions going, this is easier to do via messing with Eval than hacking a new filter that can 'fake' multiple arguments.


function Arr2Str(string "filter", string "args")
{
Eval( filter + "(" + args + ")" )
}

function Arr2Str(string "filter", string "args", string "clipname")
{
Eval( filter + "(" + clipname + "," + args + ")")
}


Ok so that won't work yet, but playing around with that stuff has inspired a bunch more fixes:
can't overload functions...probably not too useful, but given dividee's penchant for making the language "expressive"... :)
function blocks don't inherit variables from the scope it's in. that's the main stumbling block to making something like the above work, and the biggest oversight listed here IMO
the tokenizer actually doesn't support Tex-style quotes as described in the docs. wouldn't be a big deal, except you're left with no way to do something like this:


#this works
hello="hello"
foo="hello, 640, 480, true, $ffffff, $666666, $000000"
return Eval( "messageclip" + "(" + foo + ")" )

#according to the docs, this should too
foo="``hello``, 640, 480, true, $ffffff, $666666, $000000"
return Eval( "messageclip" + "(" + foo + ")" )

dividee
14th August 2002, 02:10
There is quite I few things I discovered by reading avisynth source code and that have never been documented anywhere, AFAIK.

As you wrote, with your above function definition, this doesn't work:
fname="vid.avi"
Arr2Str("AVISource","fname")
Avisynth complains because the variable fname is not defined in the context of the function.
But this works:
global fname="test.avi"
Arr2Str("AVISource","fname")
global is a keyword that makes the variable available to all contexts. (note: in debug mode, an assertion refcount==0 fails when the ScriptEnvironment is destructed, so there must be a bug somewhere with global).

There are only two scopes: local or global. No nested scopes are possible. It is fairly trivial to change avisynth to have dynamic scope. In fact, dynamic scope is even easier than what exists now. I wonder why Ben didn't do it...

Another trick: exception handling
try {
AVISource("test.avi",true)
}
catch (e) {
#opening the avi with audio failed, let's try without audio
AVISource("test.avi",false)
}
Of course this works only when the exception is thrown when the script is interpreted, not when the filtergraph is running.

WarpEnterprises
14th August 2002, 11:39
Ahh, now I can add them to the doc (wasn't able to find out the exact syntax)
Btw.: can YOU tell me what the Catch(clip) function does?