Advertisement
Guest User

console.txt

a guest
Mar 3rd, 2015
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.56 KB | None | 0 0
  1.  
  2. Comming Soon (if there's any demand):
  3. Console For Programmers
  4. Plugins
  5. Command & Variable hooks
  6. Console consumers
  7. Hungry Man and Slim Jim versions
  8.  
  9.  
  10.  
  11. Console Keys
  12. ------------
  13.  
  14. Tab Tab will complete commands on the first token. It will
  15. also complete variable names if the current token is
  16. prefixed by the variable substitution prefix '$'.
  17. Shift tab will cycle the backwards.
  18.  
  19. ctrl-u Delete the current line in the input buffer.
  20.  
  21. backspace Delete the previous char.
  22.  
  23. Up Previous command in history
  24.  
  25. Down Next command in history (after going up)
  26.  
  27. Left Same as backspace
  28.  
  29. ` Toggle console active
  30.  
  31. Keys bound using the "bind" command are only check while the
  32. console is inactive.
  33.  
  34.  
  35. Console Parsing
  36. ---------------
  37.  
  38. In parsing, the console normally seperates tokens by white
  39. space. All leading and trailing white space is removed.
  40. There are some special characters used by the parser:
  41.  
  42. # Comment to end of line.
  43.  
  44. ' The single quote toggles on/off command aliasing and
  45. variable substitution. The characters within single
  46. quotes are not considered a single token.
  47. This example delays evaluation of the FrameRate
  48. variable untill XX is itself evaluated:
  49.  
  50. % set XX echo '$ConsoleWorld::FrameRate'
  51. % eval $XX
  52.  
  53. "" Anything in quotes in considered a single token.
  54. Variable substitution does not take place if a
  55. variable is embeded within other text in a string:
  56.  
  57. % echo "This is the time: $Time"
  58. This is the time: $Time
  59.  
  60. But this will work:
  61. % echo "This is the time:" "$Time"
  62. This is the time: 5:00
  63.  
  64. If variable substitution does occure in a quoted
  65. string, then the variable value is itself inserted
  66. into the parser in quotes.
  67. Nested quotes are not supported.
  68.  
  69. ; End of command. Is used to combine several console
  70. commands onto a single line:
  71.  
  72. % bind ctrl-c "cls; echo Hello World"
  73. % loadShow; showGfxSW
  74. % if test "$CC" == yes; echo Yes; else; echo No; endif
  75.  
  76. () Similar to double quotes, except that if any variable
  77. substition takes place the substituted value is not
  78. itself quoted. The quoting cause token seperation
  79. between the inserted value and what's already on the
  80. parser stack. An example of the difference:
  81. % set World Lush
  82. % echo "$World"Day
  83. World Day
  84. %echo ($World)Day
  85. WorldDay
  86.  
  87.  
  88. Variable & Alias Substitution
  89. -----------------------------
  90.  
  91. Alias substition only takes place on the first token of a command.
  92. The first token is check against the alias dictionary. If there
  93. is a match, the value is pushed onto the parser stack. Alias
  94. can be aliases for other aliases, substition continues untill
  95. the dictionary lookup fails.
  96.  
  97. Variable substitution takes place on all tokens but the first,
  98. unless a token has been enclosed in single quotes. Any token
  99. starting with '$' is looked up in the variable dictionary. If a
  100. match is found, it's value is pushed onto the parser stack and
  101. parsing continues. Variables in the value of a variable being
  102. expanded will themselves get expanded.
  103.  
  104. % set XX 'World: $World'
  105. % set World Lush
  106. % echo $XX
  107. World: Lush
  108.  
  109. Since "World" hasn't been set yet, the first set command encloses
  110. $World in single quotes to delay evaluation.
  111.  
  112.  
  113. Variable Types
  114. --------------
  115.  
  116. Though variables are always stored internally as strings. They
  117. can be accessed through code using typed methods. These methods
  118. provide type conversion.
  119.  
  120. Bool Can be either 0, 1, false or true
  121. Int Ints are converted using atoi
  122. Float Floats are converted using atof
  123.  
  124.  
  125. Variables Defined by the Console
  126. --------------------------------
  127.  
  128. Console::Prompt
  129.  
  130. The prompt used for input. There is currently only a
  131. single prompt and no way to know if one is in a conditional
  132. block. (default prompt is "%")
  133.  
  134. Console::AutoExec
  135.  
  136. A bool value. If set to true, and the first first token in
  137. a command does not match either an alias, or any builtin
  138. or plugin command, the console attempts to exec "token".cs.
  139. Any file with the .cs script in the current directory is also
  140. included in the command completion list. (Default is true)
  141.  
  142. Console::ExecEcho
  143.  
  144. A bool value. If set to true, all the commands in console
  145. scripts are echoed to the screen. (default is false)
  146.  
  147. Console::BindEcho
  148.  
  149. A bool value. If set to true, whenever a bound key is
  150. evaluated, the command is echoed to the screen.
  151.  
  152. Console::Return
  153.  
  154. An int value. This is the value returned by the last
  155. command executed. Normally a return value of 0 is considered
  156. normal. Non zero values indicate errors.
  157.  
  158. Console::StripVarPrefix
  159.  
  160. A bool value. If this value is true, during variable assignment
  161. the variable name is first stripped of the variable prefix ($).
  162. (Default is true)
  163.  
  164. Example:
  165. % set '$XX yy'
  166.  
  167. Will set the variable 'XX' to yy if the StripVarPrefix is true,
  168. otherwise it will set the variable '$XX' to yy (includes $ in
  169. the variable name). This feature is used mainly to get access
  170. to variable tab completion while setting a var. You can type
  171. "set '$Console", then tab, tab, tab... untill you find the one
  172. you want, then type in the value.
  173.  
  174. Console::GFXFont
  175.  
  176. The name of the GFX font to use during rendering.
  177. (Default is "")
  178.  
  179. Console::Disable
  180.  
  181. A bool value. If set to true, it disables access to the
  182. console.
  183.  
  184. Console::Debug
  185.  
  186. A bool value. Set to true if the console was compiled with
  187. the DEBUG preprocessor variable defined.
  188.  
  189. Console::LastLineTimeout
  190.  
  191. An int value. How ling in ms. the last line printed to the
  192. console is displayed at the top of the screen. This is only
  193. relevent when the console is inactive. If set to 0, or any
  194. value less then 0, the last line printed will never be
  195. displayed. (default is 4000)
  196.  
  197.  
  198. Console Commands
  199. ----------------
  200.  
  201. alias [name] [command...]
  202.  
  203. Alias with no arguments will list out all the current
  204. aliases in the alias dictionary. Alias with just the alias
  205. name will remove that alias from the dictionary.
  206.  
  207. activate
  208.  
  209. Toggles activation of the console.
  210.  
  211. bind [keydesc] [command...]
  212.  
  213. Bind keyboard input to console commands. These bindings
  214. only work while the console is inactive.
  215. Bind by itself will list all the current bindings.
  216. Bind follow by a key description without a command will
  217. unbind that key.
  218.  
  219. The key descriptions are built as follows:
  220.  
  221. [make,break] [ctrl-][alt-][shift-]key
  222.  
  223. where key is any single letter key or one of the following
  224. reserved keys:
  225.  
  226. f[1-15], escape, backspace, tab, enter,
  227. control, quote, shift, alt, space, capslock,
  228. numlock, scroll, numpad[0-9,-,+], numpadequals,
  229. numpadcenter, numpadcomma, sysreq, stop,
  230. home, up, right, left, down, end, prior, next,
  231. insert, delete, win, app
  232.  
  233. If make or break is not specified, the default is make.
  234.  
  235. Example:
  236. % bind ctrl-o messageCanvasDevive MainWindow outline
  237.  
  238. cls
  239.  
  240. Clears out the current printf history.
  241.  
  242. debug
  243.  
  244. Issues an int3
  245.  
  246. define functionName
  247.  
  248. Defines a function. Every line untill "enddef" is read will
  249. be in the function. Currently, define will fail if the
  250. function already exists. No aliasing or variable
  251. substitution takes place untill the function is evaluated.
  252.  
  253. Example:
  254. % define newWindow
  255. % if test "$1" != ""
  256. % if isObject $1
  257. % echo newWindow: Object already exists
  258. % return 1
  259. % else
  260. % newObject $1 SimGui::Canvas $1 320 240
  261. % GuiNewContentCtrl $1 SimGui::TSControl
  262. % endif
  263. % else
  264. % echo newWindow: Must pass window name
  265. % return 1
  266. % endif
  267. % enddef
  268. %
  269. % newWindow xx
  270.  
  271. echo [args...]
  272.  
  273. Prints its arguments to the console. Echo will insert
  274. a single space between it's tokens (white space is stripped
  275. off by the parser).
  276.  
  277. Example:
  278. % echo Timeout value: $Console::LastLineTimeout
  279. Timeout value: 100
  280. % echo "Timeout " value: $Console::LastLineTimeout
  281. Timeout value: 100
  282.  
  283. else
  284.  
  285. Toggles the current "if" conditional evaluation. Only valid
  286. with an "if" block.
  287.  
  288. Example:
  289. % if focusServer
  290. % echo Loading server volumes...
  291. % newObject testVol SimVolume test.vol
  292. % else
  293. % echo No server running
  294. % endif
  295.  
  296. enddef
  297.  
  298. Ends the current "define" function block. Must be paired
  299. with a "define"
  300.  
  301. endif
  302.  
  303. Ends the current "if" conditional block. Must be paired
  304. with an "if".
  305.  
  306. eval [args...]
  307.  
  308. Evaluates it's arguments as a console command. This can
  309. be used to build console commands on the fly.
  310.  
  311. Evaluates the command "moonday" (which could be an alias
  312. a script or any other valid command):
  313. % set World moon
  314. % set Time day
  315. % setcat Script $World $Time
  316. % eval $Script
  317.  
  318. exec [filename]
  319.  
  320. Evaluates the contents of a text file a line at a time.
  321. If the filename does not contain a .cs extension, the
  322. resource manager currently asserts. This command is not
  323. used much as console scripts can be invoked normally like
  324. any other command (if Console::AutoExec is true).
  325.  
  326. Either of these will run the loadShow.cs script:
  327. % exec loadShow.cs
  328. % loadShow
  329.  
  330. export variableName filename.cs [append]
  331.  
  332. Exports the environment variable to the file in such a
  333. way that execing the file will set the variable to it's
  334. current value. The variable name can include the wildcards
  335. [*,?]. The optional "append" argument specifies whether to
  336. overwrite or append the file.
  337.  
  338. Example:
  339. % export Console* consoleSettings.cs
  340.  
  341. false
  342.  
  343. Returns a non zero value (1) indicating false.
  344.  
  345. ?
  346.  
  347. Lists out all the commands, including those registered
  348. by console plugins. Reserved words are not commands and
  349. will not be listed (if, endif, etc.)
  350.  
  351. history
  352.  
  353. Prints out the current command history. The history
  354. buffer size is a compile time variable and is currently
  355. set at 25.
  356.  
  357. if command...
  358.  
  359. Command is evaluated. If it's return value is 0, then
  360. the statements following "if" are evaluated (basically a
  361. return value of 0 is considered true). Command may be any
  362. console command, alias, or console script. All internal
  363. commands return the value 0 indicating no errors (true).
  364. Any non zero return normally indicates some error condition.
  365. "if" statements may be nested.
  366.  
  367. Example:
  368. % if focusServer
  369. % echo Loading server volumes...
  370. % newObject testVol SimVolume test.vol
  371. % else
  372. % echo No server running
  373. % endif
  374.  
  375. % if test "$1" == "Lush"
  376. % if test "$2" != "Day"
  377. % echo Only support daytime for lush world
  378. % return 1
  379. % else
  380. % echo Lush Day it is
  381. % endif
  382. % endif
  383.  
  384. inc variableName
  385.  
  386. Evaluates the variable as an integer and sets it to
  387. that value plus one.
  388.  
  389. not variableName
  390.  
  391. Evaluates the variable as a boolean and sets it to the
  392. complement.
  393.  
  394. return [intValue]
  395.  
  396. Return from a script. The return value defaults to 0.
  397. Return values can be tested directly on the "if" conditional
  398. branch statement, or can be tested using the environment
  399. variable Console::Return.
  400.  
  401. set [variableName] [value...]
  402.  
  403. Set with no arguments will display all the variables in
  404. the environment. Set with only the variable name will
  405. unset, or clear, that variable, except in the case where
  406. the variable name includes a wildcard [*,?]. In that case
  407. all the variables that match the pattern will be displayed.
  408.  
  409. Since the parser strips off white spaces, set will insert
  410. a single space between all it's arguments to build the value
  411. that will be assigned to the variable.
  412.  
  413. Example:
  414. % set Console* # Display everything starting with Console
  415. % set # Display all vars.
  416. % set World moon # Sets "World" to the value "moon"
  417. % set Script # Deletes the variable "Script"
  418.  
  419. setcat variableName [value...]
  420.  
  421. Setcat will set the variable to the concatenation of all
  422. the arguments. Similar to set, except that setcat will
  423. not insert white spaces between the arguments.
  424.  
  425. Example:
  426. % set XX Hello World
  427. % echo $XX
  428. Hello World
  429. % setcat XX Hello World
  430. % echo $XX
  431. HelloWorld
  432.  
  433. true
  434.  
  435. Returns a zero value (0), indicating true.
  436.  
  437. test value1 operation value2
  438.  
  439. Compares the two values and returns a boolean result.
  440. Valid operations are: ==, !=, <=, >=, >, <
  441. If both the values start with a digit, '-' or '.' they
  442. are considered to be numbers and are compared as floating
  443. point values. Otherwise they are compared as strings.
  444. The return value of test can be used in conjunction with
  445. the "if" conditional branch statement or can be tested
  446. using the environment variable Console::Return.
  447.  
  448. Example:
  449. % if test "$1" == Day
  450. % echo Loading world day script
  451. % endif
  452.  
  453. % if test "$Delta" < 0.5
  454. % echo Delta too small.
  455. % return 1
  456. % endif
  457.  
  458. The reason you see most of the environment variables
  459. quoted when being tested is that if the variable does
  460. not exist then the number of arguments to test will be
  461. incorrect and test will report an error. Quoting the
  462. variable quarentees that there will be a token, even if
  463. it's just an empty string.
  464.  
  465. quit
  466.  
  467. Quit the game
  468.  
  469.  
  470. Script Files
  471. ------------
  472.  
  473. Script files are like commands. They can be executed from
  474. the console command line, take arguments and can return
  475. integer values. Script files may invoke other script files as
  476. well as themselves.
  477.  
  478. Argments are passed to console scripts through the the
  479. environment variables 1 through n (used $1, $n).
  480.  
  481. A value can be returned using the "return" command. Scripts
  482. can be used like internal commands on "if" conditional
  483. statements, or anywhere else a command or alias is valid.
  484.  
  485. Example:
  486. File makeDay.cs <<
  487. if "$1" == "Day"
  488. #
  489. # do some work
  490. #
  491. return 0 # True
  492. else
  493. return 1 # False
  494. endif
  495. <<
  496.  
  497. % if makeDay $Time
  498. % echo Day script done
  499. % else
  500. % echo Error running day script
  501. % endif
  502.  
  503. If an error occurs in a script that is not trapped on
  504. an "if" statment, the script returns immediatly with a
  505. return value of 1. If there are no errors, 0 is returned
  506. returned when the end of the file is reached.
  507.  
  508. Functions defined using define/enddef behave the same as
  509. script files.
  510.  
  511.  
  512. Console Reserved Words
  513. ----------------------
  514.  
  515. The console has several reserved words:
  516.  
  517. if, else, endif, define, enddef
  518.  
  519. Only the first token in a command is checked for reserved
  520. words, so using them anywhere else is not a problem.
  521. Key words do not command complete, nor do they show up the
  522. the command list (?).
  523.  
  524. Examples:
  525. # Will not work:
  526. % alias if echo
  527. % if 100
  528. Console: Unkown command: 100
  529. Console: Error on if condition
  530.  
  531. # Ok
  532. % echo if x
  533. if x
  534. %
  535.  
  536. Normal console or plugin commands are not reserved words:
  537.  
  538. % alias alias echo
  539. % alias 100
  540. 100
  541. % # Course, now you can't get rid of the alias.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement