Improve Lua REPL handling of statements #4026
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rework the way the Lua console REPL executes commands
The old way first tries to execute
$"console.log({rawCommand})"
, which prints out the values of an entered expression, but results in a syntax error if the command is a statement such asfoo = 1
. If the first attempt errors, it executes the raw command without the log call, so the command still works, but it's printing out confusing syntax error messages anyway. If the expression itself causes an error like"a" + 1
orstring.format("%error")
, it tries to run it twice and prints out two different errors.The PR changes it so
LuaLibraries.ExecuteString
attempts to first parse the modified command without running it, and then only executes either the modified command or the raw command. This avoids unnecessary error messages, double execution of certain commands etc.Check if completed: