diff options
author | Norbert Preining <norbert@preining.info> | 2022-02-14 03:01:43 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-02-14 03:01:43 +0000 |
commit | 01b69c78ff33854f7f28149e8167cb4219fcb416 (patch) | |
tree | 84f65fb4b68924dee319c869e951cc3dfa32f89f /macros/luatex/latex/pyluatex/pyluatex.lua | |
parent | a488c0e94aba29c7f7062852569792d58efda8dc (diff) |
CTAN sync 202202140301
Diffstat (limited to 'macros/luatex/latex/pyluatex/pyluatex.lua')
-rw-r--r-- | macros/luatex/latex/pyluatex/pyluatex.lua | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/macros/luatex/latex/pyluatex/pyluatex.lua b/macros/luatex/latex/pyluatex/pyluatex.lua index f95ab989c0..f9d8ff68a6 100644 --- a/macros/luatex/latex/pyluatex/pyluatex.lua +++ b/macros/luatex/latex/pyluatex/pyluatex.lua @@ -33,7 +33,6 @@ pyluatex = pyluatex or { -- status.filename: path to pyluatex.sty local folder = file.pathpart(file.collapsepath(status.filename, true)) -local script = file.join(folder, "pyluatex-interpreter.py") local tcp = nil local env_end = nil @@ -53,6 +52,7 @@ local function err_cmd(message) end function pyluatex.start(executable) + local script = file.join(folder, "pyluatex-interpreter.py") local is_windows = package.config:sub(1,1) ~= "/" local cmd if is_windows then @@ -61,15 +61,25 @@ function pyluatex.start(executable) cmd = executable .. " \"" .. script .. "\" &" end local f = io.popen(cmd, "r") - local port = f:read("*l"):gsub("\r", ""):gsub("\n", "") + local port = f:read("*l") f:close() - if port then - tcp = socket.tcp() - tcp:connect("127.0.0.1", port) - else - tex.sprint(err_cmd("Python backend (executable: " .. executable .. - ") could not be started")) + function err(message) + tex.sprint(err_cmd("Python backend could not be started (" .. message .. ")")) + end + + if port == nil then + err("executable: " .. executable) + return + end + port = trim(port) + if port:match("^%d+$") == nil then + err("invalid TCP port: " .. port) + return + end + tcp = socket.tcp() + if tcp:connect("127.0.0.1", port) == nil then + err("TCP connection failed") end end |