Engine:CCMD run: Difference between revisions

32 bytes removed ,  16 October 2023
 
(13 intermediate revisions by the same user not shown)
Line 157: Line 157:
</kua>
</kua>
==== Special delimiters ====
==== Special delimiters ====
:1. Back ticks surrounding text passed directly to a context will be stripped, such that the resulting text will get treated as a script block to be run in the context. Normally all text is passed verbatim, including quotes. This is useful for multi-line scripts, as normally all text on the same line will be passed without quotes anyway.
: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"`
> lua `print "bob"`
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>
</kua>
: Back ticks effectively treat the rest of the statement as a block, by being preemptively removed before passing to the context, and execute as though were actually in the 'lua' context. 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.
 
== 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>
<kua>
> lua `
> lua `
Line 198: Line 222:
</kua>
</kua>
: This time commands are run in the unintended context.
: This time commands are run in the unintended context.
<kua>
> lua run 'print "bob"'
bob
</kua>
: Above calls the 'lua' context 'run' command, and as normal 'print "bob"' is a complete parameter for 'run', that then gets executed in the Lua runtime all together.
<kua>
> lua print "bob"
bob
> lua 'print "bob"'
Error in : [string "'print "bob"'"]:1: unexpected symbol near ''print "bob"'' (3)
</kua>
: Passed directly to the 'lua' context verbatim and treated necessarily as a command to be run. This fails as 'print is not a valid 'lua' context command, and 'print "bob"' is not valid Lua.


== Notes ==
== Notes ==
*
*