Thread: AviSynth Q&A
View Single Post
Old 26th December 2017, 10:39   #108  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
RT_Stats:- https://forum.doom9.org/showthread.p...light=RT_Stats

Code:
RT_VarExist(string)
 Given the name (string) of the variable that you want to test for existence, returns true if exists, else false.
 Eg, #a=32
    RT_Debug(string(RT_VarExist("a")))  # would output 'false' to debugview unless '#a=32' uncommented. {Defined(a) would fail with error}.
    return colorbars()
Could also simulate (for Globals) with Try/Catch in script (within a function, and return as result).

EDIT:

Code:
Function VarType(String GlobalName) {
    Try {
	g = Eval(GlobalName) # Fail here if not exist
        res=    g.IsBool   ? 1
            \ : g.IsInt    ? 2
            \ : g.IsFloat  ? 3
            \ : g.IsString ? 4
            \ : g.IsClip   ? 5
            \ : 0
    } Catch (msg) {
        res = 0 # Not Exist
    }
    return res
}

Function VarTypeName(Int TypIx) {Assert(0 <= Typix <= 5,"VarTypeName: Bad Typix") Return Select(TypIx,"NOT_EXIST","Bool","Int","Float","String","Clip")}

Global G_i = 666   # Comment Me Out

Type = VarType("G_i")

TypeName=VarTypeName(Type)

MessageClip("Global G_i Type = "+String(Type) + " : TypeName='"+TypeName+"'")
EDITED:

EDIT: RT_VarExist just returns result of an Avisynth function, would do equivalent of VarExist on local of that name, and if failed then on Global of that name.
We cant test locals in script within a separate function, you would need to inline script try/catch in-situ if required for local.

EDIT: Something like
Code:
    Try {Dummy=Eval(LocalName) LocalExist=True} Catch(msg) {LocalExist=False} # Dummy, avoid assign anything to Last
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 26th December 2017 at 11:29.
StainlessS is offline   Reply With Quote