lock utilities #53

Parent #79Owner #2Flags readSource RPG Core/rpgcore-patched.db

Aliases: lock utilities

11 verbs · 11 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
init_scannerthis none thisrxd#534
scan_tokenthis none thisrxd#5334
canonicalize_spacesthis none thisrxd#535
parse_keyexpthis none thisrxd#5315
parse_Ethis none thisrxd#5313
parse_Athis none thisrxd#5343
eval_keythis none thisrxd#5330
match_objectthis none thisrxd#5320
unparse_keythis none thisrxd#5346
eval_key_newthis none thisrxd#5342
parse_A_newthis none thisrxd#5347

Properties

PropertyDefinerFlagsOwnerValue
player#53rc#2#2
input_index#53rc#25
input_length#53rc#24
input_string#53rc#2"here"
index_incremented#53rc#20
help_msg#79rc#2
list of 13{"These routines are used when locking objects, and when testing an object's lock before allowing use (such as in an exit).", "", ":parse_keyexp (string keyexpression, object player)", " => returns an object or list for the new key as defined by the", " keyexpression or a string describing the error if it failed.", "", ":eval_key (LIST|OBJ key, testobject)", " => returns true if the given testobject satisfies the key.", "", ":unparse_key (LIST|OBJ key)", " => returns a string describing the key in english/moo-code terms.", "", "For more information on keys and locking, read `help locking', `help keys', and `help @lock'."}
key#1c#2<clear>
aliases#1rc#2{"lock utilities"}
description#1rc#2"This the lock utilities package, used by the MOOwide locking mechanisms. See `help $lock_utils' for more details."
object_size#1r#36{11190, -1090650497}
html#1rc#2<clear>

Ancestry

Ancestors (nearest first): #79 Generic Utilities Package#1 Root Class

Children: none

Call graph

calls n53_1 #53:scan_token n53_2 #53:canonicalize_spaces n53_1->n53_2 n53_3 #53:parse_keyexp n53_0 #53:init_scanner n53_3->n53_0 n53_4 #53:parse_E n53_3->n53_4 n53_4->n53_1 n53_5 #53:parse_A n53_4->n53_5 n53_5->n53_1 n53_5->n53_4 n53_5->n53_5 n53_7 #53:match_object n53_5->n53_7 n53_6 #53:eval_key n53_6->n53_6 n52_8 #52:contains n53_6->n52_8 n52_5 #52:isa n53_6->n52_5 n53_8 #53:unparse_key n53_8->n53_8 n53_9 #53:eval_key_new n53_9->n53_6 n53_9->n52_8 n52_0 #52:has_property n53_9->n52_0 n52_9 #52:all_contents n53_9->n52_9 n52_2 #52:has_verb n53_9->n52_2 n53_10 #53:parse_A_new n53_10->n53_1 n53_10->n53_4 n53_10->n53_5 n53_10->n53_7

Source

init_scanner

Spec this none thisFlags rxdOwner #2Definer #53

Referenced by

Source

1this.input_string = args[1];
2this.input_length = length(args[1]);
3this.input_index = 1;
4this.index_incremented = 0;

scan_token

Spec this none thisFlags rxdOwner #2Definer #53

Referenced by

Source

1string = this.input_string;
2len = this.input_length;
3i = this.input_index;
4while ((i <= len) && (string[i] == " "))
5i = i + 1;
6endwhile
7if (i > len)
8this.index_incremented = 0;
9return "";
10elseif ((ch = string[i]) in {"(", ")", "!", "?", "~"})
11this.input_index = i + 1;
12this.index_incremented = 1;
13return ch;
14elseif (ch in {"&", "|"})
15this.input_index = i = i + 1;
16this.index_incremented = 1;
17if ((i <= len) && (string[i] == ch))
18this.input_index = i + 1;
19this.index_incremented = 2;
20endif
21return ch + ch;
22else
23start = i;
24while ((i <= len) && (!((ch = string[i]) in {"(", ")", "!", "?", "&", "|", "~"})))
25i = i + 1;
26endwhile
27this.input_index = i;
28i = i - 1;
29while (string[i] == " ")
30i = i - 1;
31endwhile
32this.index_incremented = (i - start) + 1;
33return this:canonicalize_spaces(string[start..i]);
34endif

canonicalize_spaces

Spec this none thisFlags rxdOwner #2Definer #53

Referenced by

Source

1name = args[1];
2while (index(name, "  "))
3name = strsub(name, "  ", " ");
4endwhile
5return name;

