blob: 20391614ea7b9a2b736af9fedc2427f85e7074b7 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001int parse_command(string str, mixed source, string pattern, var1, var2 ...);
2
3Parses commands given in "str" against the pattern in "pattern" and
4returns 1 if it matches. "source" is either an object or an array of objects.
5This is essentially a 'hotted' sscanf and it has a similar syntax, although
6parse_command works on word basis where sscanf works on character basis.
7
8.ip str
9Given command
10.ip source
11Either an array holding the accessible objects, or
12an object from which to recurse and create
13the list of accessible objects, normally
14ob = environment(this_player()) .
15
16.ip pattern
17Parse pattern as list of words and formats:
18.nf
19 Syntax:
20 'word' obligatory text (One word)
21 [word] optional text (One word)
22 / Alternative marker
23 %o Single item, object
24 %l Single living object
25 %s Any text (multiple words)
26 %w Any word
27 %p Preposition
28 %i Any items
29 %d Number 0- or tx(0-99)
30.fi
31Example string: " 'get' / 'take' %i " .
32Items as in %o and %i can on many forms, some examples:
33.nf
34 apple, two apples, twentyfirst apple
35 apples, all apples, all green apples, all green ones
36.fi
37
38.ip varN
39This is the list of result variables as in sscanf.
40One variable is needed for each %_.
41The return types of different %_ is:
42.nf
43 %o Returns an object
44 %l Returns an object
45 %s Returns a string of words
46 %w Returns a string of one word
47 %p Can on entry hold a list of word in array
48 or an empty variable
49 Returns:
50 if empty variable: a string
51 if array: array[0]=matched word
52 %i Returns a special array on the form:
53 [0] = (int) given numeric prefix
54 =0: all or a pluralform given
55 >0: numeral given: two, three, four...
56 <0: order given: second, third ...
57 [1..n] (object) Objectpointers
58 A list of the POSSIBLE objects that can match
59 the given %i. No choosing of third or such.
60 %d Returns a number
61.fi
62.lp
63Example:
64
65a=parse_command("take apple",environment(this_player()),
66 " 'get' / 'take' %i ",items);
67
68HISTORY
69 LDMud 3.3.258 and LP "03.02.1@150" removed the compat-mode
70 parse_command().
71
7229.10.2006 Zesstra