-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathProgrammersManual.texinfo
executable file
·6876 lines (5741 loc) · 292 KB
/
ProgrammersManual.texinfo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\input texinfo @c -*-texinfo-*-
@comment %**start of header
@set INDEX
@setfilename ProgrammersManual.info
@settitle LambdaMOO+Stunt Programmer's Manual
@c Uncomment the following line for two-sided printing.
@c @setchapternewpage odd
@macro lmversion
10-wip
@end macro
@macro lmdate
January 2014
@end macro
@comment %**end of header
@ifinfo
@format
@sp 5
*******************************************
*** LambdaMOO+Stunt Programmer's Manual ***
*******************************************
For LambdaMOO+Stunt Version @lmversion
@lmdate
by Pavel Curtis et al
@sp 4
Copyright @copyright{} 1991, 1992, 1993, 1995, 1996 by Pavel Curtis.
Copyright @copyright{} 1997 by Erik Ostrom.
Copyright @copyright{} 2004 by Roger F. Crew.
Copyright @copyright{} 2011, 2012, 2013, 2014 by Todd Sundsted.
@end format
Permission is granted to make and distribute verbatim copies of this manual
provided the copyright notice and this permission notice are preserved on all
copies.
@ignore
Permission is granted to process this file through TeX and print the results,
provided the printed document carries copying permission notice identical to
this one except for the removal of this paragraph (this paragraph not being
relevant to the printed manual).
@end ignore
Permission is granted to copy and distribute modified versions of this manual
under the conditions for verbatim copying, provided that the entire resulting
derived work is distributed under the terms of a permission notice identical
to this one.
Permission is granted to copy and distribute translations of this manual into
another language, under the above conditions for modified versions, except
that this permission notice may be stated in a translation approved by the
author.
@format
@sp 5
@end format
@end ifinfo
@titlepage
@title LambdaMOO+Stunt Programmer's Manual
@subtitle For LambdaMOO+Stunt Version @lmversion@*
@subtitle @lmdate
@author by Pavel Curtis@*
@author a.k.a. Haakon@*
@author a.k.a. Lambda
@page
@vskip 0pt plus 1filll
Copyright @copyright{} 1991, 1992, 1993, 1995, 1996 by Pavel Curtis.@*
Copyright @copyright{} 1997 by Erik Ostrom.@*
Copyright @copyright{} 2004 by Roger F. Crew.@*
Copyright @copyright{} 2011, 2012, 2013, 2014 by Todd Sundsted.
Copies of the electronic source for this document can be obtained using
anonymous FTP on the Internet. At the site @code{ftp.lambda.moo.mud.org} the
files are @code{pub/MOO/ProgrammersManual.*}; several different file
formats are provided, including HTML, Texinfo, plain text, and PostScript.
Permission is granted to make and distribute verbatim copies of this manual
provided the copyright notice and this permission notice are preserved on all
copies.
Permission is granted to copy and distribute modified versions of this manual
under the conditions for verbatim copying, provided that the entire resulting
derived work is distributed under the terms of a permission notice identical
to this one.
Permission is granted to copy and distribute translations of this manual into
another language, under the above conditions for modified versions, except
that this permission notice may be stated in a translation approved by the
author.
@end titlepage
@node Top, Introduction, (dir), (dir)
@comment node-name, next, previous, up
@ifnothtml
@ifset INFO
@format
*******************************************
*** LambdaMOO+Stunt Programmer's Manual ***
*******************************************
For LambdaMOO+Stunt Version @lmversion
@lmdate
by Pavel Curtis et al
Copyright @copyright{} 1991, 1992, 1993, 1995, 1996 by Pavel Curtis.
Copyright @copyright{} 1997 by Erik Ostrom.
Copyright @copyright{} 2004 by Roger F. Crew.
Copyright @copyright{} 2011, 2012, 2013, 2014 by Todd Sundsted.
@end format
@end ifset
@end ifnothtml
@menu
* Introduction:: What is LambdaMOO?
* Database:: The LambdaMOO Database
* Parsing:: The Built-in Command Parser
* Language:: The MOO Programming Language
* Server:: Server Commands and Database Assumptions
* Function Index:: Index to All Built-In Functions
@end menu
@ifhtml
@contents
@end ifhtml
@c evidently, space is not allowed here
@c
@node Introduction, Database, Top, Top
@comment node-name, next, previous, up
@chapter Introduction
LambdaMOO is a network-accessible, multi-user, programmable, interactive
system well-suited to the construction of text-based adventure games,
conferencing systems, and other collaborative software. Its most common use,
however, is as a multi-participant, low-bandwidth virtual reality, and it is
with this focus in mind that I describe it here.
Participants (usually referred to as @dfn{players}) connect to LambdaMOO using
Telnet or some other, more specialized, @dfn{client} program. Upon
connection, they are usually presented with a @dfn{welcome message} explaining
how to either create a new @dfn{character} or connect to an existing one.
Characters are the embodiment of players in the virtual reality that is
LambdaMOO.
Having connected to a character, players then give one-line commands that are
parsed and interpreted by LambdaMOO as appropriate. Such commands may cause
changes in the virtual reality, such as the location of a character, or may
simply report on the current state of that reality, such as the appearance of
some object.
The job of interpreting those commands is shared between the two major
components in the LambdaMOO system: the @dfn{server} and the @dfn{database}.
The server is a program, written in a standard programming language, that
manages the network connections, maintains queues of commands and other tasks
to be executed, controls all access to the database, and executes other
programs written in the MOO programming language. The database contains
representations of all the objects in the virtual reality, including the MOO
programs that the server executes to give those objects their specific
behaviors.
Almost every command is parsed by the server into a call on a MOO procedure,
or @dfn{verb}, that actually does the work. Thus, programming in the MOO
language is a central part of making non-trivial extensions to the database
and thus, the virtual reality.
In the next chapter, I describe the structure and contents of a LambdaMOO
database. The following chapter gives a complete description of how the
server performs its primary duty: parsing the commands typed by players.
Next, I describe the complete syntax and semantics of the MOO programming
language. Finally, I describe all of the database conventions assumed by the
server.
@quotation Note
This manual describes only those aspects of LambdaMOO that are
entirely independent of the contents of the database. It does not describe,
for example, the commands or programming interfaces present in the LambdaCore
database.
@end quotation
@node Database, Parsing, Introduction, Top
@comment node-name, next, previous, up
@chapter The LambdaMOO Database
In this chapter, I begin by describing in detail the various kinds of data
that can appear in a LambdaMOO database and that, therefore, MOO programs can
manipulate. In a few places, I refer to the @dfn{LambdaCore} database. This
is one particular LambdaMOO database, created every so often by extracting the
``core'' of the current database for the original LambdaMOO.
@quotation Note
The original LambdaMOO resides on the host
@code{lambda.moo.mud.org} on port 8888. Feel free to drop by! A copy of the most
recent release of the LambdaCore database can be obtained by anonymous FTP from
host @code{ftp.lambda.moo.mud.org} in the directory @code{pub/MOO}.
@end quotation
@menu
* Values:: MOO Value Types
* Objects:: Objects in the MOO Database
@end menu
@node Values, Objects, Database, Database
@comment node-name, next, previous, up
@section MOO Value Types
There are a few kinds of values that MOO programs can manipulate:
@itemize @bullet
@item
object references (to the anonymous objects in the database)
@item
object numbers (of the permanent objects in the database)
@item
integers (in a specific, large range)
@item
real numbers (represented with floating-point numbers)
@item
strings (of characters)
@item
errors (arising during program execution)
@item
lists (of all of the above, including lists)
@item
maps (or collections of key/value pairs)
@end itemize
@dfn{Objects} are the backbone of the MOO database and, as such, deserve a
great deal of discussion; the entire next section is devoted to them. For now,
let it suffice to say that there are two kinds of objects, anonymous objects
and permanent objects. Anonymous objects are typically transient and are
garbage collected when they are no longer needed. Permanent objects, as their
name implies, are typically longed lived. Every permanent object is assigned a
unique @dfn{object number} and must be accessed via that object number. The
lifecycle of a permanent object is explicitly managed by the programmer.
A reference to an anonymous object is returned when the anonymous object is
created with @code{create()}. References can be shared but they cannot be
forged. That is, there is no literal representation of a reference to an
anonymous object (that's why they are @emph{anonymous}).
The @dfn{object number} of a permanent object is also returned when the
permanent object is created with @code{create()}. However, there is a literal
representation of an object number. In programs, we write a reference to a
particular permanent object by putting a hash mark (@samp{#}) followed by the
number, like this:
@example
#495
@end example
@noindent
Object numbers are always integers.
An object number may or may not refer to an actual, live permanent object. If
it does, we say that the object number is @emph{valid}. If it does not, we say
that the object number is @emph{invalid}.
There are three special object numbers used for a variety of purposes:
@code{#-1}, @code{#-2}, and @code{#-3}, usually referred to in the
LambdaCore database as @code{$nothing}, @code{$ambiguous_match}, and
@code{$failed_match}, respectively.
MOO supports the integers from @minus{}2^31 (that is, negative two to the power
of 31) up to 2^31 @minus{} 1 (one less than two to the power of 31); that's
from @minus{}2147483648 to 2147483647, enough for most purposes. In MOO
programs, integers are written just as you see them here, an optional minus
sign followed by a non-empty sequence of decimal digits. In particular, you
may not put commas, periods, or spaces in the middle of large integers, as we
sometimes do in English and other natural languages (e.g., `2,147,483,647').
Real numbers in MOO are represented as they are in almost all other programming
languages, using so-called @dfn{floating-point} numbers. These have certain
(large) limits on size and precision that make them useful for a wide range of
applications. Floating-point numbers are written with an optional minus sign
followed by a non-empty sequence of digits punctuated at some point with a
decimal point (`.') and/or followed by a scientific-notation marker (the letter
`E' or `e' followed by an optional sign and one or more digits). Here are some
examples of floating-point numbers:
@example
325.0 325. 3.25e2 0.325E3 325.E1 .0325e+4 32500e-2
@end example
@noindent
All of these examples mean the same number. The third of these, as an example
of scientific notation, should be read ``3.25 times 10 to the power of 2''.
@quotation
@emph{Fine points:} The MOO represents floating-point numbers using the local
meaning of the C-language @code{double} type, which is almost always equivalent
to IEEE 754 double precision floating point. If so, then the smallest positive
floating-point number is no larger than @code{2.2250738585072014e-308} and the
largest floating-point number is @code{1.7976931348623157e+308}.
IEEE infinities and NaN values are not allowed in MOO. The error
@code{E_FLOAT} is raised whenever an infinity would otherwise be computed;
@code{E_INVARG} is raised whenever a NaN would otherwise arise. The value
@code{0.0} is always returned on underflow.
@end quotation
Character @dfn{strings} are arbitrarily-long sequences of normal, ASCII
printing characters. When written as values in a program, strings are
enclosed in double-quotes, like this:
@example
"This is a character string."
@end example
@noindent
To include a double-quote in the string, precede it with a backslash
(@samp{\}), like this:
@example
"His name was \"Leroy\", but nobody ever called him that."
@end example
@noindent
Finally, to include a backslash in a string, double it:
@example
"Some people use backslash ('\\') to mean set difference."
@end example
@noindent
MOO strings may not include special ASCII characters like carriage-return,
line-feed, bell, etc. The only non-printing characters allowed are spaces and
tabs.
@anchor{note-Binary Strings}
@quotation
@emph{Fine point:} There is a special kind of string used for representing the
arbitrary bytes used in general, binary input and output. In a @dfn{binary
string}, any byte that isn't an ASCII printing character or the space character
is represented as the three-character substring "~XX", where XX is the
hexadecimal representation of the byte; the input character `~' is represented
by the three-character substring "~7E". This special representation is used by
the functions @code{encode_binary()} and @code{decode_binary()} and by the
functions @code{notify()} and @code{read()} with network connections that are
in binary mode. See the descriptions of the @code{set_connection_option()},
@code{encode_binary()}, and @code{decode_binary()} functions for more details.
@end quotation
@dfn{Errors} are, by far, the least frequently used values in MOO. In the
normal case, when a program attempts an operation that is erroneous for some
reason (for example, trying to add a number to a character string), the server
stops running the program and prints out an error message. However, it is
possible for a program to stipulate that such errors should not stop execution;
instead, the server should just let the value of the operation be an error
value. The program can then test for such a result and take some appropriate
kind of recovery action. In programs, error values are written as words
beginning with @samp{E_}. The complete list of error values, along with their
associated messages, is as follows:
@example
E_NONE @r{No error}
E_TYPE @r{Type mismatch}
E_DIV @r{Division by zero}
E_PERM @r{Permission denied}
E_PROPNF @r{Property not found}
E_VERBNF @r{Verb not found}
E_VARNF @r{Variable not found}
E_INVIND @r{Invalid indirection}
E_RECMOVE @r{Recursive move}
E_MAXREC @r{Too many verb calls}
E_RANGE @r{Range error}
E_ARGS @r{Incorrect number of arguments}
E_NACC @r{Move refused by destination}
E_INVARG @r{Invalid argument}
E_QUOTA @r{Resource limit exceeded}
E_FLOAT @r{Floating-point arithmetic error}
E_FILE @r{File error}
E_EXEC @r{Exec error}
E_INTRPT @r{Interrupted}
@end example
MOO supports two kinds of collections. Collections hold zero or more related
MOO values, including other collections.
The first kind of collection in MOO programs is a @dfn{list}. A list is a
sequence of arbitrary MOO values, possibly including other lists. In programs,
lists are written in mathematical set notation with each of the elements
written out in order, separated by commas, the whole enclosed in curly braces
(@samp{@{} and @samp{@}}). For example, a list of the names of the days of the
week is written like this:
@example
@{"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"@}
@end example
@noindent
Note that it doesn't matter that we put a line-break in the middle of
the list. This is true in general in MOO: anywhere that a space can go,
a line-break can go, with the same meaning. The only exception is
inside character strings, where line-breaks are not allowed.
The other kind of collection is a @dfn{map}. A map, which is sometimes called
a ``dictionary'', implements an ordered associative relationship between pairs
of MOO values. The first value in the pair is typically called the ``key'' and
the second value is typically called the ``value''. The value can hold any MOO
value, including lists and other maps. The key can hold any non-collection
value (that is, it cannot hold a list or map) and each key in a map must be
unique. In programs, maps are written as a sequence of key/value pairs,
separated by commas, enclosed in brackets (@samp{[} and @samp{]}). In each
pair, the key and value are separated by an arrow (@samp{->}). A map of names
to ages is written like this:
@example
["Bob" -> 23, "Sally" -> 13, "Dave" -> 19,
"Peter" -> 27, "Karen" -> 27]
@end example
@noindent
Note that while the keys must be unique, the values are not required to be so.
@node Objects, , Values, Database
@comment node-name, next, previous, up
@section Objects in the MOO Database
Objects are, in a sense, the whole point of the MOO programming language.
Objects encapsulate state and behavior -- as they do in other object-oriented
programming languages. Permanent objects are also used to represent objects in
the virtual reality, like people, rooms, exits, and other concrete things.
Because of this, MOO makes a bigger deal out of creating objects than it does
for other kinds of values, like integers.
Numbers always exist, in a sense; you have only to write them down in order to
operate on them. With objects, it is different. The permanent object with
number @samp{#958} does not exist just because you write down its number. An
explicit operation, the @samp{create()} function described later, is required
to bring an object into existence. Symmetrically, once created, objects
continue to exist until there are no more references to them (for anonymous
objects) or they are explicitly destroyed by the @samp{recycle()} function
(for both anonymous and permanent objects).
The identifying number associated with a permanent object is unique to that
object. It was assigned when the object was created and will never be reused,
even if the object is destroyed. Thus, if we create an object and it is
assigned the number @samp{#1076}, the next object to be created will be
assigned @samp{#1077}, even if @samp{#1076} is destroyed in the meantime.
Both anonymous and permanent objects are made up of three kinds of pieces that
together define their behavior: @dfn{attributes}, @dfn{properties}, and
@dfn{verbs}.
@menu
* Attributes:: Fundamental Object Attributes
* Properties:: Properties on Objects
* Verbs:: Verbs on Objects
@end menu
@node Attributes, Properties, Objects, Objects
@comment node-name, next, previous, up
@subsection Fundamental Object Attributes
There are three fundamental @dfn{attributes} to every object:
@enumerate 1
@item
A flag (either true or false) specifying whether or not the object represents
a player,
@item
A list of object that are its @dfn{parents}, and
@item
A list of the objects that are its @dfn{children}; that is, those objects for
which this object is one of their parents.
@end enumerate
The act of creating a character sets the player attribute of an object and only
a wizard (using the function @code{set_player_flag()}) can change that setting.
Only characters have the player bit set to 1. Currently, only permanent
objects can be players.
The parent/child relationship is used for sharing behavior among objects.
For example, the LambdaCore database contains an object representing a sort of
``generic'' room. All other rooms are @dfn{descendants} (i.e., children or
children's children, or @dots{}) of that one. The generic room defines those
pieces of behavior that are common to all rooms; other rooms specialize that
behavior for their own purposes. The notion of objects and specialization is
the very essence of what is meant by @dfn{object-oriented} programming. Only
the functions @code{create()}, @code{recycle()}, @code{chparents()}, and
@code{renumber()} can change the parents and children attributes.
@node Properties, Verbs, Attributes, Objects
@comment node-name, next, previous, up
@subsection Properties on Objects
A @dfn{property} is a named ``slot'' in an object that can hold an arbitrary
MOO value. Every object has nine built-in properties whose values are
constrained to be of particular types. In addition, an object can have any
number of other properties, none of which have type constraints. The built-in
properties are as follows:
@example
name @r{a string, the usual name for this object}
owner @r{an object, the player who controls access to it}
location @r{an object, where the object is in virtual reality}
contents @r{a list of objects, the inverse of @samp{location}}
programmer @r{a bit, does the object have programmer rights?}
wizard @r{a bit, does the object have wizard rights?}
r @r{a bit, is the object publicly readable?}
w @r{a bit, is the object publicly writable?}
f @r{a bit, is the object fertile?}
a @r{a bit, can this be a parent of anonymous objects?}
@end example
The @samp{name} property is used to identify the object in various printed
messages. It can only be set by a wizard or by the owner of the object. For
player objects, the @samp{name} property can only be set by a wizard; this
allows the wizards, for example, to check that no two players have the same
name.
The @samp{owner} identifies the object that has owner rights to this object,
allowing them, for example, to change the @samp{name} property. Only a wizard
can change the value of this property.
The @samp{location} and @samp{contents} properties describe a hierarchy of
object containment in the virtual reality. Most objects are located
``inside'' some other object and that other object is the value of the
@samp{location} property. The @samp{contents} property is a list of those
objects for which this object is their location. In order to maintain the
consistency of these properties, only the @code{move()} function is able to
change them.
The @samp{wizard} and @samp{programmer} bits are only applicable to
characters, objects representing players. They control permission to use
certain facilities in the server. They may only be set by a wizard.
The @samp{r} bit controls whether or not players other than the owner of this
object can obtain a list of the properties or verbs in the object.
Symmetrically, the @samp{w} bit controls whether or not non-owners can add or
delete properties and/or verbs on this object. The @samp{r} and @samp{w} bits
can only be set by a wizard or by the owner of the object.
The @samp{f} bit specifies whether or not this object is @dfn{fertile}, whether
or not players other than the owner of this object can create new objects with
this one as a parent. It also controls whether or not non-owners can use the
@code{chparents()} built-in function to make this object a parent of an
existing object. The @samp{f} bit can only be set by a wizard or by the owner
of the object.
The @samp{a} bit specifies whether or not this object can be used as a parent
of an anonymous object created by a player other than the owner of this object.
It works similarly to the @samp{f} bit, but governs the creation of anonymous
objects only.
All of the built-in properties on any object can, by default, be read by any
player. It is possible, however, to override this behavior from within the
database, making any of these properties readable only by wizards. See the
chapter on server assumptions about the database for details.
As mentioned above, it is possible, and very useful, for objects to have other
properties aside from the built-in ones. These can come from two sources.
First, an object has a property corresponding to every property in its parent
objects. To use the jargon of object-oriented programming, this is a kind of
@dfn{inheritance}. If some object has a property named @samp{foo}, then so
will all of its children and thus its children's children, and so on.
Second, an object may have a new property defined only on itself and its
descendants. For example, an object representing a rock might have properties
indicating its weight, chemical composition, and/or pointiness, depending upon
the uses to which the rock was to be put in the virtual reality.
Every defined property (as opposed to those that are built-in) has an owner
and a set of permissions for non-owners. The owner of the property can get
and set the property's value and can change the non-owner permissions. Only a
wizard can change the owner of a property.
The initial owner of a property is the player who added it; this is usually,
but not always, the player who owns the object to which the property was
added. This is because properties can only be added by the object owner or a
wizard, unless the object is publicly writable (i.e., its @samp{w} property is
1), which is rare. Thus, the owner of an object may not necessarily be the
owner of every (or even any) property on that object.
The permissions on properties are drawn from this set: @samp{r} (read),
@samp{w} (write), and @samp{c} (change ownership in descendants). Read
permission lets non-owners get the value of the property and, of course, write
permission lets them set that value. The @samp{c} permission bit is a little
more complicated.
Recall that every object has all of the properties that its parents do and
perhaps some more. Ordinarily, when a child object inherits a property from
its parents, the owner of the child becomes the owner of that property. This
is because the @samp{c} permission bit is ``on'' by default. If the @samp{c}
bit is not on, then the inherited property has the same owner in the child as
it does in the parent.
As an example of where this can be useful, the LambdaCore database ensures
that every player has a @samp{password} property containing the encrypted
version of the player's connection password. For security reasons, we don't
want other players to be able to see even the encrypted version of the
password, so we turn off the @samp{r} permission bit. To ensure that the
password is only set in a consistent way (i.e., to the encrypted version of a
player's password), we don't want to let anyone but a wizard change the
property. Thus, in the parent object for all players, we made a wizard the
owner of the password property and set the permissions to the empty string,
@code{""}. That is, non-owners cannot read or write the property and, because
the @samp{c} bit is not set, the wizard who owns the property on the parent
class also owns it on all of the descendants of that class.
Another, perhaps more down-to-earth example arose when a character named Ford
started building objects he called ``radios'' and another character, yduJ,
wanted to own one. Ford kindly made the generic radio object fertile, allowing
yduJ to create a child object of it, her own radio. Radios had a property
called @samp{channel} that identified something corresponding to the frequency
to which the radio was tuned. Ford had written nice programs on radios (verbs,
discussed below) for turning the channel selector on the front of the radio,
which would make a corresponding change in the value of the @samp{channel}
property. However, whenever anyone tried to turn the channel selector on
yduJ's radio, they got a permissions error. The problem concerned the
ownership of the @samp{channel} property.
As I explain later, programs run with the permissions of their author. So, in
this case, Ford's nice verb for setting the channel ran with his permissions.
But, since the @samp{channel} property in the generic radio had the @samp{c}
permission bit set, the @samp{channel} property on yduJ's radio was owned by
her. Ford didn't have permission to change it! The fix was simple. Ford
changed the permissions on the @samp{channel} property of the generic radio to
be just @samp{r}, without the @samp{c} bit, and yduJ made a new radio. This
time, when yduJ's radio inherited the @samp{channel} property, yduJ did not
inherit ownership of it; Ford remained the owner. Now the radio worked
properly, because Ford's verb had permission to change the channel.
@node Verbs, , Properties, Objects
@comment node-name, next, previous, up
@subsection Verbs on Objects
The final kind of piece making up an object is @dfn{verbs}. A verb is a named
MOO program that is associated with a particular object. Most verbs implement
commands that a player might type; for example, in the LambdaCore database,
there is a verb on all objects representing containers that implements
commands of the form `put @var{object} in @var{container}'. It is also
possible for MOO programs to invoke the verbs defined on objects. Some verbs,
in fact, are designed to be used only from inside MOO code; they do not
correspond to any particular player command at all. Thus, verbs in MOO are
like the `procedures' or `methods' found in some other programming languages.
As with properties, every verb has an owner and a set of permission bits. The
owner of a verb can change its program, its permission bits, and its argument
specifiers (discussed below). Only a wizard can change the owner of a verb.
The owner of a verb also determines the permissions with which that verb runs;
that is, the program in a verb can do whatever operations the owner of that
verb is allowed to do and no others. Thus, for example, a verb owned by a
wizard must be written very carefully, since wizards are allowed to do just
about anything.
The permission bits on verbs are drawn from this set: @samp{r} (read),
@samp{w} (write), @samp{x} (execute), and @samp{d} (debug). Read permission
lets non-owners see the program for a verb and, symmetrically, write
permission lets them change that program. The other two bits are not,
properly speaking, permission bits at all; they have a universal effect,
covering both the owner and non-owners.
The execute bit determines whether or not the verb can be invoked from within
a MOO program (as opposed to from the command line, like the @samp{put} verb
on containers). If the @samp{x} bit is not set, the verb cannot be called
from inside a program. The @samp{x} bit is usually set.
The setting of the debug bit determines what happens when the verb's program
does something erroneous, like subtracting a number from a character string.
If the @samp{d} bit is set, then the server @dfn{raises} an error value; such
raised errors can be @dfn{caught} by certain other pieces of MOO code. If the
error is not caught, however, the server aborts execution of the command and,
by default, prints an error message on the terminal of the player whose command
is being executed. (See the chapter on server assumptions about the database
for details on how uncaught errors are handled.) If the @samp{d} bit is not
set, then no error is raised, no message is printed, and the command is not
aborted; instead the error value is returned as the result of the erroneous
operation.
@quotation Note
The @samp{d} bit exists only for historical reasons; it used to
be the only way for MOO code to catch and handle errors. With the introduction
of the @code{try}-@code{except} statement and the error-catching expression,
the @samp{d} bit is no longer useful. All new verbs should have the @samp{d}
bit set, using the newer facilities for error handling if desired. Over time,
old verbs written assuming the @samp{d} bit would not be set should be changed
to use the new facilities instead.
@end quotation
In addition to an owner and some permission bits, every verb has three
`argument specifiers', one each for the direct object, the preposition, and
the indirect object. The direct and indirect specifiers are each drawn from
this set: @samp{this}, @samp{any}, or @samp{none}. The preposition specifier
is @samp{none}, @samp{any}, or one of the items in this list:
@example
with@r{/}using
at@r{/}to
in front of
in@r{/}inside@r{/}into
on top of@r{/}on@r{/}onto@r{/}upon
out of@r{/}from inside@r{/}from
over
through
under@r{/}underneath@r{/}beneath
behind
beside
for@r{/}about
is
as
off@r{/}off of
@end example
The argument specifiers are used in the process of parsing commands,
described in the next chapter.
@node Parsing, Language, Database, Top
@comment node-name, next, previous, up
@chapter The Built-in Command Parser
The MOO server is able to do a small amount of parsing on the commands
that a player enters. In particular, it can break apart commands that
follow one of the following forms:
@example
@var{verb}
@var{verb} @var{direct-object}
@var{verb} @var{direct-object} @var{preposition} @var{indirect-object}
@end example
Real examples of these forms, meaningful in the LambdaCore database, are
as follows:
@example
look
take yellow bird
put yellow bird in cuckoo clock
@end example
Note that English articles (i.e., @samp{the}, @samp{a}, and @samp{an}) are not
generally used in MOO commands; the parser does not know that they are
not important parts of objects' names.
To have any of this make real sense, it is important to understand
precisely how the server decides what to do when a player types a
command.
But first, we mention the three situations in which
a line typed by a player is @emph{not} treated as an ordinary command:
@enumerate
@item
The line may exactly match the connection's defined @dfn{flush command},
if any (@samp{.flush} by default), in which case
all pending lines of input are cleared
and nothing further is done with the flush command itself.
Likewise, any line may be flushed by a subsequent flush command
before the server otherwise gets a chance to process it.
For more on this, see @ref{Flushing,.flush,Flushing Unprocessed Input}.
@item
The line may begin with a prefix that qualifies it
for @dfn{out-of-band} processing and thence, perhaps,
as an @dfn{out-of-band command}.
For more on this, see @ref{Out-of-band Processing,OOB,Out-of-band Processing}.
@item
The connection may be subject to a @code{read()} call
(@pxref{Manipulating Connections,read(),Operations on Network Connections})
or there may be a @code{.program} command in progress
(@pxref{Programming,.program,The @code{.program} Command}),
either of which will consume the line accordingly.
Also note that if connection option @code{"hold-input"} has been set,
all in-band lines typed by the player are held at this point for future reading,
even if no reading task is currently active.
@end enumerate
@noindent
Otherwise, we (finally) have an actual command line that can undergo
@dfn{normal command parsing} as follows:
The server checks whether or not the first non-blank character in the
command is one of the following:
@example
" : ;
@end example
@noindent
If so, that character is replaced by the corresponding command below, followed
by a space:
@example
say emote eval
@end example
@need 2000
@noindent
For example, the command
@example
"Hi, there.
@end example
@noindent
is treated exactly as if it were as follows:
@example
say Hi, there.
@end example
The server next breaks up the command into words. In the simplest case,
the command is broken into words at every run of space characters; for example,
the command @samp{foo bar baz} would be broken into the words @samp{foo},
@samp{bar}, and @samp{baz}. To force the server to include spaces in a
``word'', all or part of a word can be enclosed in double-quotes. For example,
the command
@example
foo "bar mumble" baz" "fr"otz" bl"o"rt
@end example
@noindent
is broken into the words @samp{foo}, @samp{bar mumble}, @samp{baz frotz}, and
@samp{blort}. Finally, to include a double-quote or a backslash in a word,
they can be preceded by a backslash, just like in MOO strings.
Having thus broken the string into words, the server next checks to see if the
first word names any of the five ``intrinsic'' commands: @samp{.program},
@samp{PREFIX}, @samp{OUTPUTPREFIX}, @samp{SUFFIX}, @samp{OUTPUTSUFFIX}.
The first one of these is only available to programmers, the other four are
intended for use by client programs; all five are described in the final
chapter of this document, @ref{Server,,Server Commands and Database Assumptions}.
If the first word isn't one of the above, then we get to the usual case: a
normal MOO command.
The server next gives code in the database a chance to handle the command. If
the verb @code{$do_command()} exists, it is called with the words of the
command passed as its arguments and @code{argstr} set to the raw command typed
by the user. If @code{$do_command()} does not exist, or if that verb-call
completes normally (i.e., without suspending or aborting) and returns a false
value, then the built-in command parser is invoked to handle the command as
described below. Otherwise, it is assumed that the database code handled the
command completely and no further action is taken by the server for that
command.
If the built-in command parser is invoked, the server tries to parse the
command into a verb, direct object, preposition and indirect object. The first
word is taken to be the verb. The server then tries to find one of the
prepositional phrases listed at the end of the previous section, using the
match that occurs earliest in the command. For example, in the very odd
command @samp{foo as bar to baz}, the server would take @samp{as} as the
preposition, not @samp{to}.
If the server succeeds in finding a preposition, it considers the words
between the verb and the preposition to be the direct object and those
after the preposition to be the indirect object. In both cases, the
sequence of words is turned into a string by putting one space between
each pair of words. Thus, in the odd command from the previous
paragraph, there are no words in the direct object (i.e., it is
considered to be the empty string, @code{""}) and the indirect object is
@code{"bar to baz"}.
If there was no preposition, then the direct object is taken to be all
of the words after the verb and the indirect object is the empty string.
The next step is to try to find MOO objects that are named by the direct
and indirect object strings.
First, if an object string is empty, then the corresponding object is the
special object @code{#-1} (aka @code{$nothing} in LambdaCore). If an object
string has the form of an object number (i.e., a hash mark (@samp{#}) followed
by digits), and the object with that number exists, then that is the named
object. If the object string is either @code{"me"} or @code{"here"}, then the
player object itself or its location is used, respectively.
Otherwise, the server considers all of the objects whose location is either
the player (i.e., the objects the player is ``holding'', so to speak) or the
room the player is in (i.e., the objects in the same room as the player); it
will try to match the object string against the various names for these
objects.
The matching done by the server uses the @samp{aliases} property of each of the
objects it considers. The value of this property should be a list of strings,
the various alternatives for naming the object. If it is not a list, or the
object does not have an @samp{aliases} property, then the empty list is used.
In any case, the value of the @samp{name} property is added to the list for the
purposes of matching.
The server checks to see if the object string in the command is either exactly
equal to or a prefix of any alias; if there are any exact matches, the prefix
matches are ignored. If exactly one of the objects being considered has a
matching alias, that object is used. If more than one has a match, then the
special object @code{#-2} (aka @code{$ambiguous_match} in LambdaCore) is used.
If there are no matches, then the special object @code{#-3} (aka
@code{$failed_match} in LambdaCore) is used.
So, now the server has identified a verb string, a preposition string,
and direct- and indirect-object strings and objects. It then looks at
each of the verbs defined on each of the following four objects, in
order:
@enumerate 1
@item
the player who typed the command,
@item
the room the player is in,
@item
the direct object, if any, and
@item
the indirect object, if any.
@end enumerate
@noindent
For each of these verbs in turn, it tests if all of the the following
are true:
@itemize @bullet
@item
the verb string in the command matches one of the names for the
verb,
@item
the direct- and indirect-object values found by matching are allowed by
the corresponding argument specifiers for the verb, and
@item
the preposition string in the command is matched by the preposition
specifier for the verb.
@end itemize
@noindent
I'll explain each of these criteria in turn.
Every verb has one or more names; all of the names are kept in a single
string, separated by spaces. In the simplest case, a verb-name is just
a word made up of any characters other than spaces and stars (i.e., ` '
and @samp{*}). In this case, the verb-name matches only itself; that
is, the name must be matched exactly.
If the name contains a single star, however, then the name matches any prefix
of itself that is at least as long as the part before the star. For example,
the verb-name @samp{foo*bar} matches any of the strings @samp{foo},
@samp{foob}, @samp{fooba}, or @samp{foobar}; note that the star itself is not
considered part of the name.
If the verb name @emph{ends} in a star, then it matches any string that begins
with the part before the star. For example, the verb-name @samp{foo*} matches
any of the strings @samp{foo}, @samp{foobar}, @samp{food}, or @samp{foogleman},
among many others. As a special case, if the verb-name is @samp{*} (i.e., a
single star all by itself), then it matches anything at all.
Recall that the argument specifiers for the direct and indirect objects are
drawn from the set @samp{none}, @samp{any}, and @samp{this}. If the specifier
is @samp{none}, then the corresponding object value must be @code{#-1} (aka
@code{$nothing} in LambdaCore); that is, it must not have been specified. If
the specifier is @samp{any}, then the corresponding object value may be
anything at all. Finally, if the specifier is @samp{this}, then the
corresponding object value must be the same as the object on which we found
this verb; for example, if we are considering verbs on the player, then the
object value must be the player object.
Finally, recall that the argument specifier for the preposition is
either @samp{none}, @samp{any}, or one of several sets of prepositional
phrases, given above. A specifier of @samp{none} matches only if there
was no preposition found in the command. A specifier of @samp{any}
always matches, regardless of what preposition was found, if any. If
the specifier is a set of prepositional phrases, then the one found must
be in that set for the specifier to match.
So, the server considers several objects in turn, checking each of their
verbs in turn, looking for the first one that meets all of the criteria
just explained. If it finds one, then that is the verb whose program
will be executed for this command. If not, then it looks for a verb
named @samp{huh} on the room that the player is in; if one is found,
then that verb will be called. This feature is useful for implementing
room-specific command parsing or error recovery. If the server can't
even find a @samp{huh} verb to run, it prints an error message like
@samp{I couldn't understand that.} and the command is considered complete.
At long last, we have a program to run in response to the command typed by the
player. When the code for the program begins execution, the following
built-in variables will have the indicated values:
@example
player @r{an object, the player who typed the command}
this @r{an object, the object on which this verb was found}
caller @r{an object, the same as @samp{player}}
verb @r{a string, the first word of the command}
argstr @r{a string, everything after the first word of the command}
args @r{a list of strings, the words in @samp{argstr}}
dobjstr @r{a string, the direct object string found during parsing}
dobj @r{an object, the direct object value found during matching}
prepstr @r{a string, the prepositional phrase found during parsing}
iobjstr @r{a string, the indirect object string}
iobj @r{an object, the indirect object value}
@end example
@noindent
The value returned by the program, if any, is ignored by the server.
@node Language, Server, Parsing, Top
@comment node-name, next, previous, up
@chapter The MOO Programming Language