KoboldAI-Client/extern/lualibs/pl/types.lua

7 lines
2.8 KiB
Lua

-- Penlight 1.11.0-1 | /lua/pl/types.lua | https://github.com/lunarmodules/Penlight | License: MIT | Minified using https://www.npmjs.com/package/luamin/v/1.0.4
-- Copyright (C) 2009-2016 Steve Donovan, David Manura.
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
local a=require'pl.utils'local b=math.ceil;local c=a.assert_arg;local d={}function d.is_callable(e)return type(e)=='function'or getmetatable(e)and getmetatable(e).__call and true end;d.is_type=a.is_type;local f=getmetatable(io.stdout)function d.type(e)local g=type(e)if g=='table'or g=='userdata'then local h=getmetatable(e)if h==f then return'file'elseif h==nil then return g else return h._name or"unknown "..g end else return g end end;function d.is_integer(i)return b(i)==i end;function d.is_empty(j,k)if j==nil then return true elseif type(j)=="table"then return next(j)==nil elseif type(j)=="string"then return j==""or not not k and not not j:find("^%s+$")else return true end end;local function l(m)if type(m)=='table'then return true end;return getmetatable(m)end;function d.is_indexable(m)local h=l(m)if h==true then return true end;return h and h.__len and h.__index and true end;function d.is_iterable(m)local h=l(m)if h==true then return true end;return h and h.__pairs and true end;function d.is_writeable(m)local h=l(m)if h==true then return true end;return h and h.__newindex and true end;local n={yes=true,y=true,["true"]=true,t=true,["1"]=true}local o={boolean=function(j,p,q)return j end,string=function(j,p,q)j=j:lower()if n[j]then return true end;for r,s in ipairs(p or{})do if type(s)=="string"and j==s:lower()then return true end end;return false end,number=function(j,p,q)return j~=0 end,table=function(j,p,q)if q and next(j)~=nil then return true end;return false end}function d.to_bool(j,p,q)local t;if p then c(2,p,"table")end;t=o[type(j)]if t then return t(j,p,q)elseif q and j~=nil then return true end;return false end;return d