parse_keyexp

Spec this none thisFlags rxdOwner #2Definer #53

Referenced by

Source

1"parse_keyexp(STRING keyexpression, OBJ player) => returns a list containing the coded key, or a string containing an error message if the attempt failed.";
2"";
3"Grammar for key expressions:";
4"";
5"    E ::= A       ";
6"       |  E || A  ";
7"       |  E && A  ";
8"    A ::= ( E )   ";
9"       |  ! A     ";
10"       |  object  ";
11"       |  ? object  ";
12"       |  ~ object  ";
13this:init_scanner(args[1]);
14this.player = args[2];
15return this:parse_E();

parse_E

Spec this none thisFlags rxdOwner #2Definer #53

Referenced by

Source

1exp = this:parse_A();
2if (typeof(exp) != STR)
3while ((token = this:scan_token()) in {"&&", "||"})
4rhs = this:parse_A();
5if (typeof(rhs) == STR)
6return rhs;
7endif
8exp = {token, exp, rhs};
9endwhile
10"The while loop above always eats a token. Reset it back so the iteration can find it again. Always losing `)'. Ho_Yan 3/9/95";
11this.input_index = this.input_index - this.index_incremented;
12endif
13return exp;

parse_A

Spec this none thisFlags rxdOwner #2Definer #53

Referenced by

Source

1token = this:scan_token();
2if (token == "(")
3exp = this:parse_E();
4if ((typeof(exp) != STR) && (this:scan_token() != ")"))
5return "Missing ')'";
6else
7return exp;
8endif
9elseif (token == "~")
10exp = this:parse_A();
11if (typeof(exp) == STR)
12return exp;
13else
14return {"~", exp};
15endif
16elseif (token == "!")
17exp = this:parse_A();
18if (typeof(exp) == STR)
19return exp;
20else
21return {"!", exp};
22endif
23elseif (token == "?")
24next = this:scan_token();
25if (next in {"(", ")", "!", "&&", "||", "?", "~"})
26return ("Missing object-name before '" + token) + "'";
27elseif (next == "")
28return "Missing object-name at end of key expression";
29else
30what = this:match_object(next);
31if (typeof(what) == OBJ)
32return {"?", this:match_object(next)};
33else
34return what;
35endif
36endif
37elseif (token in {"&&", "||"})
38return ("Missing expression before '" + token) + "'";
39elseif (token == "")
40return "Missing expression at end of key expression";
41else
42return this:match_object(token);
43endif

eval_key

Spec this none thisFlags rxdOwner #2Definer #53

Referenced by

Source

1"eval_key(LIST|OBJ coded key, OBJ testobject) => returns true if testobject will solve the provided key.";
2{key, who} = args;
3type = typeof(key);
4if (!(type in {LIST, OBJ}))
5return 1;
6elseif (typeof(key) == OBJ)
7return (who == key) || $object_utils:contains(who, key);
8endif
9op = key[1];
10if (op == "~")
11if ($object_utils:isa(who, key[2]))
12return 1;
13endif
14for k in (who.contents)
15(ticks_left() < 4000) && suspend(0);
16if ($object_utils:isa(k, key[2]))
17return 1;
18endif
19endfor
20elseif (op == "!")
21return !this:eval_key(key[2], who);
22elseif (op == "?")
23return key[2]:is_unlocked_for(who);
24elseif (op == "&&")
25return this:eval_key(key[2], who) && this:eval_key(key[3], who);
26elseif (op == "||")
27return this:eval_key(key[2], who) || this:eval_key(key[3], who);
28else
29raise(E_DIV);
30endif

match_object

Spec this none thisFlags rxdOwner #2Definer #53

Referenced by

Source

1"used by $lock_utils to unparse a key expression so one can use `here' and `me' as well as doing the regular object matching.";
2token = args[1];
3if (token == "me")
4return this.player;
5elseif (token == "here")
6if (valid(this.player.location))
7return this.player.location;
8else
9return ("'here' has no meaning where " + this.player.name) + " is";
10endif
11else
12what = this.player.location:match_object(token);
13if (what == $failed_match)
14return ("Can't find an object named '" + token) + "'";
15elseif (what == $ambiguous_match)
16return ("Multiple objects named '" + token) + "'";
17else
18return what;
19endif
20endif

unparse_key

Spec this none thisFlags rxdOwner #2Definer #53

Referenced by

Source

