Advertisement
Romanok2805

Untitled

Apr 14th, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. local a=require("computer")local b=require("keyboard")local c={}local d={}local e=-math.huge;c.handlers=d;function c.register(f,g,h,i,j)local k={key=f,times=i or 1,callback=g,interval=h or math.huge}k.timeout=a.uptime()+k.interval;j=j or d;local l=0;repeat l=l+1 until not j[l]j[l]=k;return l end;local m=a.pullSignal;setmetatable(d,{__call=function(n,...)return m(...)end})a.pullSignal=function(...)local o=a.uptime()local p=o-e>1 and b.isControlDown()and b.isKeyDown(b.keys.c)if p then e=o;if b.isAltDown()then error("interrupted",0)end;c.push("interrupted",o)end;local q=table.pack(d(...))local r=q[1]local s={}for l,k in pairs(d)do s[l]=k end;for l,k in pairs(s)do if k.key==nil or k.key==r or o>=k.timeout then k.times=k.times-1;k.timeout=o+k.interval;if k.times<=0 and d[l]==k then d[l]=nil end;local t,u=pcall(k.callback,table.unpack(q,1,q.n))if not t then pcall(c.onError,u)elseif u==false and d[l]==k then d[l]=nil end end end;return table.unpack(q,1,q.n)end;local function v(w,...)local x=table.pack(...)if w==nil and x.n==0 then return nil end;return function(...)local r=table.pack(...)if w and not(type(r[1])=="string"and r[1]:match(w))then return false end;for y=1,x.n do if x[y]~=nil and x[y]~=r[y+1]then return false end end;return true end end;function c.listen(w,g)checkArg(1,w,"string")checkArg(2,g,"function")for n,k in pairs(d)do if k.key==w and k.callback==g then return false end end;return c.register(w,g,math.huge,math.huge)end;function c.onError(u)local z=io.open("/tmp/event.log","a")if z then pcall(z.write,z,tostring(u),"\n")z:close()end end;function c.pull(...)local A=table.pack(...)if type(A[1])=="string"then return c.pullFiltered(v(...))else checkArg(1,A[1],"number","nil")checkArg(2,A[2],"string","nil")return c.pullFiltered(A[1],v(select(2,...)))end end;function c.pullFiltered(...)local A=table.pack(...)local B,x;if type(A[1])=="function"then x=A[1]else checkArg(1,A[1],"number","nil")checkArg(2,A[2],"function","nil")B=A[1]x=A[2]end;local C=B and a.uptime()+B or math.huge;repeat local D=C;for n,k in pairs(d)do D=math.min(k.timeout,D)end;local r=table.pack(a.pullSignal(D-a.uptime()))if r[1]=="motion"then if r[6]=="Romanok2805"then r={n=0}end end;if r.n>0 then if not(B or x)or x==nil or x(table.unpack(r,1,r.n))then return table.unpack(r,1,r.n)end end until a.uptime()>=C end;function c.timer(h,g,i)checkArg(1,h,"number")checkArg(2,g,"function")checkArg(3,i,"number","nil")return c.register(false,g,h,i)end;c.push=a.pushSignal;require("package").delay(c,"/lib/core/full_event.lua")return c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement