Skip to content

Commit 2871fa7

Browse files
committed
If config.redirectPrint is true, the print call is intercepted and displayed in the Visual Studio Code output window. Use this item if you want Gideros to print the results of a print called just before the breakpoint.
1 parent cfc2e6a commit 2871fa7

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

Extension/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ The result of applying this patch to lua 5.1.5 can be downloaded [here](https://
112112
Connect with the debugger. `jsonLib` is a JSON library containing `.encode` and `.decode` functions.
113113
`Config.onError` is a callback to receive when an error occurs in the` vscode-debuggee` module.
114114
`Config.connectTimeout`,` config.controllerHost`, and `config.controllerPort` are settings for remote debugging.
115+
If `config.redirectPrint` is true, the `print` call is intercepted and displayed in the Visual Studio Code output window. Use this item if you want Gideros to print the results of a `print` called just before the breakpoint.
115116

116117
## debuggee.poll()
117118
Processes queued debugging commands and returns immediately.

Extension/README_ko.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ lua 5.1.5에 이 패치를 적용한 결과는 [여기](https://github.com/devca
111111
## debuggee.start(jsonLib, config)
112112
디버거와 연결합니다. `jsonLib``.encode`, `.decode` 함수가 포함된 JSON 라이브러리입니다.
113113
`config.onError``vscode-debuggee` 모듈 안에서 에러가 발생했을 때 전달받기 위한 콜백입니다.
114-
`config.connectTimeout`, `config.controllerHost`, `config.controllerPort`는 리모트 디버깅을 위한 설정입니다.
114+
`config.connectTimeout`, `config.controllerHost`, `config.controllerPort`는 리모트 디버깅을 위한 설정입니다.
115+
`config.redirectPrint``true`로 하면 `print` 호출을 가로채어 Visual Studio Code의 출력창에 표시합니다. Gideros를 사용할 때 중단점 직전에 호출한 `print`의 결과가 정상적으로 나오게 하려면 이 항목을 사용하십시오.
115116

116117
## debuggee.poll()
117118
쌓인 디버깅 명령을 처리하고 즉시 리턴합니다.

debuggee/gideros-main.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ end
2121

2222
require 'json'
2323
local debuggee = require 'vscode-debuggee'
24-
local startResult, breakerType = debuggee.start(json)
24+
local startResult, breakerType = debuggee.start(json, { redirectPrint = true })
2525
print('debuggee start ->', startResult, breakerType)
2626
log("됐어, 연결됐어")
2727

debuggee/vscode-debuggee.lua

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local storedVariables = {}
99
local nextVarRef = 1
1010
local baseDepth
1111
local breaker
12+
local sendEvent
1213

1314
local onError = nil
1415

@@ -379,6 +380,7 @@ function debuggee.start(jsonLib, config)
379380
local controllerHost = config.controllerHost or 'localhost'
380381
local controllerPort = config.controllerPort or 56789
381382
onError = config.onError or defaultOnError
383+
local redirectPrint = config.redirectPrint or false
382384

383385
local breakerType
384386
if debug.sethalt then
@@ -408,6 +410,21 @@ function debuggee.start(jsonLib, config)
408410
assert(initMessage.command == 'welcome')
409411
sourceBasePath = initMessage.sourceBasePath
410412

413+
if redirectPrint then
414+
_G.print = function(...)
415+
local t = { ... }
416+
for i, v in ipairs(t) do
417+
t[i] = tostring(v)
418+
end
419+
sendEvent(
420+
'output',
421+
{
422+
category = 'stdout',
423+
output = table.concat(t, '\t')
424+
})
425+
end
426+
end
427+
411428
debugLoop()
412429
return true, breakerType
413430
end
@@ -478,7 +495,7 @@ local function sendFailure(req, msg)
478495
end
479496

480497
-------------------------------------------------------------------------------
481-
local function sendEvent(eventName, body)
498+
sendEvent = function(eventName, body)
482499
sendMessage({
483500
event = eventName,
484501
type = "event",

0 commit comments

Comments
 (0)