1":unparse_key(LIST|OBJ coded key) => returns a string describing the key in english/moo-code terms.";
2"Example:";
3"$lock_utils:unparse_key({\"||\", $hacker, $housekeeper}) => \"#18105[Hacker] || #36830[housekeeper]\"";
4key = args[1];
5type = typeof(key);
6if (!(type in {LIST, OBJ}))
7return "(None.)";
8elseif (type == OBJ)
9if (valid(key))
10return tostr(key, "[", key.name, "]");
11else
12return tostr(key);
13endif
14else
15op = key[1];
16arg1 = this:unparse_key(key[2]);
17if (op == "?")
18return "?" + arg1;
19elseif (op == "~")
20return "children of " + arg1;
21elseif (op == "!")
22if (typeof(key[2]) == LIST)
23return ("!(" + arg1) + ")";
24else
25return "!" + arg1;
26endif
27elseif (op in {"&&", "||"})
28other = (op == "&&") ? "||" | "&&";
29lhs = arg1;
30rhs = this:unparse_key(key[3]);
31if ((typeof(key[2]) == OBJ) || (key[2][1] != other))
32exp = lhs;
33else
34exp = ("(" + lhs) + ")";
35endif
36exp = ((exp + " ") + op) + " ";
37if ((typeof(key[3]) == OBJ) || (key[3][1] != other))
38exp = exp + rhs;
39else
40exp = ((exp + "(") + rhs) + ")";
41endif
42return exp;
43else
44raise(E_DIV);
45endif
46endif

eval_key_new

Spec this none thisFlags rxdOwner #2Definer #53

Referenced by

none

Source

1set_task_perms($no_one);
2{key, who} = args;
3type = typeof(key);
4if (!(type in {LIST, OBJ}))
5return 1;
6elseif (typeof(key) == OBJ)
7return (who == key) || $object_utils:contains(who, key);
8endif
9op = key[1];
10if (op == "!")
11return !this:eval_key(key[2], who);
12elseif (op == "?")
13return key[2]:is_unlocked_for(who);
14elseif (op == "&&")
15return this:eval_key(key[2], who) && this:eval_key(key[3], who);
16elseif (op == "||")
17return this:eval_key(key[2], who) || this:eval_key(key[3], who);
18elseif (op == ".")
19if ($object_utils:has_property(who, key[2]) && who.(key[2]))
20return 1;
21else
22for thing in ($object_utils:all_contents(who))
23if ($object_utils:has_property(thing, key[2]) && thing.(key[2]))
24return 1;
25endif
26endfor
27endif
28return 0;
29elseif (op == ":")
30if ($object_utils:has_verb(who, key[2]) && who:(key[2])())
31return 1;
32else
33for thing in ($object_utils:all_contents(who))
34if ($object_utils:has_verb(thing, key[2]) && thing:(key[2])())
35return 1;
36endif
37endfor
38endif
39return 0;
40else
41raise(E_DIV);
42endif

parse_A_new

Spec this none thisFlags rxdOwner #2Definer #53

Referenced by

none

Source

1token = this:scan_token();
2if (token == "(")
3exp = this:parse_E();
4if ((typeof(exp) != STR) && (this:scan_token() != ")"))
5return "Missing ')'";
6else
7return exp;
8endif
9elseif (token == "!")
10exp = this:parse_A();
11if (typeof(exp) == STR)
12return exp;
13else
14return {"!", exp};
15endif
16elseif (token == "?")
17next = this:scan_token();
18if (next in {":", ".", "(", ")", "!", "&&", "||", "?", "~"})
19return ("Missing object-name before '" + token) + "'";
20elseif (next == "")
21return "Missing object-name at end of key expression";
22else
23what = this:match_object(next);
24if (typeof(what) == OBJ)
25return {"?", this:match_object(next)};
26else
27return what;
28endif
29endif
30elseif (token in {":", "."})
31next = this:scan_token();
32if (next in {":", ".", "(", ")", "!", "&&", "||", "?", "~"})
33return ("Missing verb-or-property-name before '" + token) + "'";
34elseif (next == "")
35return "Missing verb-or-property-name at end of key expression";
36elseif (typeof(next) != STR)
37return "Non-string verb-or-property-name at end of key expression";
38else
39return {token, next};
40endif
41elseif (token in {"&&", "||"})
42return ("Missing expression before '" + token) + "'";
43elseif (token == "")
44return "Missing expression at end of key expression";
45else
46return this:match_object(token);
47endif