Open main menu
Home
Random
Log in
Settings
About AddOn Studio
Disclaimers
AddOn Studio
Search
Editing
Engine:CCMD lua.lua edit
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{dev/uiccmd}} Runs a Lua statement in a Lua runtime. <kua>lua print("fred")</kua> == Arguments == * name - (none) * value - the verbatim Lua code 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 == Used to run a Lua text directly in the 'lua' context, if the first statement is not engine command, variable or alias in the 'lua' context. This allows the script in the 'lua' context to act as though it were running directly in a Lua console. 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. ; Line by line processing: The 'lua_edit' default command will only be run when a statement is not another context, or a command, variable, or alias. Script in the 'lua' context is still run statement by statement, as script in the engine. For example: <kua> context lua print(1+2); exit </kua> Is actually: <kua> context lua print(1+2) -- sent to Lua runtime ; // script statement delimiter processed in script exit // script </kua> This however would run ';' delimited statements in one Lua chunk, using the 'lua' context 'run' command. And then still run the script 'exit' command: <kua> context lua run `print(1+2);print(1+2)`;exit </kua> And this fails because 'if', 'print', and 'end' are in separate script statements: <kua> context lua if bob then -- Lua errer! print(1 + 2) end </kua> These work: <kua> context lua run `if bob then print(1 + 3) end` if bob then print(1 + 4) end </kua> ; Outer return statement: If the outer scope of the Lua code calls return, the return values will be printed. For example: <kua> context lua a = 1 return a return 100 + 1000 </kua> Will write '1' and '1100' to the engine log/console. This is similar to an interactive Lua console's '=' convenience command like <code>=100</code>, where will output '100' in the console when '=' starts a console line, after the command is run. In the engine real Lua interactive console, and this mechanism is special to only 'lua_edit', and is provided for similar convenience. == 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. <kua> context lua print(1 + 2) exit </kua> : Prints '3'. === Dual inline scripting === Run Lua from script: <kua> lua print(1 + 2) > 3 </kua> Run script from lua: <kua> var bob fred context lua script 'bob' > fred exit </kua> Together fluidly: <kua> lua print(1 + 2) > 3 bob > fred context lua print(1 + 2) > 3 script 'bob' > fred </kua> === Inline scripting === Lua and JS from script: <kua> var bob fred lua print(1 + 2) js print(1 + 3) bob context lua print(1 + 4) script 'bob james;bob' exit context js print(1 + 5); script('bob alan;bob'); exit > 3 > 4 > fred > 5 > james > 6 > alan </kua> With blocks: <kua> var bob fred bob lua run ` local s = script print(1 + 4) s 'bob james;bob' s 'js function alan(s) { script("bob "+s+";bob"); }' ` js alan("alan"); > fred > 5 > james > alan </kua> == 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.
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Crumb
(
edit
)
Template:Crumbtext
(
edit
)
Template:Dev/uiccmd
(
edit
)
Template:Editlink
(
edit
)
Template:Engine/devnav
(
edit
)
Template:Tocright
(
edit
)