pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.6k stars 519 forks source link

print result not accordance between step and run #1098

Closed robertlzj closed 3 years ago

robertlzj commented 3 years ago
print'1\0'
print'2'
pkulchenko commented 3 years ago

@robertlzj, indeed; thank you for the report!

It's caused by the fact that Scintilla InsertText call doesn't take the string length into account and stops at the first zero. I switched to a different method that should handle that. See if this patch fixes this for you:

diff --git a/src/editor/output.lua b/src/editor/output.lua
index d0523d28..67a0ff40 100644
--- a/src/editor/output.lua
+++ b/src/editor/output.lua
@@ -96,7 +96,9 @@ function DisplayOutputNoMarker(...)
   local insertedAt = promptLine == wx.wxNOT_FOUND and out:GetLength() or out:PositionFromLine(promptLine) + inputBound
   local current = out:GetReadOnly()
   out:SetReadOnly(false)
-  out:InsertTextDyn(insertedAt, out.useraw and message or FixUTF8(message, "\022"))
+  out:GotoPos(insertedAt)
+  local text = out.useraw and message or FixUTF8(message, "\022")
+  out:AddTextDyn(text)
   out:EmptyUndoBuffer()
   out:SetReadOnly(current)
   out:GotoPos(out:GetLength())
robertlzj commented 3 years ago

Thanks. Now it will even print each control char on Scinilla's way.

pkulchenko commented 3 years ago

Right; pushed the changes.