Manual:DIL Manual/external
Jump to navigation
Jump to search
Contents
external
Keyword. Declares the other templates a template calls.
external name@zone(arg : type, ...); type name@zone(arg : type, ...); name(arg : type, ...);
The external section comes right after the dilbegin header, before var. Each line declares one template: a procedure (no type) or a function (its return type first), with its arguments. After that the template can be called by that name: name@zone(...) as a statement, or as a value when it is a function.
A name without @zone means a template in the template's own zone, and is called without @zone too.
Notes
- Every template you call needs a declaration, also one in the same zone. Without it vmc says "No such variable" with the name. Only a template calling itself needs none.
- The declaration must match the template: return type, number of arguments and their types (the argument names don't matter). vmc checks your calls against the declaration; the server checks the declaration against the real template when it boots. A missing template is logged as "Cannot resolve external reference 'name@zone'", a wrong one as "Error typechecking reference to 'name@zone'" (in vme.log and the zone's .err file). Calling it later stops the program with "Error in remote call function #n not valid".
- Only declarations that are called are checked; unused ones cost nothing.
- Declaring the same template twice is a syntax error, and so is
externalwith nothing after it. - A procedure has no value:
i := proc@zone(self);is "Assigning incompatible types". - A DIL function's result can't be passed straight to another DIL function:
f(g(x))fails with "Incompatible argument types in argument 1". Putg(x)in a variable first. Built-in functions such asitoa(g(x))are fine. - vmc writes a ready-made declaration for each template of a zone to
<zone>.dhwhen it compiles the zone. - A template can also be called through a string variable that holds its name, without a declaration:
fn := "max@function"; i := (integer) fn(3, 4);, orfn(self);for a procedure. The arguments are then only checked at run time.
Example
dilbegin integer half_exp(u : unitptr);
external
integer max@function(a : integer, b : integer);
code
{
return (max@function(0, u.exp / 2));
}
dilend
dilbegin show_half(arg : string);
external
integer half_exp(u : unitptr);
var
n : integer;
code
{
n := half_exp(self);
sendtext("Half your experience is " + itoa(n) + ".<br/>", self);
quit;
}
dilend
half_exp calls max from function.zon (declared as in death.zon); show_half calls half_exp from its own zone.