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

7 lines
3.4 KiB
Lua
Raw Normal View History

-- Penlight 1.11.0-1 | /lua/pl/config.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,b,c,d,e=_G.type,_G.tonumber,_G.ipairs,_G.io,_G.table;local function f(g,h)local i={}local j=e.insert;h='[^'..h..']+'for k in g:gmatch(h)do j(i,k)end;return i end;local function l(g)return g:gsub('^%s+',''):gsub('%s+$','')end;local function m(g)return g:gsub("['\"](.*)['\"]",'%1')end;local n={}function n.lines(o)local p,q,r;local s=''if a(o)=='string'then p,r=d.open(o,'r')if not p then return nil,r end;q=true else p=o or d.stdin;if not o.read then return nil,'not a file-like object'end end;if not p then return nil,'file is nil'end;return function()local t=p:read()while t do if t:match'%S'and not t:match'^%s*[;#]'then local u=t:find'\\%s*$'if u then s=s..t:sub(1,u-1)elseif s==''then return t else t=s..t;s=''return t end end;t=p:read()end;if q then p:close()end end end;function n.read(o,v)local w;local x,r=n.lines(o)if not x then return nil,r end;local s=x()v=v or{}if v.smart then w=true;if s:match'^[^=]+='then v.keysep='='elseif s:match'^[^:]+:'then v.keysep=':'v.list_delim=':'elseif s:match'^%S+%s+'then v.keysep=' 'if s:match'^%S+%s+%S+%s+%S+'then v.list_delim=' 'end;v.variabilize=false end end;local function y(z,A)local B=v[z]if B==nil then return A else return B end end;local C='^[%d%+%-]'local D={}local E=D;local F=y('variabilize',true)local G=y('list_delim',',')local H=y('convert_numbers',true)local I=y('convert_boolean',false)local J=y('trim_space',true)local K=y('trim_quotes',false)local L=y('ignore_assign',false)local M=y('keysep','=')local N=M==' 'and'%s+'or'%s*'..M..'%s*'if G==' 'then G='%s+'end;local function O(P)if F then P=P:gsub('[^%w]','_')end;return P end;local function Q(R)if G and R:find(G)then R=f(R,G)for u,S in c(R)do R[u]=Q(S)end elseif H and R:find(C)then local B=b(R)if not B and R:match' kB$'then R=R:gsub(' kB','')B=b(R)end;if B then R=B end elseif I and R=='true'then return true elseif I and R=='false'then return false end;if a(R)=='string'then if J then R=l(R)end;if not K and w and R:match'^"'then K=true end;if K then R=m(R)end end;return R end;while s do if s:find('^%[')then local T=O(s:match('%[([^%]]+)%]'))D=E;D[T]={}D=D[T]else s=s:gsub('^%s*','')local U,V=s:find(N)if U and not L then local P=O(s:sub(1,U-1))local R=Q(s:sub(V+1))D[P]=R else D[#D+1]=Q(s)end end;s=x()end;return E end;return n