<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://avisynth.nl/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://avisynth.nl/index.php?action=history&amp;feed=atom&amp;title=Function_objects</id>
		<title>Function objects - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://avisynth.nl/index.php?action=history&amp;feed=atom&amp;title=Function_objects"/>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php?title=Function_objects&amp;action=history"/>
		<updated>2026-04-07T22:03:52Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.19.24</generator>

	<entry>
		<id>http://avisynth.nl/index.php?title=Function_objects&amp;diff=13353&amp;oldid=prev</id>
		<title>111.119.49.91: remove orphaned div closing tag</title>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php?title=Function_objects&amp;diff=13353&amp;oldid=prev"/>
				<updated>2024-05-17T03:04:48Z</updated>
		
		<summary type="html">&lt;p&gt;remove orphaned div closing tag&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr valign='top'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 03:04, 17 May 2024&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 191:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 191:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;----&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;----&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Back to [[AviSynth Syntax]].&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Back to [[AviSynth Syntax]].&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;[[Category:Internal_functions]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;[[Category:Internal_functions]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;[[Category:AviSynth_Syntax]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;[[Category:AviSynth_Syntax]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;[[Category:Scripting_Basics]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;[[Category:Scripting_Basics]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>111.119.49.91</name></author>	</entry>

	<entry>
		<id>http://avisynth.nl/index.php?title=Function_objects&amp;diff=12230&amp;oldid=prev</id>
		<title>Pinterf: Function objects: add content</title>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php?title=Function_objects&amp;diff=12230&amp;oldid=prev"/>
				<updated>2021-02-11T07:43:13Z</updated>
		
		<summary type="html">&lt;p&gt;Function objects: add content&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Function object basics ==&lt;br /&gt;
&lt;br /&gt;
Concept of function objects was introduced in Avisynth Neo and was backported to Avisynth+ (avaliable from v3.6).&lt;br /&gt;
Function object is a new variable type. Once declared, they can be assigned to a variable, and use as function arguments.&lt;br /&gt;
Internal functions can be casted to function objects, helpes a cleaner syntax for some existing internal function (e.g. ScriptClip).&lt;br /&gt;
&lt;br /&gt;
A user defined function or an external plugin can even take such type as an argument in the parameter list.&lt;br /&gt;
&lt;br /&gt;
'''Basic example'''&lt;br /&gt;
&lt;br /&gt;
  a = function(int x, int y) {&lt;br /&gt;
      return x + y&lt;br /&gt;
  }&lt;br /&gt;
  MessageClip(String(a)) #Function&lt;br /&gt;
  b = a&lt;br /&gt;
  MessageClip(String(b)) #Function&lt;br /&gt;
  MessageClip(String(a == b)) # true&lt;br /&gt;
&lt;br /&gt;
'''Take as an argument'''&lt;br /&gt;
&lt;br /&gt;
  function MyFunc(func f) {&lt;br /&gt;
      return f(2, 3)&lt;br /&gt;
  }&lt;br /&gt;
  a = MyFunc(function(x, y) {&lt;br /&gt;
      return x + y&lt;br /&gt;
  })&lt;br /&gt;
  MessageClip(String(a)) # 5&lt;br /&gt;
&lt;br /&gt;
'''return as a return value'''&lt;br /&gt;
&lt;br /&gt;
  function MyFunc() {&lt;br /&gt;
      return function(x, y) {&lt;br /&gt;
          return x + y&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  a = MyFunc()(2, 3)&lt;br /&gt;
  MessageClip(String(a)) # 5&lt;br /&gt;
&lt;br /&gt;
Capture the variable at that point with '[]' before the formal argument&lt;br /&gt;
&lt;br /&gt;
'''Capture example'''&lt;br /&gt;
&lt;br /&gt;
  function MyFunc() {&lt;br /&gt;
      x = 2&lt;br /&gt;
      y = 3&lt;br /&gt;
      return function[x, y]() {&lt;br /&gt;
          return x + y&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  a = MyFunc()()&lt;br /&gt;
  MessageClip(String(a)) # 5&lt;br /&gt;
&lt;br /&gt;
== Specification details ==&lt;br /&gt;
&lt;br /&gt;
Function objects are functions defined with the new syntax.&lt;br /&gt;
&lt;br /&gt;
  function [] () {...}&lt;br /&gt;
&lt;br /&gt;
It looks like an unnamed function compared to the usual function definitions so far. '[]' Does not have to be optional.&lt;br /&gt;
&lt;br /&gt;
Functions defined in the normal function format are not function objects (for compatibility).&lt;br /&gt;
&lt;br /&gt;
  function MyFunc() {return 123}&lt;br /&gt;
  a = MyFunc&lt;br /&gt;
  MessageClip(String(a)) # 123 (Not Function)&lt;br /&gt;
&lt;br /&gt;
Similarly, built-in functions and plug-in functions are not function objects.&lt;br /&gt;
&lt;br /&gt;
  a = Invert # Error: I don't know what 'Invert' means.&lt;br /&gt;
&lt;br /&gt;
Functions that are not function objects can be made into function objects by using the func function.&lt;br /&gt;
&lt;br /&gt;
  a = func(Invert)&lt;br /&gt;
  Version().a() # Invert a clip&lt;br /&gt;
&lt;br /&gt;
A new 'func' has been added to the value type.&lt;br /&gt;
&lt;br /&gt;
  function MyFunc(func x, func y, int z) {&lt;br /&gt;
    return x () + y () + z&lt;br /&gt;
  }&lt;br /&gt;
  a = MyFunc(function(){1}, function(){2}, 3)&lt;br /&gt;
  MessageClip(String(a)) # 6 (= 1 + 2 + 3)&lt;br /&gt;
&lt;br /&gt;
The IsFunction function that determines the function object has been added.&lt;br /&gt;
&lt;br /&gt;
  a = function() {}&lt;br /&gt;
  MessageClip(String(IsFunction(a))) # true&lt;br /&gt;
&lt;br /&gt;
== Compare with GRunT ==&lt;br /&gt;
&lt;br /&gt;
Let's compare function objects with GRunT, a plugin that makes ScriptClip easier to write.&lt;br /&gt;
&lt;br /&gt;
The following code on the GRunT introduction page&lt;br /&gt;
&lt;br /&gt;
  function bracket_luma(clip c, float th1, float th2) {&lt;br /&gt;
      Assert (0 &amp;lt;= th1 &amp;amp;&amp;amp; th1 &amp;lt;th2 &amp;amp;&amp;amp; th2 &amp;lt;= 255, &amp;quot;Invalid thresholds!&amp;quot;)&lt;br /&gt;
      ScriptClip (c, &amp;quot;&amp;quot; &amp;quot;&lt;br /&gt;
         avl = AverageLuma ()&lt;br /&gt;
         avl &amp;lt;= th1? Last.BlankClip (): avl&amp;gt; = th2? last.BlankClip (color = color_white): last&lt;br /&gt;
      &amp;quot;&amp;quot; &amp;quot;, args =&amp;quot; th1, th2 &amp;quot;, local = true)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
It is a sample to appeal the goodness of GRunT, but with Neo it can be written as follows.&lt;br /&gt;
&lt;br /&gt;
  function bracket_luma(clip c, float th1, float th2) {&lt;br /&gt;
      Assert (0 &amp;lt;= th1 &amp;amp;&amp;amp; th1 &amp;lt;th2 &amp;amp;&amp;amp; th2 &amp;lt;= 255, &amp;quot;Invalid thresholds!&amp;quot;)&lt;br /&gt;
      ScriptClip(c, function [th1, th2] () {&lt;br /&gt;
         avl = AverageLuma()&lt;br /&gt;
         avl &amp;lt;= th1? Last.BlankClip() : avl&amp;gt; = th2? last.BlankClip(color = color_white) : last&lt;br /&gt;
      })&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
There are the following differences compared to GRunT.&lt;br /&gt;
&lt;br /&gt;
- There is no need to pass the processing content as a character string&lt;br /&gt;
- Variables to be used can be written in a special syntax, so the amount of description is reduced.&lt;br /&gt;
&lt;br /&gt;
== Supports 'function' type of input of built-in functions ==&lt;br /&gt;
&lt;br /&gt;
A version that can pass the function has been added to the function that passed the processing content as a script string.&lt;br /&gt;
&lt;br /&gt;
=== ScriptClip ===&lt;br /&gt;
&lt;br /&gt;
ScriptClip(clip clip, func filter [, bool show, bool after_frame])&lt;br /&gt;
&lt;br /&gt;
'''Example 1'''&lt;br /&gt;
&lt;br /&gt;
  Version()&lt;br /&gt;
  ScriptClip (function [] (clip c) {&lt;br /&gt;
      c.Subtitle(String(current_frame))&lt;br /&gt;
  })&lt;br /&gt;
&lt;br /&gt;
'''Example 2: Comparison with string input'''&lt;br /&gt;
&lt;br /&gt;
ScriptClip with text script input&lt;br /&gt;
&lt;br /&gt;
  SSS2=&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  p=(current_frame)*pow(framecount(last)-1,-1)*100&lt;br /&gt;
  q=ceil(0.0625*((framecount(last))-(current_frame+1)))&lt;br /&gt;
   Subtitle(String(q,&amp;quot;%.0f&amp;quot;)+String(&amp;quot; - &amp;quot;)+String(p,&amp;quot;%.2f&amp;quot;)+String(&amp;quot;% - &amp;quot;)+String(current_frame,&amp;quot;%.0f&amp;quot;)) &lt;br /&gt;
  &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  clip1 = Input.Scriptclip(SSS2,After_Frame=True)&lt;br /&gt;
&lt;br /&gt;
With function object (declared inline)&lt;br /&gt;
&lt;br /&gt;
  clip1 = Input.Scriptclip(function[](clip c) { p=(current_frame)*pow(framecount(last)-1,-1)*100 \&lt;br /&gt;
    q=ceil(0.0625*((framecount(last))-(current_frame+1))) \&lt;br /&gt;
    Subtitle(String(q,&amp;quot;%.0f&amp;quot;)+String(&amp;quot; - &amp;quot;)+String(p,&amp;quot;%.2f&amp;quot;)+String(&amp;quot;% - &amp;quot;)+String(current_frame,&amp;quot;%.0f&amp;quot;)) \&lt;br /&gt;
  }, After_Frame=True)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== ConditionalFilter ===&lt;br /&gt;
&lt;br /&gt;
ConditionalFilter(clip testclip, clip source1, clip source2, func condition [, bool show])&lt;br /&gt;
&lt;br /&gt;
'''Example'''&lt;br /&gt;
&lt;br /&gt;
  a = Version()&lt;br /&gt;
  b = a.Invert()&lt;br /&gt;
  ConditionalFilter(a, a, b, function [] (clip c) {&lt;br /&gt;
      current_frame&amp;lt;30 # if true return a else b&lt;br /&gt;
  })&lt;br /&gt;
&lt;br /&gt;
=== ConditionalSelect ===&lt;br /&gt;
&lt;br /&gt;
ConditionalSelect(clip testclip, func get_index, clip source0 [, clip source1 ...] [, bool show])&lt;br /&gt;
&lt;br /&gt;
'''Example'''&lt;br /&gt;
&lt;br /&gt;
  Version ()&lt;br /&gt;
  ConditionalSelect(function [] (clip c) {&lt;br /&gt;
      current_frame / 100&lt;br /&gt;
  }, subtitle(&amp;quot;0&amp;quot;), subtitle(&amp;quot;1&amp;quot;), subtitle(&amp;quot;2&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
=== WriteFile system ===&lt;br /&gt;
&lt;br /&gt;
:WriteFile(clip clip, string filename, func expression1 [, func expression2 [, ...]] [, bool append, bool flush])&lt;br /&gt;
&lt;br /&gt;
:WriteFileIf(clip clip, string filename, func expression1 [, func expression2 [, ...]] [, bool append, bool flush])&lt;br /&gt;
&lt;br /&gt;
:WriteFileStart (clip clip, string filename, func expression1 [, func expression2 [, ...]] [, bool append])&lt;br /&gt;
&lt;br /&gt;
:WriteFileEnd (clip clip, string filename, func expression1 [, func expression2 [, ...]] [, bool append])&lt;br /&gt;
&lt;br /&gt;
'''Example'''&lt;br /&gt;
&lt;br /&gt;
  Version().ConvertToY()&lt;br /&gt;
  WriteFile(&amp;quot;out.txt&amp;quot;, function() {&lt;br /&gt;
      string(current_frame) + &amp;quot;:&amp;quot; + string(YPlaneMedian())&lt;br /&gt;
  })&lt;br /&gt;
----&lt;br /&gt;
Back to [[AviSynth Syntax]].&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Internal_functions]]&lt;br /&gt;
[[Category:AviSynth_Syntax]]&lt;br /&gt;
[[Category:Scripting_Basics]]&lt;/div&gt;</summary>
		<author><name>Pinterf</name></author>	</entry>

	</feed>