- 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
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user