Advertisement
Nofew

muf-cheat

Oct 20th, 2015
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.97 KB | None | 0 0
  1. The MUF Cheat-Sheet, as seen by Sammael (Arthur, The., etc)
  2. -or-
  3. Reference manual for MUCK Forth ("MUF") -terse
  4.  
  5. v2.2fb4.0 July 29, 1990
  6.  
  7. ENTERING EDITING MODE
  8. @program <program name> (creates a new program if none match)
  9. @edit <program name or number>
  10.  
  11. EDITING COMMANDS
  12. <number> i insert before <number>
  13. . exit insert mode
  14. c compile
  15. <number1> <number2> l list
  16. <number1> <number2> d delete
  17. <letter> <letter> a show macros (abridged)
  18. <letter> <letter> s show macros (long)
  19. <program#> v view program header
  20. <program#> p list prog's public functs.
  21. h help on edit mode
  22. u uncompile
  23. q quit editor mode
  24.  
  25.  
  26. COMPILER DIRECTIVES
  27.  
  28. $echo <string> Echos <string> during compile
  29. $define <defname> <defin.> $enddef Defines <defname> to <defin.>
  30. $def <defname> <defin.> Same, but stops at end of line
  31. $undef <defname> Undefines <defname>
  32. $include <obj> Load $defines from <obj>
  33. $ifdef <defname>[<comparison>] Starts $ifdef clause.
  34. $ifndef <defname>[<comparison>] Starts $ifndef clause.
  35. $else Compile if $if[n]def failed.
  36. $endif Marks end of $if[n]def clause
  37.  
  38. note: __version is a standard $define, containing the server version.
  39.  
  40.  
  41. STRUCTURES
  42.  
  43. A function has the format of
  44. : <funcname> <instruction> [<instruction> ... ] ;
  45.  
  46. If-then statements use the structure
  47. <comparisons> if <cmds_if_true> [else <cmds_if_false>] then
  48.  
  49. Loops can use two different structures.
  50. begin
  51. <instructions>
  52. <comparisons>
  53. until (repeats loop until comparison is true)
  54. begin
  55. <instructions>
  56. repeat (repeat loop)
  57.  
  58. Both types of loops can contain as many of the following as needed.
  59. <comparison> while (if comparison is false, exit the loop)
  60. break (exit the loop. Often used inside if-thens)
  61. continue (go to the start of the loop. used in if-thens)
  62.  
  63.  
  64. PRIMITIVE TERMINOLOGY
  65.  
  66. v type variable
  67. d type dbref
  68. i type int (boolean)
  69. s type string
  70. a type address (word)
  71.  
  72.  
  73. SYNTAX
  74.  
  75. ( ... ) commments
  76. : begin user-def word
  77. ; end user-def word
  78. var <VARNAME> variable declaration
  79. lvar <VARNAME> local variable declaration.
  80. public <FUNCNAME> declares a function public.
  81.  
  82. checkargs ( s -- ) checks stack against 's' arg. desc.
  83.  
  84. if ( i -- )
  85. else ( -- )
  86. then ( -- )
  87.  
  88. begin ( -- ) defines the beginning of loops.
  89. while ( i -- ) break out of loop if value is false
  90. break ( -- ) break out of loop.
  91. continue ( -- ) jump to beginning of loop.
  92. until ( i -- ) ends begin-until. repeats if false.
  93. repeat ( -- ) ends begin-repeat. jumps to begin.
  94.  
  95. jmp ( a -- ) jumps execution to given address.
  96. exit ( -- ) exit the current subroutine.
  97. abort ( s -- ) stop MUF prog w/ given error mesg.
  98. execute ( a -- ??? ) call a given subroutine by address.
  99. call ( d -- ??? ) call remote program
  100. or ( d s -- ??? ) call public function in remote prog
  101.  
  102. preempt ( -- ) stops multitasking.
  103. background ( -- ) starts multitasking, no blocking.
  104. foreground ( -- ) starts multitasking, blocking user
  105. input for that user.
  106.  
  107. sleep ( i -- ) pause the program for i seconds
  108. fork ( -- i ) forks off BG muf process. Returns
  109. pid to parent and 0 to child.
  110. queue ( i d s -- i ) queue event to run prog d after i
  111. seconds with s on the stack.
  112. Returns pid of queued process.
  113. kill ( i -- ) kills process of given pid.
  114. ispid? ( i -- i ) processID -- process_exists?
  115.  
  116. pop ( x -- )
  117. dup ( x -- x x )
  118. swap ( x y -- y x )
  119. over ( x y -- x y x )
  120. rot ( x y z -- y z x )
  121. rotate ( ni ... n1 i -- n(i-1) ... n1 ni )
  122. pick ( ni ... n1 i -- n1 ni )
  123. put ( ni ... n1 x i -- x ... n1 )
  124.  
  125. ! ( x v -- ) store value x in var v.
  126. value may be any type data
  127. @ ( v -- x ) fetch value x from var v
  128. atoi ( s -- i ) string --> integer
  129. intostr ( i -- s ) integer || dbref --> string
  130. dbref ( i -- d ) integer --> dbref
  131. int ( x -- i ) VAR || object --> integer
  132. variable ( i -- v ) integer --> VAR ref
  133.  
  134. + - * / % ( i1 i2 -- i )
  135. < > = <= >= ( i1 i2 -- i )
  136. strcmp,
  137. stringcmp ( s1 s2 -- i ) strcmp == case sens.
  138. stringpfx ( s1 s2 -- i ) return 0 if s2 is prefix of s1
  139. strncmp ( s1 s2 n -- i ) compares only n letters
  140. number? ( s -- i )
  141. dbcmp ( d1 d2 -- i )
  142. and or ( i1 i2 -- i )
  143. not ( i -- i' )
  144.  
  145. strlen ( s -- i )
  146. strcat ( s1 s2 -- s )
  147. instr ( s1 s2 -- i ) finds s2 in s1. 0 if !found
  148. strcut ( s i -- s1 s2 ) cuts string at pos. i
  149. explode ( s1 s2 -- ... i ) s2 is the partition, len >0
  150. subst ( s1 s2 s3 -- s ) string, replacement, tobesub
  151. pronoun_sub ( d s -- s' ) does % subs a la osucc/ofail
  152.  
  153. read ( -- s )
  154. notify ( d s -- ) player, message
  155. notify_except ( d1 d2 s -- ) place, player, message
  156. notify_exclude (s dn..d1 i dr-- ) Send s to all players in room
  157. dr except for the i players
  158. listed in d1 through dn.
  159.  
  160. pennies ( d -- i )
  161. addpennies ( d i -- ) player, pennies
  162. random ( -- i )
  163.  
  164. getpropval ( d s -- i ) zero if none
  165. getpropstr ( d s -- s ) "" if none
  166. addprop ( d s1 s2 i -- ) ignores i unless s2 is ""
  167. remove_prop ( d s -- )
  168.  
  169. desc, name, succ,
  170. fail, drop, osucc,
  171. ofail, odrop: ( d -- s ) retrieve message
  172.  
  173. setname, setdesc,
  174. setsucc, setfail,
  175. setdrop, setosucc,
  176. setofail: ( d s -- ) set message
  177.  
  178. player?, thing?,
  179. room?, program?,
  180. exit?, ok?: ( d -- i ) boolean
  181.  
  182. location ( d -- d' )
  183. owner ( d -- d' )
  184. moveto ( d1 d2 -- ) moves d1 to d2
  185. set ( d s -- ) object, string (flag)
  186. flag? ( d s -- i ) object, string -- boolean
  187. mlevel ( d -- i ) object -- mucker level.
  188. match ( s -- d ) thing, dbref (#-1 = NOTHING,
  189. #-2 = AMBIGUOUS, #-3 = HOME)
  190. rmatch ( d s -- d ) object, thing, dbref
  191. part_pmatch ( s -- d ) partial name -- dbref
  192. copyobj ( d -- d' ) returns dbref of new object
  193. contents ( d -- ... i ) returns stack of dbrefs and i
  194.  
  195. time ( -- i i i) seconds, minutes, hours
  196. date ( -- i i i) monthday, month, year
  197. systime ( -- i ) system time in secs since
  198. 00:00 1/1/70 GMT
  199. timesplit ( i -- 8 ints) sec, m, hr, dy, mnth, yr, wkdy, yrdy
  200. timefmt ( s i -- s ) format, systime -- timestring
  201. gmtoffset ( -- s ) seconds offset from GMT time.
  202.  
  203. setlink ( d d -- ) object, dest
  204. setown ( d d -- ) object, newowner
  205. newobject ( d s -- d ) location, name -- new objref
  206. newroom ( d s -- d ) parent, name -- new objref
  207. newexit ( d s -- d ) attached-to, name -- new objref
  208. recycle ( d -- ) item to recycle
  209. stats ( d -- 7 ints) owner -- totalowned, #rooms, #exits,
  210. #things, #programs, #players,
  211. #garbage.
  212.  
  213. int? ( ? -- i ) is top stack item an integer?
  214. string? ( ? -- i ) is top stack item a string?
  215. dbref? ( ? -- i ) is top stack item a dbref?
  216. nextprop ( d s -- s ) object, propname -- next propname
  217. propdir? ( d s -- i ) object, propname--is it a propdir?
  218.  
  219. awake? ( d -- i ) player -- number of connections
  220. online ( -- dN ... d1 N ) all connected players w/ count
  221. concount ( -- i ) # of connections to the server
  222. condbref ( i -- d ) connection number -- player
  223. conidle ( i -- i ) conn. # -- idle time in secs
  224. contime ( i -- i ) conn. # -- online time in secs
  225. conhost ( i -- s ) conn. # -- hostname
  226. conboot ( i -- ) connection number
  227. connotify ( i s -- ) connection number, string
  228. condescr ( i -- i ) connection# -- descriptor#
  229. descrcon ( i -- i ) descriptor# -- connection#
  230. nextdescr ( i -- i ) descriptor# -- next descriptor#
  231. descriptors ( d -- ix..i1 i ) plyr -- descriptors... count
  232.  
  233. bitor ( i i -- i ) int, int -- bitwise or result
  234. bitxor ( i i -- i ) int, int -- bitwise exclusive-or
  235. bitand ( i i -- i ) int, int -- bitwise and result
  236. bitshift ( i i -- i ) int, #bits -- bitwise shift
  237.  
  238. version ( -- s ) Version String
  239. depth ( -- i ) stack depth
  240. dbtop ( -- d ) top of database + 1 item.
  241. prog ( -- d ) this program's dbref
  242. trig ( -- d ) a secure form of trigger @
  243. caller ( -- d ) the program that called this one.
  244.  
  245. force ( d s -- ) player, force string
  246. localvar ( i -- l ) local var num -- localvar
  247.  
  248. locked? ( d d -- i ) player, object -- is object locked?
  249. getlockstr ( d -- s ) object -- lockstring
  250. setlockstr ( d s -- i ) object, lockstr -- successful?
  251.  
  252. toupper ( s -- s ) uppercases all letters in the string
  253. tolower ( s -- s ) lowercases all letters in the string
  254. instring ( s s -- i ) case insensitive version of instr
  255. rinstring ( s s -- i ) case insensitive version of rinstr
  256. striplead ( s -- s ) Strip leading spaces from string.
  257. striptail ( s -- s ) Strip tail spaces from string.
  258. strip ( s -- s ) Basically 'striplead striptail'
  259. unparseobj ( d -- s ) object -- name-and-flags-string.
  260. smatch ( s s -- i ) string, smatch string -- matched?
  261. envpropstr ( d s -- d s ) startobj, propname -- obj strval
  262.  
  263. LIBRARIES
  264. How to use a library:
  265. 1) Use "@register lib" to list what libraries exist.
  266. 2) Use "@view $lib/<libraryname>" to list the docs on that library.
  267. 3) When you've found the library and the function you want, then all
  268. you have to do in your program is, at the beginning of it,
  269. $include $lib/<libraryname>
  270. then just use the function name to invoke it later in your program
  271. and it will run as if it were a function in your program.
  272.  
  273. How to make a library:
  274. 1) create a program with several useful generic subroutines.
  275. 2) DOCUMENT those subroutines in a commented out header in the prog.
  276. 3) @set <program>=_docs:<command to list those DOCS you made>
  277. 4) make sure that all the functions are declared PUBLIC.
  278. 5) Make sure the program is set LINK_OK.
  279. 6) Globally register the program with the @register command with a
  280. prefix of "lib/". ie: @reg lib-strings=lib/strings
  281. 7) Set up the interface for each function on the program. To do this,
  282. you will need to set properties on the program in the form
  283. _defs/<callname>:"$<libname>" match "<funcname>" call
  284. where <callname> is the name that you want to have people use to
  285. invoke it in their programs, <libname> is the registered name you
  286. gave it (ie: lib/strings), and <funcname> is the actual name of
  287. the function in the program. Example:
  288. @set lib-strings=_defs/.split:"$lib/strings" match "split" call
  289. 8) You're done!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement