Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function split(str, pat)
- local t = {} -- NOTE: use {n = 0} in Lua-5.0
- if str ~= nil then
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- else
- print("##SHIPPER ERROR failed to split ["..str.."] by:"..pat)
- end
- return t
- end
- local function getFirst(line, char)
- local index = -1
- for i=1,string.len(line) do
- local c = line:sub(i, i)
- if c == char and index == -1 then index = i end
- end
- return index
- end
- local function getLines(dir)
- if fs.exists(dir) then
- local file = fs.open(dir, "r")
- local lines = {}
- local line = file.readLine()
- local i = 0
- while line ~= nil do
- lines[#lines + 1] = line
- line = file.readLine()
- i = i + 1
- if i > 100 then
- i = 0
- sleep(0)
- end
- end
- file.close()
- return lines
- else
- return {}
- end
- end
- local function stackEvents(dir, fdir)
- local lines = getLines(dir)
- local que = {}
- if #lines > 0 then
- local j = 0
- for i=1,#lines do
- local line = lines[i]
- j = j + 1
- if j > 100 then
- j = 0
- sleep(0)
- end
- local index = getFirst(line, "@")
- local n = tonumber(line:sub(1, index-1))
- local ev = line:sub(index+1, -1)
- local splt = split(ev, ";")
- local event = splt[1]
- local args = {}
- if #splt > 1 then
- for i=2,#splt do
- local sp = split(splt[i], ",")
- local type = sp[1]
- local val = sp[2]
- if type == "number" then
- args[#args + 1] = tonumber(val)
- elseif type == "string" then
- args[#args + 1] = tostring(val)
- else
- print("INVALID TYPE:"..type.." NOT SUPPORTED")
- end
- end
- end
- local evnt = {event}
- if #args > 0 then for i=1,#args do evnt[#evnt + 1] = args[i] end end
- if type(n) == "number" then
- for i=1,n do
- que[#que + 1] = evnt
- end
- else
- que[#que + 1] = evnt
- end
- end
- end
- if #que > 0 then
- local j = 0
- for i=1,#que do
- j = j + 1
- if j > 50 then
- j = 0
- sleep(0)
- end
- local event = que[i]
- if #event == 1 then
- os.queueEvent( event[1] )
- elseif #event == 2 then
- os.queueEvent( event[1] , event[2] )
- elseif #event == 3 then
- os.queueEvent( event[1] , event[2] , event[3] )
- elseif #event == 4 then
- os.queueEvent( event[1] , event[2] , event[3] , event[4])
- end
- end
- end
- if fdir ~= nil and fdir:gsub(" ", "") ~= "" then
- os.run({}, fdir)
- end
- end
- local stuff = {...}
- local dir = ""
- for i=1,#stuff do if dir == "" then dir = stuff[i] else dir = dir.." "..stuff[i] end end
- if dir == "" then
- print("Please enter directory:")
- dir = read()
- end
- print("[Optional] Enter file directory to run")
- local fdir = read()
- stackEvents(dir, fdir)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement