- Sanitize get and set
This commit is contained in:
@@ -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
|
if SYSTEM~='Web' then
|
||||||
|
local get = love.system.getClipboardText
|
||||||
|
local set = love.system.setClipboardText
|
||||||
return {
|
return {
|
||||||
get=function () return CLIPBOARD.get() or '' end,
|
get=function() return get() or '' end,
|
||||||
set=love.system.setClipboardText,
|
set=function(content) set(_sanitize(content)) end,
|
||||||
_update=NULL,
|
_update=NULL,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -16,24 +36,11 @@ clipboard_thread:start(getCHN,setCHN,triggerCHN)
|
|||||||
local clipboard={}
|
local clipboard={}
|
||||||
|
|
||||||
function clipboard.get()
|
function clipboard.get()
|
||||||
return getCHN:peek()
|
return getCHN:peek() or ''
|
||||||
end
|
end
|
||||||
|
|
||||||
function clipboard.set(content)
|
function clipboard.set(content)
|
||||||
if type(content)=='boolean' then
|
setCHN:push(_sanitize(content))
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function clipboard._update()
|
function clipboard._update()
|
||||||
|
|||||||
Reference in New Issue
Block a user