<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://wiki.lostsouls.org/w/skins/common/feed.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Man functions - Revision history</title>
		<link>http://wiki.lostsouls.org/w/index.php?title=Man_functions&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.8.2</generator>
		<lastBuildDate>Sun, 10 May 2026 10:34:05 GMT</lastBuildDate>
		<item>
			<title>Laine at 16:45, 11 June 2007</title>
			<link>http://wiki.lostsouls.org/w/index.php?title=Man_functions&amp;diff=3928&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Description==&lt;br /&gt;
&lt;br /&gt;
Functions are named blocks of code which are be called with&lt;br /&gt;
a number of argument values, and which return a result value&lt;br /&gt;
to the caller.&lt;br /&gt;
&lt;br /&gt;
Functions are defined in an object and are also known as&lt;br /&gt;
&amp;quot;local funs&amp;quot; or short &amp;quot;lfuns&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Defining a function==&lt;br /&gt;
&lt;br /&gt;
A function definition takes the form&lt;br /&gt;
&lt;br /&gt;
          &amp;lt;modifiers&amp;gt; &amp;lt;type&amp;gt; name ( &amp;lt;arguments&amp;gt; ) {&lt;br /&gt;
             statements...&lt;br /&gt;
          }&lt;br /&gt;
&lt;br /&gt;
The parts in detail:&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;modifiers&amp;gt; can be any one of &amp;quot;static&amp;quot;, &amp;quot;private&amp;quot;, &amp;quot;public&amp;quot;&lt;br /&gt;
and &amp;quot;protected&amp;quot; (see [[man modifiers|modifiers(LPC)]]), optionally combined&lt;br /&gt;
with &amp;quot;varargs&amp;quot; (see [[man varargs|varargs(LPC)]]) and/or &amp;quot;nomask&amp;quot;.&lt;br /&gt;
If not specified, the function behaves as if it was&lt;br /&gt;
specified as &amp;quot;public&amp;quot;, but this visibility can be restricted&lt;br /&gt;
  in derived object through non-public inheritance.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;type&amp;gt; is the type of the result returned by the function.&lt;br /&gt;
If specified as &amp;quot;void&amp;quot;, the function is compiled to return&lt;br /&gt;
the value 0 under all circumstances. If not specified, the&lt;br /&gt;
type is assumed to be &amp;quot;mixed&amp;quot;, furthermore typechecking is&lt;br /&gt;
disabled for this function.&lt;br /&gt;
&lt;br /&gt;
- name is the name of the function, e.g. &amp;quot;short&amp;quot;, or &amp;quot;Nice_Try&amp;quot;,&lt;br /&gt;
under which it is made known.&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;arguments&amp;gt; is a list of variable definitions in the&lt;br /&gt;
normal '&amp;lt;type&amp;gt; &amp;lt;name&amp;gt;' style, separated by comma.&lt;br /&gt;
&lt;br /&gt;
Examples: &lt;br /&gt;
                        () : no argument taken&lt;br /&gt;
                        (int a) : takes on integer argument&lt;br /&gt;
                        (mixed a, object *b): takes two arguments, one&lt;br /&gt;
                           arbitrary type, one array of objects.&lt;br /&gt;
          &lt;br /&gt;
- { statements... } defines the code for this function. This&lt;br /&gt;
is a normal block (see block(LPC)) and as such can define&lt;br /&gt;
its own local variables.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Declaring a function==&lt;br /&gt;
&lt;br /&gt;
A function declaration makes the name and type of a function known&lt;br /&gt;
to the compiler with the assertion that the code for this function&lt;br /&gt;
will be provided &amp;quot;elsewhere&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The form is:&lt;br /&gt;
&lt;br /&gt;
          &amp;lt;modifiers&amp;gt; &amp;lt;type&amp;gt; name ( &amp;lt;arguments&amp;gt; );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Typical uses are:&lt;br /&gt;
&lt;br /&gt;
- to declare in advance functions which are called before they&lt;br /&gt;
can be defined; for example if the create() function of an object&lt;br /&gt;
calls other functions which are defined after the create().&lt;br /&gt;
&lt;br /&gt;
- to declare functions which will be provided by an inheriting&lt;br /&gt;
object.&lt;br /&gt;
&lt;br /&gt;
Calling a declared but undefined function results in a runtime error.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Calling a function==&lt;br /&gt;
&lt;br /&gt;
Functions in other objects are called with the call_other() efun,&lt;br /&gt;
which can be shortened to '-&amp;gt;':&lt;br /&gt;
&lt;br /&gt;
           ob-&amp;gt;fun(a, b, c)&lt;br /&gt;
           call_other(ob, &amp;quot;fun&amp;quot;, a, b, c)&lt;br /&gt;
