- Sanitize get and set

This commit is contained in:
ParticleG
2024-11-01 08:25:24 +08:00
parent c642bd3857
commit 017f874f38

View File

@@ -1,7 +1,27 @@
local function _sanitize(content)
if type(content)=='boolean' then
content=content and 'true' or 'false'
end
if type(content)=='nil' then
content=''
end
if type(content)=='number' then
content=tostring(content)
end
if type(content)~='string' then
MES.new('error',"Invalid content type!")
MES.traceback()
return ''
end
return content
end
if SYSTEM~='Web' then
local get = love.system.getClipboardText
local set = love.system.setClipboardText
return {
get=function () return CLIPBOARD.get() or '' end,
set=love.system.setClipboardText,
get=function() return get() or '' end,
set=function(content) set(_sanitize(content)) end,
_update=NULL,
}
end
@@ -16,24 +36,11 @@ clipboard_thread:start(getCHN,setCHN,triggerCHN)
local clipboard={}
function clipboard.get()
return getCHN:peek()
return getCHN:peek() or ''
end
function clipboard.set(content)
if type(content)=='boolean' then
content=content and 'true' or 'false'
end
if type(content)=='nil' then
content=''
end
if type(content)=='number' then
content=tostring(content)
end
if type(content)~='string' then
MES.new('error',"Invalid content type!")
MES.traceback()
end
setCHN:push(content)
setCHN:push(_sanitize(content))
end
function clipboard._update()