mirror of
https://github.com/CCLeonOS/LeonOS.git
synced 2026-03-03 15:17:01 +00:00
fix: 修复事件拉取函数的安全性问题并改进错误处理
修复多个文件中事件拉取函数的安全性问题,添加更健壮的fallback机制 在imageview.lua中改进错误信息显示,确保image变量转换为字符串 在pkg.lua中调整JSON序列化参数以生成更紧凑的输出
This commit is contained in:
@@ -60,8 +60,8 @@ local function main(args)
|
||||
end)
|
||||
|
||||
if not success then
|
||||
print("Error loading image: " .. image)
|
||||
print("Make sure the URL points to a valid image file compatible with CC Tweaked.")
|
||||
print("Error loading image: " .. tostring(image))
|
||||
print("Make sure the URL points to a valid image file compatible with CC Tweaked.")
|
||||
return
|
||||
end
|
||||
|
||||
@@ -79,9 +79,15 @@ local function main(args)
|
||||
|
||||
print("\nImage displayed. Press ESC to exit.")
|
||||
|
||||
-- 监听ESC键
|
||||
-- 安全地监听ESC键
|
||||
while true do
|
||||
local _, key = os.pullEvent("key")
|
||||
-- 使用安全的事件拉取函数
|
||||
local pullEventFunc = os.pullEvent or os.pullEventRaw
|
||||
if not pullEventFunc then
|
||||
error("No valid event pulling function found")
|
||||
end
|
||||
|
||||
local event, key = table.unpack({pullEventFunc("key")})
|
||||
if key == 27 then -- ESC键
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
|
||||
Reference in New Issue
Block a user