Difference between revisions of "Manual:DIL Manual/unitdir()"
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = unitdir() = | |
| + | '''Function''' (stringlist). Lists the unit files that DIL has stored, by a pattern. | ||
| − | + | unitdir(pattern : string) | |
| − | + | Returns the names of the files in the <code>units</code> directory that match <code>pattern</code>: the files <code>store()</code> writes and <code>restore()</code> and <code>delunit()</code> read. death.zon uses <code>unitdir(".*")</code> at boot to bring back the corpses that were stored before a crash or reboot. | |
| − | |||
| − | |||
| − | |||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | pattern || string || A regular expression that must match the ''whole'' file name. "" means all files. | ||
| + | |} | ||
| − | + | == Returns == | |
| − | + | Stringlist: the matching file names, in no particular order (the order the directory gives them). Empty when nothing matches or the directory doesn't exist. It fails if <code>pattern</code> fails, is a string variable that has never had a value, or is not a valid regular expression; assigning a failed list leaves the variable as it was. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | == Notes == | |
| − | + | * The pattern is a regular expression (Perl style), not a shell wildcard: <code>".*"</code> is everything, <code>"corpse[.].*"</code> is every name starting with "corpse.", and a plain <code>.</code> matches any character. A shell-style <code>"*"</code> is not a valid expression. | |
| − | + | * The directory is <code>units/</code> under the zone's DIL file directory: the sixth column of the zone's line in <code>vme/etc/zonelist</code> (death has <code>../lib/death</code>), or else <code>dil_file_dir</code> in <code>server.cfg</code>. The zone is that of the program the unit runs; a function from another zone that it calls (<code>f@otherzone</code>) still looks in the calling program's directory. | |
| + | * Only file names are returned, without a path, ready for <code>restore()</code>. | ||
| − | + | == Example == | |
| − | + | <pre> | |
| − | + | dilbegin aware reload_units(); | |
| − | + | var | |
| − | + | files : stringlist; | |
| − | + | u : unitptr; | |
| − | + | i : integer; | |
| − | + | n : integer; | |
| − | + | code | |
| − | + | { | |
| − | + | files := unitdir("corpse[.].*"); | |
| − | + | n := length(files); | |
| − | + | i := 0; | |
| − | + | while (i < n) | |
| − | + | { | |
| − | + | u := restore(files.[i], null); | |
| − | + | if (u == null) | |
| − | + | log("reload_units: could not restore " + files.[i]); | |
| − | + | i := i + 1; | |
| − | + | } | |
| − | + | quit; | |
| − | + | } | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
dilend | dilend | ||
| + | </pre> | ||
| + | Brings back every stored unit whose file name starts with "corpse.", into the unit that runs it (<code>restore()</code> with null puts it there); adapted from <code>reload_corpse</code> in death.zon. | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/store()|store()]] | |
| − | + | * [[Manual:DIL Manual/restore()|restore()]] | |
| − | + | * [[Manual:DIL Manual/delunit()|delunit()]] | |
| − | + | * [[Manual:DIL Manual/strdir()|strdir()]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 23:15, 14 November 2026
unitdir()
Function (stringlist). Lists the unit files that DIL has stored, by a pattern.
unitdir(pattern : string)
Returns the names of the files in the units directory that match pattern: the files store() writes and restore() and delunit() read. death.zon uses unitdir(".*") at boot to bring back the corpses that were stored before a crash or reboot.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pattern | string | A regular expression that must match the whole file name. "" means all files. |
Returns
Stringlist: the matching file names, in no particular order (the order the directory gives them). Empty when nothing matches or the directory doesn't exist. It fails if pattern fails, is a string variable that has never had a value, or is not a valid regular expression; assigning a failed list leaves the variable as it was.
Notes
- The pattern is a regular expression (Perl style), not a shell wildcard:
".*"is everything,"corpse[.].*"is every name starting with "corpse.", and a plain.matches any character. A shell-style"*"is not a valid expression. - The directory is
units/under the zone's DIL file directory: the sixth column of the zone's line invme/etc/zonelist(death has../lib/death), or elsedil_file_dirinserver.cfg. The zone is that of the program the unit runs; a function from another zone that it calls (f@otherzone) still looks in the calling program's directory. - Only file names are returned, without a path, ready for
restore().
Example
dilbegin aware reload_units();
var
files : stringlist;
u : unitptr;
i : integer;
n : integer;
code
{
files := unitdir("corpse[.].*");
n := length(files);
i := 0;
while (i < n)
{
u := restore(files.[i], null);
if (u == null)
log("reload_units: could not restore " + files.[i]);
i := i + 1;
}
quit;
}
dilend
Brings back every stored unit whose file name starts with "corpse.", into the unit that runs it (restore() with null puts it there); adapted from reload_corpse in death.zon.