Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function path_goback(path,amm)
- pathtbl={}
- s=""
- pathsize=0
- -- Divide string and count the number of
- -- divisions.
- for str in string.gmatch(path, "([^/]+)") do
- pathtbl[#pathtbl+1] = str
- end
- for k, v in pairs(pathtbl) do
- pathsize=k
- end
- pathsize = pathsize - amm
- -- Split string into words based on seperator.
- pathtbl={}
- for str in string.gmatch(path, "([^/]+)") do
- pathtbl[#pathtbl+1] = str
- end
- -- Based on how large the user wants the string to be
- -- add only the string bits that led up to the user defined
- -- size.
- for k, v in pairs(pathtbl) do
- if(k <= pathsize)then s = s..pathtbl[k].."/" end
- end
- return "/" .. s
- end
- local function path_getsize(path)
- pathtbl={}
- pathsize=0
- -- Divide string and count the number of
- -- divisions.
- for str in string.gmatch(path, "([^/]+)") do
- pathtbl[#pathtbl+1] = str
- end
- for k, v in pairs(pathtbl) do
- pathsize=k
- end
- return pathsize
- end
- function newpath(name,stuckindex)
- if(name == nil or type(name) ~= "string")then error("PathAPI: Name must be provided for new paths. ") end
- if(string.sub(name,#name,#name) ~= "/")then
- name = name .. "/"
- end
- if(type(stuckindex) ~= "number")then stuckindex = 0 end
- local pathobj = {
- path = name,
- stuckind = stuckindex,
- getsize = function(self)
- return path_getsize(self.path)
- end,
- goback = function(self,amm)
- if(self:getsize() - amm >= self.stuckind)then
- self.path = path_goback(self.path,amm)
- return self.path
- else
- return false
- end
- end,
- getraw = function(self)
- return self.path
- end,
- add = function(self,new)
- self.path = self.path .. new .. "/"
- return self.path
- end,
- set = function(self,npath)
- self.path = npath
- return self.path
- end,
- lockpath = function(self)
- self.stuckind = self:getsize()
- end,
- unlockpath = function(self)
- self.stuckind = 0
- end,
- }
- return pathobj
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement