49
edits
| (13 intermediate revisions by the same user not shown) | |||
| Line 17: | Line 17: | ||
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. | 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. | ||
;Outer return statement: | ; 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> | If the outer scope of the Lua code calls return, the return values will be printed. For example: <kua> | ||
context lua | context lua | ||
| Line 25: | Line 61: | ||
</kua> Will write '1' and '1100' to the engine log/console. | </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. | 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 == | == Examples == | ||
| Line 89: | Line 125: | ||
var bob fred | var bob fred | ||
bob | bob | ||
lua ` | lua run ` | ||
local s = script | local s = script | ||
print(1 + 4) | print(1 + 4) | ||