/
ColdC/Functions/
ColdC/Structure/
<head><title>ColdC: Defining Methods</title></head>

<body>
<h1 align=center><a href="/ColdC/">ColdC</a>: Defining Methods</h1>
<hr>

<p>When defining a method several considerations must be taken into account.
What arguments will the method accept?  What local variables will the method
use?  What sort of flags will the method have?  What sort of access will other
objects have to the method?

<a name="args"></a><a name="vars"></a>
<h2>Arguments and Variables</h2>

<p>The arguments and variables for a method are defined within the method code.
The internal structure of a method is:

<blockquote><PRE>
arg <VAR>arg1</VAR>, <VAR>arg2</VAR>, <VAR>...</VAR>, [<VAR>rest</VAR>];
var <VAR>var1</VAR>, <VAR>var2</VAR>, <VAR>...</VAR>;

<VAR>statement1</VAR>
<VAR>statement2</VAR>
<VAR>.</VAR>
<VAR>.</VAR>
<VAR>.</VAR>
</PRE></blockquote>

<P>The <CODE>arg</CODE> declaration gives a list of argument variables,
whose values will correspond to the arguments passed with the message.  You
may omit the <CODE>arg</CODE> declaration if the method does not take any
arguments.  If the final argument variable is given in square brackets
(that is, if you specify <VAR>rest</VAR>), then the method can accept a
variable number of argments; <VAR>rest</VAR> will contain a list of the
arguments beyond the ones corresponding to the argument variables.  If
you do not specify <VAR>rest</VAR>, then the method can accept only the
number of arguments specified by the argument variables, no more.

<P>The <CODE>var</CODE> declaration tells the compiler that the listed
identifiers should refer to local variables.  You may omit the
<CODE>var</CODE> declaration if you do not wish to declare any local
variables.

<P>The statements <VAR>statement1</VAR>, <VAR>statement2</VAR>,
<VAR>...</VAR> are the body of the method.  They tell the interpreter
what the method does.

<a name="flags"></a>
<h2>Method Flags</h2>

<p>Method flags define certain behavioral features of the method.  Currently
the following method flags exist:

<dl>
<dt><code><b>'nooverride</b></code>
<dd>Methods which specify <code>'nooverride</code> cannot be overridden by
    any of the defining object's descendants.
<dt><code><b>'lock</b></code>
<dd><code>'lock</code> locks all aspects of a method.  Locked methods
    cannot have their access or flags changed, nor can they be recompiled
    during run-time.  Locked methods can be changed outside of the regular
    running environment (such as in a textdb, or with coldcc).
<dt><code><b>'fork</b></code>
<dd><code>'fork</code> is used to specify that the method forks from the
    current task.  The return value of a forked method is the task id of
    the new task (fork is currently unsupported).
<dt><code><b>'native</b></code>
<dd><code>'native</code> specifies a native method.
    Native methods are not really methods, but are actually functions
    acting as a method.  Because of this native methods cannot be listed
    or manipulated in most of the usual ways.
</dl>

<p>All method flags, with the exception of <code>'native</code>, can be
manipulated using the functions
<code><a href="/ColdC/Functions/method_flags.html">method_flags()</a></code> and
<code><a href="/ColdC/Functions/set_method_flags.html">set_method_flags()</a></code>.

<a name="access"></a>
<h2>Method Access</h2>

<p>It is possible to restrict what calls a method by setting the method's
access.  By default all methods are <i>public</i> methods.  The available
settings for method access are:

<dl>
<dt><code><b>'public</b></code>
<dd>This access state is the default.  A public method can be called by
    any object.
<dt><code><b>'protected</b></code>
<dd>Protected methods can only be called by the defining object, or
    descendants of the defining object (sender() must be this()).
<dt><code><b>'private</b></code>
<dd>Private methods can only be called by the object they were defined
    on (caller() must be this()).
<dt><code><b>'root</b></code>
<dd>Root methods can only be called by the <code>$root</code> object
    (caller() must be <code>$root</code>).
<dt><code><b>'driver</b></code>
<dd>Driver methods can only be called by the driver.
</dl>

<p>Method access can be manipulated using the functions
<code><a href="/ColdC/Functions/method_access.html">method_access()</a></code> and
<code><a href="/ColdC/Functions/set_method_access.html">set_method_access()</a></code>.

<hr size=4><p align=center><i>Last Modified on Feb 26 1996</i>
<br><i>Copyright &copy; 1995, 1996, Brandon Gillespie</i>
</body>