Engine:CCMD lua.lua edit: Difference between revisions
Jump to navigation
Jump to search
Line 51: | Line 51: | ||
script 'bob' | script 'bob' | ||
> fred | > fred | ||
</kua> | |||
=== Inline multi-runtime scripting === | |||
Run Lua and JS from script: | |||
<kua> | |||
var bob fred | |||
lua print(1 + 2) | |||
js print(1 + 3) | |||
context lua | |||
print(1 + 4) | |||
script 'bob james;bob' | |||
exit | |||
context lua | |||
print(1 + 5) | |||
script 'bob alan;bob' | |||
exit | |||
> 3 | |||
> 4 | |||
> fred | |||
> 5 | |||
> james | |||
> 6 | |||
> alan | |||
</kua> | </kua> | ||
== Notes == | == Notes == | ||
* While 'lua_edit' is intended make console Lua commands easy to run, can allow scripts and other types of macros to avoid lots of situations where complex logic would otherwise be required, by simply switching to the 'lua' context and then running a series of single line lua chunks. | * While 'lua_edit' is intended make console Lua commands easy to run, can allow scripts and other types of macros to avoid lots of situations where complex logic would otherwise be required, by simply switching to the 'lua' context and then running a series of single line lua chunks. |
Revision as of 18:55, 17 October 2023
Runs a Lua statement in a Lua runtime.
print("fred")
Arguments
- name - (none)
- value - the verbatim text of the Lua statement or statements to be run
Associations
- Is by default placed in the 'lua' context.
- Is the default command for the 'lua' context.
- Does not have its own command name in 'lua'.
Details
Can be used to run commands as though were directly in a Lua console, if the first statement is not engine command, variable or alias in the 'lua' context.
While the 'lua' context has the ability to hold variables and aliases, they cannot be created from script as the 'lua' context has no 'alias', 'set' or 'var' type script commands added to the context.
Examples
Default values
Below, 'exit' is actually a 'lua' context command, which simply switches to the 'global' context. It is not run in a Lua runtime.
context lua
print(1 + 2)
exit
- Prints '3'.
Dual inline scripting
Run Lua from script:
lua print(1 + 2)
> 3
Run script from lua:
var bob fred
context lua
script 'bob'
> fred
exit
Together fluidly:
lua print(1 + 2)
> 3
bob
> fred
context lua
print(1 + 2)
> 3
script 'bob'
> fred
Inline multi-runtime scripting
Run Lua and JS from script:
var bob fred
lua print(1 + 2)
js print(1 + 3)
context lua
print(1 + 4)
script 'bob james;bob'
exit
context lua
print(1 + 5)
script 'bob alan;bob'
exit
> 3
> 4
> fred
> 5
> james
> 6
> alan
Notes
- While 'lua_edit' is intended make console Lua commands easy to run, can allow scripts and other types of macros to avoid lots of situations where complex logic would otherwise be required, by simply switching to the 'lua' context and then running a series of single line lua chunks.