&lt;br /&gt;
Functions in the same object are called just by writing their name,&lt;br /&gt;
followed by the arguments in parenthesis:&lt;br /&gt;
&lt;br /&gt;
        short()&lt;br /&gt;
           compute(a)&lt;br /&gt;
           do_that(a, &amp;quot;foo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
If the number of values passed to the function does not match the&lt;br /&gt;
number of expected arguments (and if type checking is enabled), the&lt;br /&gt;
driver will perform the necessary adaption at call time: excess&lt;br /&gt;
values are ignored, missing values are substituted by the number 0.&lt;br /&gt;
The values passed to the called function are massaged by the driver&lt;br /&gt;
to match the argument list&lt;br /&gt;
&lt;br /&gt;
==Functions and Inheritance==&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;public&amp;quot; or &amp;quot;protected&amp;quot; (== &amp;quot;static&amp;quot;) function defined in one&lt;br /&gt;
object is also visible in all inheriting objects. The exception from&lt;br /&gt;
this rule is when an inheriting child redefines (&amp;quot;overloads&amp;quot;) the&lt;br /&gt;
inherited function with its own. When compiling with type checking,&lt;br /&gt;
the argument list of the redefined function has to match the&lt;br /&gt;
original one.&lt;br /&gt;
&lt;br /&gt;
When a function is called, the driver looks for the function first&lt;br /&gt;
in the object called, and if not found there, then in the inherited&lt;br /&gt;
objects.&lt;br /&gt;
&lt;br /&gt;
To explicitly call an inherited function (useful when a redefining&lt;br /&gt;
functions wants to use the original one), the &amp;quot;::&amp;quot; operator is used:&lt;br /&gt;
&lt;br /&gt;
            ::create()&lt;br /&gt;
            ::compute(a)&lt;br /&gt;
&lt;br /&gt;
The named function is searched only in the inherited objects, and&lt;br /&gt;
the first found is used.&lt;br /&gt;
&lt;br /&gt;
If the function is inherited from several objects and a specific&lt;br /&gt;
one is to be called, the &amp;quot;::&amp;quot; can be extended to contain the&lt;br /&gt;
partial or full name of the inherited object:&lt;br /&gt;
&lt;br /&gt;
            inherit &amp;quot;/obj/cooker&amp;quot;;&lt;br /&gt;
            inherit &amp;quot;/obj/container&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            tainer::create()&lt;br /&gt;
            container::create()&lt;br /&gt;
            &amp;quot;tainer&amp;quot;::create()&lt;br /&gt;
            &amp;quot;container&amp;quot;::create()&lt;br /&gt;
            &amp;quot;obj/container&amp;quot;::create()&lt;br /&gt;
            &amp;quot;/obj/container&amp;quot;::create()&lt;br /&gt;
&lt;br /&gt;
all call the create() in the container inherit. Note that the&lt;br /&gt;
name given to the :: operator is matched against the ends of&lt;br /&gt;
the inherited names.&lt;br /&gt;
&lt;br /&gt;
One special form of this call is&lt;br /&gt;
&lt;br /&gt;
            efun::find_object()&lt;br /&gt;
&lt;br /&gt;
which bypasses any redefinition of an efun (here find_object())&lt;br /&gt;
and directly calls the efun itself. This is only possible for&lt;br /&gt;
efun-redefinitions which do not use the &amp;quot;nomask&amp;quot; modifier.&lt;br /&gt;
&lt;br /&gt;
Additionally, a call to a function inherited from several objects&lt;br /&gt;
can be instructed to call _all_ inherited functions through the&lt;br /&gt;
use of the wildcards &amp;quot;*&amp;quot; (match any number of arbitrary characters)&lt;br /&gt;
and &amp;quot;?&amp;quot; (match one arbitrary character):&lt;br /&gt;
&lt;br /&gt;
            inherit &amp;quot;/obj/cooker&amp;quot;;&lt;br /&gt;
            inherit &amp;quot;/obj/container&amp;quot;;&lt;br /&gt;
            &amp;quot;*&amp;quot;::create()&lt;br /&gt;
            &amp;quot;co*&amp;quot;::create()&lt;br /&gt;
            &amp;quot;*er&amp;quot;::create()&lt;br /&gt;
&lt;br /&gt;
all call both inherited create()s. The function called this way&lt;br /&gt;
must not take arguments, and the single results from all calls are&lt;br /&gt;
combined into one array used as final result. If there is no such&lt;br /&gt;
function inherited at all, the statement will just return&lt;br /&gt;
an empty array.&lt;br /&gt;
&lt;br /&gt;
==See Also==        &lt;br /&gt;
[[man types|types(LPC)]], [[man modifiers|modifiers(LPC)]], [[man varargs|varargs(LPC)]], [[man references|references(LPC)]], [[man call other|call_other(E)]], [[man simul efun|simul_efun(C)]], [[man call out|call_out(E)]]&lt;/div&gt;</description>
			<pubDate>Mon, 11 Jun 2007 16:45:51 GMT</pubDate>			<dc:creator>Laine</dc:creator>			<comments>http://wiki.lostsouls.org/Talk:Man_functions</comments>		</item>
	</channel>
</rss>