0
1
mirror of https://github.com/radio95-rnt/rds95.git synced 2026-02-26 12:32:05 +01:00

better error handling

This commit is contained in:
2025-12-29 17:22:01 +01:00
parent 5ed6e666ae
commit 73c7ee055d
2 changed files with 11 additions and 5 deletions

View File

@@ -57,17 +57,15 @@ end
function rds2_group(stream)
if #_RDS2_ODAs == 0 then return false, 0, 0, 0, 0 end
if _RDS2_ODA_pointer > #_RDS2_ODAs then _RDS2_ODA_pointer = 1 end
local checked = 0
while checked < #_RDS2_ODAs and _RDS2_ODAs[_RDS2_ODA_pointer] == false do
_RDS2_ODA_pointer = _RDS2_ODA_pointer + 1
if _RDS2_ODA_pointer > #_RDS2_ODAs then _RDS2_ODA_pointer = 1 end
checked = checked + 1
end
if checked == #_RDS2_ODAs then return false, 0, 0, 0, 0 end
if _RDS2_ODA_pointer > #_RDS2_ODAs then _RDS2_ODA_pointer = 1 end
local oda = _RDS2_ODAs[_RDS2_ODA_pointer]
local channel_offset = 16 * ((not oda.file_related) and 1 or 0)
local channel = ((_RDS2_ODA_pointer - 1 + channel_offset) & 0x3F)

View File

@@ -2,13 +2,21 @@ function data_handle(data)
if string.sub(data, 1, 4):lower() == "lua=" then
local chunk, err = load("return " .. string.sub(data, 5), "udp_chunk") -- skip "lua="
if not chunk then return string.format("-\r\n%s\r\n", err) end
local results = { chunk() }
local results = {}
local stat, err = pcall(function ()
results = { chunk() }
end)
if not stat then return tostring(err) end
for i = 1, #results do results[i] = tostring(results[i]) end
return table.concat(results, ", ") .. "\r\n"
elseif string.sub(data, 1, 5):lower() == "file=" then
local chunk, err = loadfile(data:sub(6)) -- skip "file="
if not chunk then return string.format("-\r\n%s\r\n", err) end
local results = { chunk() }
local results = {}
local stat, err = pcall(function ()
results = { chunk() }
end)
if not stat then return tostring(err) end
for i = 1, #results do results[i] = tostring(results[i]) end
return table.concat(results, ", ") .. "\r\n"
end