Lugaru's Epsilon
Programmer's
Editor 14.04

Context:
Epsilon User's Manual and Reference
   Epsilon Extension Language
      . . .
      Constant Expressions
      Global Definitions
         Key Tables
         Color Classes
         Function Definitions
      Differences Between EEL And C
      . . .

Previous   Up    Next
Color Classes  Epsilon Extension Language   Differences Between EEL And C


Epsilon User's Manual and Reference > Epsilon Extension Language > Global Definitions >

Function Definitions

function-definition:
        function-head block
        function-head argument-decl-list block
        ansi-function-head block
        callable-function-head block

callable-function-head:
        typed-function-head
        command typed-function-head
        typed-function-head on binding-list
        command typed-function-head on binding-list

binding-list:
        keytable-name [ constant-expression ]
        keytable-name [ constant-expression ] , binding-list

keytable-name:
        identifier

typed-function-head:
        identifier ()
        type-specifier identifier ()

function-head:
        identifier ( argument-list )
        type-specifier identifier ( argument-list )

ansi-function-head:
        identifier ( ansi-argument-list )
        type-specifier identifier ( ansi-argument-list )

ansi-argument-list:
        type-specifier declarator
        type-specifier declarator , ansi-argument-list

argument-list:
        identifier
        identifier , argument-list

argument-decl-list:
        type-specifier declarator-list ;
        type-specifier declarator-list ; argument-decl-list

A function definition begins with a type specifier, the name of the function, and parentheses surrounding a comma-separated list of arguments. Any bindings may be given here using the on keyword, as described below. Declarations for the arguments then appear, and the body of the function follows. If the command keyword appears before the type specifier, the function is a command, and Epsilon will do completion on the function when it asks for the name of a command. A function may be a command only if it has no arguments.

You may omit the type specifier before the function name, in which case the function's type is int. You may also omit the declaration for any argument, in which case the argument will be an int. Note that unlike some languages such as Pascal, if there are no arguments, an empty pair of parentheses must still appear, both in the definition and where you call the function.

You may also define functions using ANSI C/C++ syntax, in which type information for function arguments appears with the argument names inside parentheses. These function headers have the same effect:

average(int count, short *values)


average(count, values)
short *values;

When you call a function, arguments of type char or short are automatically changed to ints. A corresponding change happens to declarations of function arguments and return values. Additionally, function arguments declared as an array of some type are changed to be a pointer to the same type, just as array variables are changed to pointers to the start of the array when their names appear in expressions (see Constants and Identifiers). For example, these two function headers have the same effect.

short average(count, values)
char count;
short values[ ];


average(count, values)
short *values;

The user can call any function which takes no arguments, or bind such a function to a key. Functions which are normally invoked in this way can be made commands with the command keyword, but this is not necessary. If you omit the command keyword, Epsilon will not perform command completion on the function's name. The on keyword can appear after the (empty) parentheses of a function's argument list, to provide bindings for the function. Each binding consists of a key table name, followed by a constant (the key number) in square brackets [ ]. There may be several bindings following the on keyword, separated by commas. You must have previously declared the key table name in the same file (or an #included file). The binding takes effect when you load the function.

Sometimes it is necessary to declare an identifier as a function, although the function is actually defined in a separately compiled source file. For example, you must declare a function before you use a pointer to that function. Also, the EEL compiler must know that a function returns a non-numeric type if its return value is used. Any declaration of an identifier with type function returning ... is a function declaration. Function declarations may appear anywhere a local or global variable declaration is legal. So long as the identifier is not masked by a local variable of the same name, the declaration has effect until the end of the file.

Any function named when_loading( ) is automatically executed when you load the bytecode file it appears in into Epsilon. There may be any number of when_loading() functions defined in a file, and they execute in order, while the file is being loaded. Such functions are deleted as soon as they return. They may take no arguments.



Previous   Up    Next
Color Classes  Epsilon Extension Language   Differences Between EEL And C


Lugaru Epsilon Programmer's Editor 14.04 manual. Copyright (C) 1984, 2021 by Lugaru Software Ltd. All rights reserved.