Engine:CCMD run: Difference between revisions
Line 130: | Line 130: | ||
==== Special parameter delimiters: ==== | ==== Special parameter delimiters: ==== | ||
These currently only useful in a multiline script file, and only works for default commands, like in the 'lua' and 'js' contexts, to pass a multi-line code block to the Lua and JS runtimes. | |||
:4. curly braces - Can be used to extend a whole 'statement' or set of statements across multiple lines. But will not be recognized as a parameter delimiter. The contents will be treated as one statement block. | :4. curly braces - Can be used to extend a whole 'statement' or set of statements across multiple lines. But will not be recognized as a parameter delimiter. The contents will be treated as one statement block. |
Revision as of 00:03, 16 October 2023
Load and run script file. Run a named script file. Name must include extension.
run startup.cfg
Arguments
- name - The name of the script file to load and run.
Associations
- Is by default placed in the 'global' context.
Details
The word "script" can be a very loose term in general, with lots of meanings. Here it can be even more confusing.
In Engine, the most basic type of script is comprised of a core set of facilities in the Data module, which are composed of vars, cmds, aliases, binds, and contexts, with a very basic syntax.
This very basic syntax structure however lends well to being flexible and extensible, and thus sometimes confusing. A complex base Engine script can interact with many different environments and contexts.
Examples
Default values
For a script file named 'startup.cfg' and looks like:
echo fred
lua print(1 + 3)
alias bob fred
var fred james
bob
- Try to load a non-existent file.
> run bob.cfg Run failed: bob.cfg
- Run the example script file.
> run startup.cfg
fred
4
'fred' is 'james'
- In this case: echos 'fred' to console, runs a Lua statement that adds '1 + 3' and prints the result, creates an alias 'bob', creates 'fred' variable that the alias 'bob' will show the value of, runs the 'bob' alias that effectively prints the value of 'fred' that is 'james'.
Script syntax
In the pseudo-syntax examples in these descriptions, a space ' ' is the same as any whitespace except newline, and all of the newline chars are represented by just '\n', to make easier to read. Text with no line '\n' delimiters is considered a single line. The examples are illustrative and not exact, the descriptions are correct.
Syntax:
command-name; command-name other-text; command-name other-text // comment text
Example:
print bob; bind U +attack // changing binding
Addendum I:
- 1. Matching '{' and '}' can be used as third set of quotes to delimit other-text, as in main section item 8.
Statements:
- 1. 'Statement' is a text block that begins with a command name, and is followed by any other text, and ends with line-end or semi-colon. A new statement can begin adjacent to the previous statements ending delimiter.
statement[\n;]statement[\n;]...
- 2. 'Command' names begin or end at white-space, semi-colon, or line-end, and end at comment start.
command
;command//comment
- 3. 'Other text' starts after any white-space after command name, until semi-colon, line-end, or comment start.
command other
command other//comment
- 4. Comment text starts with '//', placed anywhere on a line, and includes all text until line-end.
command other//comment\n
- 5. Comment text, empty statements or lines, or statements or lines with only white-space, will be skipped.
;; ; //comment\n;
- 6. Command names must be at least 2 and less than 63 characters. Statements with invalid command names will be skipped.
co
commandcommand...63
- 7. 'Other text' may contain quoted text, where ''' or '"' are valid quote begin and end quote characters.
command 'other' "text"
- 8. If quoted text is found, any semi-colons, line-ends, or comment starts will be ignored, until next matching quote character.
command 'other;
' "//text"
- In this case 'command other\n statement' will be treated as one statement, and the statement does not end after the 'other;'.
- 9. No other checking or processing is done on any 'other text' after the command name, and any actual meaning is context-dependent and determined when the actual statement is run.
command other text
- 10. If embedded in text a NULL, or '\0', or any character less than ' ', will be considered as a white-space character. This means that a '\0' delimits a command name, stays included in 'other text' as is, and is otherwise ignored. This also means that these characters cannot be used in command names.
bob\0 other
- command is 'bob' other text is '\0 other'
- 11. Command names in this context can contain any character except white-space and ';' and cannot contain '//'. Command names can also have quote characters in the name and are not checked for closing quotes and treated as is as a part of the name. Valid command names: bob/"bob"/bob, "bob", "bob, bob".
+zoom
- 12. 'Executable statements' are composed of both the parsed 'command name' and 'other text' components, excluding comments
Parameters:
'Statements' intrinsically contain only a 'command' and the optional 'other text'. A command can treat the 'other text' as a whole parameter, or as divided into multiple parameters.
Examples:
> echo bob fred bob fred
- 'echo' takes the whole 'other text' as the value to print.
> set bob fred james
> bob
'bob' is 'fred'
- 'set' takes only the first two separated by space for the 'name' and 'value' parameters, and ignores james.
> echo bob "fred" 1234
bob "fred" 1234
- 'echo' still takes the whole 'other text' even with quotes.
> set bob "fred james"
> bob
'bob' is 'fred james'
- 'set' now treats james as part of the second parameter, and the quotes themselves are stripped.
Parameter delimiters:
- 1. space - any whitespace
> set bob fred
> bob
'bob' is 'fred'
- 2. single quotes - any text within a set of single quotes will be a single parameter, and the quotes will be stripped.
> set bob 'fred james'
> bob
'bob' is 'fred james'
- 3. double quotes - any text within a set of double quotes will be a single parameter, and the quotes will be stripped.
> set bob "fred james"
> bob
'bob' is 'fred james'
Special parameter delimiters:
These currently only useful in a multiline script file, and only works for default commands, like in the 'lua' and 'js' contexts, to pass a multi-line code block to the Lua and JS runtimes.
- 4. curly braces - Can be used to extend a whole 'statement' or set of statements across multiple lines. But will not be recognized as a parameter delimiter. The contents will be treated as one statement block.
In a script named 'startup.cfg':
alias testscript '
context lua
{
print("Lua")
local s = ""
for i = 10, 1, -1 do
s = s .. i .. " "
end
io.write(s)
print("print bob"..s)
}
exit
context js
{
print("JavaScript");
var s = "";
for (i = 10; i >= 1; i--) s += i + " ";
print(s);
//script("print bob" + s);
//return 0;
}
exit
'
bind U testscript