Пример #1
0
 public sealed override void Initialize(AVSValue args, ScriptEnvironment env)
 {
     try
     {
         using (new DynamicEnvironment(env))
         {
             OverlayUtils.InitArgs(this, args);
             Initialize(args);
             base.Initialize(args, env);
         }
         topLevel = new DynamicEnvironment(env, false);
         AfterInitialize();
         topLevel.Detach();
     }
     catch (Exception ex)
     {
         try
         {
             DisposeAll();
         }
         catch
         {
             // ignored
         }
         finally
         {
             if (ex is SEHException)
             {
                 throw new AvisynthException("Runtime function call error: " + DynamicEnvironment.LastError);
             }
             DynamicEnvironment.LastError = ex.Message;
             throw new AvisynthException(ex.Message);
         }
     }
 }
Пример #2
0
        public static AVSValue ToAvsValue(this object val)
        {
            if (val == null)
            {
                return(new AVSValue());
            }
            if (val is DynamicEnvironment)
            {
                val = ((DynamicEnvironment)val).Clip;
            }
            if (val is Clip clip)
            {
                var cached = DynamicEnvironment.FindClip(clip);
                if (cached != null)
                {
                    return(cached);
                }
            }

            if (!(val is string) && val is IEnumerable array)
            {
                return(new AVSValue(array.OfType <object>().Select(ToAvsValue).ToArray()));
            }
            var ctor = typeof(AVSValue).GetConstructor(new[] { val.GetType() });

            if (ctor == null)
            {
                throw new AvisynthException($"Wrong type '{val.GetType()}' for {nameof(AVSValue)} instantiation");
            }
            return((AVSValue)ctor.Invoke(new[] { val }));
        }
Пример #3
0
 public sealed override void Initialize(AVSValue args, ScriptEnvironment env)
 {
     try
     {
         using (new DynamicEnvironment(env))
         {
             OverlayUtils.InitArgs(this, args);
             Initialize(args);
             base.Initialize(args, env);
         }
         topLevel = new DynamicEnvironment(env, false);
         AfterInitialize();
         topLevel.Detach();
     }
     catch (Exception ex)
     {
         try
         {
             DisposeAll();
         }
         finally
         {
             throw ex;
         }
     }
 }
Пример #4
0
 protected override void Dispose(bool disposing)
 {
     Filters.Remove(this);
     base.Dispose(disposing);
     OverlayUtils.Dispose(this);
     topLevel?.Dispose();
     topLevel = null;
 }