Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function string.split(str,chars,num)
- num=tonumber(num)
- local tStrings={}
- local count=1
- local lastfound=1
- for at=1,str:len() do
- if str:sub(at,at+chars:len()-1)==chars then
- if num~=nil and count<num then
- count=count+1
- elseif num~=nil then
- return str:sub(1,at-1),str:sub(at+chars:len())
- else
- table.insert(tStrings,str:sub(lastfound,at-1))
- lastfound=at+chars:len()
- end
- end
- end
- if num==nil then
- table.insert(tStrings,str:sub(lastfound))
- return unpack(tStrings)
- end
- return false
- end
- function check(sDir)
- sDir=shell.resolve(sDir)
- local tPath={string.split(sDir,"/")}
- local at=""
- local i=1
- while i<=#tPath do
- local redirected=false
- local mtFile=fs.combine(at,"fsmetatable")
- at=fs.combine(at,tPath[i])
- if not fs.exists(at) and fs.exists(mtFile) then
- local mt=setmetatable({},{__index=getfenv()})
- setfenv(loadfile(mtFile),mt)()
- if mt.__index then
- at=check(type(mt.__index)=="function" and mt.__index(at,tPath[i]) or type(mt.__index)=="string" and fs.combine(mt.__index,tPath[i]))
- redirected=true
- end
- end
- if not redirected and not fs.exists(at) then
- error("'"..at.."' does not exist so '"..sDir.."' cannot exist",2)
- elseif not redirected and i<#tPath and not fs.isDir(at) then
- error("'"..at.."' is not a directory so '"..sDir.."' cannot exist",2)
- end
- i=i+1
- end
- return at
- end
Advertisement
Add Comment
Please, Sign In to add comment