49
edits
| (37 intermediate revisions by the same user not shown) | |||
| Line 18: | Line 18: | ||
== Examples == | == Examples == | ||
=== Default values === | === Default values === | ||
For a script file named 'startup.cfg' | For a script file named 'startup.cfg' which looks like: | ||
<kua> | <kua> | ||
echo fred | echo fred | ||
| Line 42: | Line 42: | ||
=== Multiline strings === | === Multiline strings === | ||
Strings in the base scripting language are intrinsically multiline. | Strings in the base scripting language are intrinsically multiline. | ||
For a script file named 'startup.cfg' | * For a script file named 'startup.cfg' which looks like: | ||
<kua> | <kua> | ||
echo 'fred | echo 'fred | ||
| Line 72: | Line 72: | ||
<kua>print bob; bind U +attack // changing binding</kua> | <kua>print bob; bind U +attack // changing binding</kua> | ||
=== Statements === | |||
=== 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. | :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. | ||
::<kua>statement[\n;]statement[\n;]...</kua> | ::<kua>statement[\n;]statement[\n;]...</kua> | ||
| Line 91: | Line 88: | ||
::<kua>co</kua> | ::<kua>co</kua> | ||
::<kua>commandcommand...63</kua> | ::<kua>commandcommand...63</kua> | ||
:7. 'Other text' may contain quoted text, where '<nowiki>'</nowiki>' or '"' are valid quote begin and end quote characters. | :7. 'Other text' may contain quoted text, where '<nowiki>'</nowiki>' or '"' or '`' are valid quote begin and end quote characters. | ||
::<kua>command 'other' "text"</kua> | ::<kua>command 'other' "text"</kua> | ||
:8. If quoted text is found, any semi-colons, line-ends, or comment starts will be ignored, until next matching quote character. | :8. If quoted text is found, any semi-colons, line-ends, or comment starts will be ignored, until next matching quote character. | ||
| Line 107: | Line 104: | ||
:12. 'Executable statements' are composed of both the parsed 'command name' and 'other text' components, excluding comments | :12. 'Executable statements' are composed of both the parsed 'command name' and 'other text' components, excluding comments | ||
=== Parameters | === 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. | '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. | ||
| Line 134: | Line 131: | ||
: 'set' now treats james as part of the second parameter, and the quotes themselves are stripped. | : 'set' now treats james as part of the second parameter, and the quotes themselves are stripped. | ||
==== | ==== Delimiters ==== | ||
:1. space - any whitespace | :1. space - any whitespace | ||
<kua> | <kua> | ||
| Line 153: | Line 150: | ||
'bob' is 'fred james' | 'bob' is 'fred james' | ||
</kua> | </kua> | ||
:3. back tick - any text within a set of back ticks will be a single parameter, and the ticks will be stripped. | |||
==== Special | <kua> | ||
: | > set bob `fred james` | ||
> bob | |||
'bob' is 'fred james' | |||
</kua> | |||
==== Special delimiters ==== | |||
:1. Back ticks surrounding text passed directly to a context will be stripped. Normally all text is passed verbatim, including quotes. Back ticks effectively treat the rest of the statement as a block for a multi-line statement. Quotes are not removed normally as they may be important to the context's command processing. Back ticks are special in that they will be removed from the start and end of the script statement. Without this special behavior, there would be no way to run a multi-line command block for an associated context, without switching to it first. | |||
<kua> | <kua> | ||
> lua `print "bob"` | |||
bob | |||
> lua ` | |||
print "bob" | |||
print "bob" | |||
` | |||
bob | |||
bob | |||
> lua ' | |||
print "bob" | |||
print "bob" | |||
' | |||
Error in : [string "'print "bob"'"]:1: unexpected symbol near ''print "bob"'' (3) | |||
</kua> | |||
== More examples == | |||
Direct context with out back ticks: | |||
<kua> | |||
> lua print "bob" | |||
bob | |||
> lua 'print "bob"' | |||
Error in : [string "'print "bob"'"]:1: unexpected symbol near ''print "bob"'' (3) | |||
> lua run 'print "bob"' | |||
bob | |||
</kua> | |||
: When addressing the context directly, all of the 'other text' that is not the command simply gets passed to the context. At the top, print "bob" gets run in 'lua' context. The second fails as 'print "bob"' is not valid for the context or Lua. The third runs usingthe run command as a normal parameter to 'run'. While it will run multiline Lua scripts, text still won't be running as a set of context commands. | |||
<kua> | |||
> lua ` | |||
print "bob" | |||
print "bob" | |||
` | |||
bob | |||
bob | |||
</kua> | |||
: Here effectively as a block inside 'lua' | |||
<kua> | |||
> context lua | |||
> print "bob" | |||
bob | |||
> print "bob" | |||
bob | |||
> context global | |||
</kua> | |||
: And same thing but switching and executing and switching back. | |||
<kua> | |||
> notthere ` | |||
print(1+2) | |||
print(1+2) | |||
` | |||
Unknown: notthere | |||
</kua> | |||
: The context did not exist and didn't run the block. In this case, guards against running commands in wrong context, if the context didn't exist at that time. | |||
<kua> | |||
> context notthere | |||
> print(1+2) | |||
Unknown: print(1+2) | |||
> print(1+2) | |||
Unknown: print(1+2) | |||
> context global | |||
</kua> | </kua> | ||
: This time commands are run in the unintended context. | |||
== Notes == | == Notes == | ||
* | * | ||