]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
manual: Update from wiki.gnome.org
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 15 Sep 2022 18:46:05 +0000 (20:46 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 15 Sep 2022 18:46:05 +0000 (20:46 +0200)
doc/manual/manual.xml

index 939824aa8be3006a214ba7fb1ff629a860f5ef3a..102e8681ba8c27a26670d317e42e3f3926624cb6 100644 (file)
 <section>
 <title>Delegates</title>
 <para>A delegate declaration defines a method type: a type that can be invoked, accepting a set of values of certain types, and returning a value of a set type. In Vala, methods are not first-class objects, and as such cannot be created dynamically; however, any method can be considered to be an instance of a delegate's type, provided that the method signature matches that of the delegate. </para>
-<para>Methods are considered to be an immutable reference type.  Any method can be referred to by name as an expression returning a reference to that method - this can be assigned to a field (or variable, or parameter), or else invoked directly as a standard method invocation (see <ulink url="http://wiki.gnome.org/Projects/Vala/Manual/Export/Projects/Vala/Manual/Expressions#Invocation_expressions">Expressions/Invocation expressions</ulink>). </para>
+<para>Methods are considered to have an immutable reference type.  Any method can be referred to by name as an expression returning a reference to that method - this can be assigned to a field (or variable, or parameter), or else invoked directly as a standard method invocation (see <ulink url="http://wiki.gnome.org/Projects/Vala/Manual/Export/Projects/Vala/Manual/Expressions#Invocation_expressions">Expressions/Invocation expressions</ulink>). </para>
 
 <section>
 <title>Types of delegate</title>
 <title>Delegate declaration</title>
 <para>The syntax for declaring a delegate changes slightly based on what sort of delegate is being declared.  This section shows the form for a namespace delegate.  Many of the parts of the declaration are common to all types, so sections from here are referenced from class delegates, interface delegates, etc. </para><itemizedlist><listitem override="none">
 <para>delegate-declaration:</para><itemizedlist><listitem override="none">
-<para>instance-delegate-declaration</para>
-<para> static-delegate-declaration</para></listitem></itemizedlist>
-<para> instance-delegate-declaration:</para><itemizedlist><listitem override="none">
 <para>[ access-modifier ] <emphasis role="strong">delegate</emphasis> return-type qualified-delegate-name <emphasis role="strong">(</emphasis> method-params-list <emphasis role="strong">)</emphasis> [ <emphasis role="strong">throws</emphasis> error-list ] <emphasis role="strong">;</emphasis></para></listitem></itemizedlist>
-<para> static-delegate-declaration:</para><itemizedlist><listitem override="none">
-<para>[ access-modifier ] <emphasis role="strong">static</emphasis> <emphasis role="strong">delegate</emphasis> return-type qualified-delegate-name <emphasis role="strong">(</emphasis> method-params-list <emphasis role="strong">)</emphasis> [ <emphasis role="strong">throws</emphasis> error-list ] <emphasis role="strong">;</emphasis></para></listitem></itemizedlist>
 <para> qualified-delegate-name:</para><itemizedlist><listitem override="none">
 <para>[ qualified-namespace-name <emphasis role="strong">.</emphasis> ] delegate-name</para></listitem></itemizedlist>
 <para> delegate-name:</para><itemizedlist><listitem override="none">
 <para>identifier</para></listitem></itemizedlist></listitem></itemizedlist>
 <para>Parts of this syntax are based on the respective sections of the method declaration syntax (see <ulink url="http://wiki.gnome.org/Projects/Vala/Manual/Export/Projects/Vala/Manual/Methods#">Methods</ulink> for details). </para>
+<para>By default, delegates are instance delegates. To declare a static delegate, add the annotation <code>[CCode (has_target = false)]</code>; see the examples below. (Static delegates used to be declared by adding the keyword <code>static</code> before <code>delegate</code> instead of using the annotation. This syntax is still accepted by the compiler, but will cause a warning to be given.) </para>
 </section>
 
 <section>
 <section>
 <title>Examples</title>
 <para>Defining delegates: </para><programlisting format="linespecific" language="vala" linenumbering="numbered" startinglinenumber="1"><lineannotation><![CDATA[// Static delegate taking two ints, returning void:]]></lineannotation>
-<lineannotation/><token><![CDATA[static]]></token><![CDATA[ ]]><token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[DelegateName]]></methodname><![CDATA[ (]]><token><![CDATA[int]]></token><![CDATA[ ]]><methodname><![CDATA[a]]></methodname><![CDATA[, ]]><token><![CDATA[int]]></token><![CDATA[ ]]><methodname><![CDATA[b]]></methodname><![CDATA[);]]>
+<lineannotation/><![CDATA[[]]><methodname><![CDATA[CCode]]></methodname><![CDATA[ (]]><methodname><![CDATA[has_target]]></methodname><![CDATA[ = ]]><token><![CDATA[false]]></token><![CDATA[)]]]>
+<token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[DelegateName]]></methodname><![CDATA[ (]]><token><![CDATA[int]]></token><![CDATA[ ]]><methodname><![CDATA[a]]></methodname><![CDATA[, ]]><token><![CDATA[int]]></token><![CDATA[ ]]><methodname><![CDATA[b]]></methodname><![CDATA[);]]>
 
 <lineannotation><![CDATA[// Instance delegate with the same signature:]]></lineannotation>
 <lineannotation/><token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[DelegateName]]></methodname><![CDATA[ (]]><token><![CDATA[int]]></token><![CDATA[ ]]><methodname><![CDATA[a]]></methodname><![CDATA[, ]]><token><![CDATA[int]]></token><![CDATA[ ]]><methodname><![CDATA[b]]></methodname><![CDATA[);]]>
 
 <lineannotation><![CDATA[// Static delegate which may throw an error:]]></lineannotation>
-<lineannotation/><token><![CDATA[static]]></token><![CDATA[ ]]><token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[DelegateName]]></methodname><![CDATA[ () ]]><token><![CDATA[throws]]></token><![CDATA[ ]]><methodname><![CDATA[GLib]]></methodname><![CDATA[.]]><methodname><![CDATA[Error]]></methodname><![CDATA[;]]>
+<lineannotation/><![CDATA[[]]><methodname><![CDATA[CCode]]></methodname><![CDATA[ (]]><methodname><![CDATA[has_target]]></methodname><![CDATA[ = ]]><token><![CDATA[false]]></token><![CDATA[)]]]>
+<token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[DelegateName]]></methodname><![CDATA[ () ]]><token><![CDATA[throws]]></token><![CDATA[ ]]><methodname><![CDATA[GLib]]></methodname><![CDATA[.]]><methodname><![CDATA[Error]]></methodname><![CDATA[;]]>
 </programlisting>
 <para>Invoking delegates, and passing as parameters. </para><programlisting format="linespecific" language="vala" linenumbering="numbered" startinglinenumber="1"><token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[f1]]></methodname><![CDATA[(]]><token><![CDATA[int]]></token><![CDATA[ ]]><methodname><![CDATA[a]]></methodname><![CDATA[) { ]]><methodname><![CDATA[stdout]]></methodname><![CDATA[.]]><methodname><![CDATA[printf]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[%d]]></phrase><![CDATA[
 ]]><phrase><![CDATA["]]></phrase><![CDATA[, ]]><methodname><![CDATA[a]]></methodname><![CDATA[); }]]>