From 0aa94b84fd98f352d972edded44af3bc073cf998 Mon Sep 17 00:00:00 2001 From: Alexey Romanoff Date: Fri, 10 Sep 2021 07:51:59 +0300 Subject: [PATCH] src/mobdebug.lua: fix cases when the server sends the data before the mobdebug starts to receive it --- src/mobdebug.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/mobdebug.lua b/src/mobdebug.lua index 36fa14c..a5b9d60 100644 --- a/src/mobdebug.lua +++ b/src/mobdebug.lua @@ -122,6 +122,8 @@ local step_level = 0 local stack_level = 0 local server local buf +local start_input_line +local start_input_error local outputs = {} local iobase = {print = print} local basedir = "" @@ -778,7 +780,13 @@ local function debugger_loop(sev, svars, sfile, sline) local line, err if mobdebug.yield and server.settimeout then server:settimeout(mobdebug.yieldtimeout) end while true do - line, err = server:receive("*l") + if start_input_line then + line, err = start_input_line, start_input_error + start_input_line = nil + start_input_error = nil + else + line, err = server:receive("*l") + end if not line then if err == "timeout" then if mobdebug.yield then mobdebug.yield() end @@ -1069,6 +1077,10 @@ local function start(controller_host, controller_port) local err server, err = mobdebug.connect(controller_host, controller_port) if server then + local line, receive_err = server:receive("*l") + start_input_line = line + start_input_error = receive_err + -- correct stack depth which already has some calls on it -- so it doesn't go into negative when those calls return -- as this breaks subsequence checks in stack_depth().