Skip to content

Commit

Permalink
Fixed issue with \r being stripped in some luasocket configurations (#53
Browse files Browse the repository at this point in the history
).

I'd not expect \r to be removed, but it does seem not come through in
love2d and I'm not sure why. I haven't seen it happening anywhere else.

Should fix pkulchenko/ZeroBraneStudio#1164.
  • Loading branch information
pkulchenko committed Sep 24, 2023
1 parent 457c86a commit 4cf97f9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/mobdebug.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--
-- MobDebug -- Lua remote debugger
-- Copyright 2011-20 Paul Kulchenko
-- Copyright 2011-23 Paul Kulchenko
-- Based on RemDebug 1.0 Copyright Kepler Project 2005
--

Expand All @@ -19,7 +19,7 @@ end)("os")

local mobdebug = {
_NAME = "mobdebug",
_VERSION = "0.804",
_VERSION = "0.805",
_COPYRIGHT = "Paul Kulchenko",
_DESCRIPTION = "Mobile Remote Debugger for the Lua programming language",
port = os and os.getenv and tonumber((os.getenv("MOBDEBUG_PORT"))) or 8172,
Expand Down Expand Up @@ -121,6 +121,7 @@ local step_into = false
local step_over = false
local step_level = 0
local stack_level = 0
local SAFEWS = "\012" -- "safe" whitespace value
local server
local buf
local outputs = {}
Expand Down Expand Up @@ -817,6 +818,8 @@ local function debugger_loop(sev, svars, sfile, sline)
local params = string.match(line, "--%s*(%b{})%s*$")
local _, _, chunk = string.find(line, "^[A-Z]+%s+(.+)$")
if chunk then
-- \r is optional, as it may be stripped by some luasocket versions, like the one in LOVE2d
chunk = chunk:gsub("\r?"..SAFEWS, "\n") -- convert safe whitespace back to new line
local func, res = mobdebug.loadstring(chunk)
local status
if func then
Expand Down Expand Up @@ -1359,7 +1362,7 @@ local function handle(params, client, options)
local _, _, exp = string.find(params, "^[a-z]+%s+(.+)$")
if exp or (command == "reload") then
if command == "eval" or command == "exec" then
exp = exp:gsub("\n", "\r") -- convert new lines, so the fragment can be passed as one line
exp = exp:gsub("\r?\n", "\r"..SAFEWS) -- convert new lines, so the fragment can be passed as one line
if command == "eval" then exp = "return " .. exp end
client:send("EXEC " .. exp .. "\n")
elseif command == "reload" then
Expand Down

0 comments on commit 4cf97f9

Please sign in to comment.