Skip to content

Commit

Permalink
Update luaLib.min.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
mercobots committed Aug 21, 2017
1 parent 18f7fa7 commit 4c7e0fa
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion luaLib.min.lua
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gettype=function(a)local b=typeOf(a)if b=="userdata"then return a:typeOf()end;return b end;is_string=function(c)if typeOf(c)=="string"then return true end end;is_bool=function(d)if typeOf(d)=="boolean"then return true end;return false end;is_numeric=function(e)if tonumber(e)~=nil then return true end;return false end;is_float=function(e)if e~=math.floor(e)then return true end;return false end;is_table=function(a)if typeOf(a)=="table"then return true end;return false end;print_r=function(a,f,g)table.show=function(a,f,g)local h;local i;local function j(a)return next(a)==nil end;local function k(l)local m=tostring(l)if typeOf(l)=="function"then local n=debug.getinfo(l,"S")if n.what=="C"then return string.format("%q",m..", C function")else return string.format("%q",m..", defined in ("..n.linedefined.."-"..n.lastlinedefined..")"..n.source)end elseif typeOf(l)=="number"or typeOf(l)=="boolean"then return m else return string.format("%q",m)end end;local function o(p,f,g,q,r)g=g or""q=q or{}r=r or f;h=h..g..r;if typeOf(p)~="table"then h=h.." = "..k(p)..";\n"else if q[p]then h=h.." = {}; -- "..q[p].." (self reference)\n"i=i..f.." = "..q[p]..";\n"else q[p]=f;if j(p)then h=h.." = {};\n"else h=h.." = {\n"for s,t in pairs(p)do s=k(s)local u=string.format("%s[%s]",f,s)r=string.format("[%s]",s)o(t,u,g.." ",q,r)end;h=h..g.."};\n"end end end end;f=f or"__unnamed__"if typeOf(a)~="table"then return f.." = "..k(a)end;h,i="",""o(a,f,g)return h..i end;print(table.show(a,f,g))end;trim=function(c)return c:gsub("^%s*(.-)%s*$","%1")end;ltrim=function(c)return c:gsub("^%s*","")end;rtrim=function(c)local e=#c;while e>0 and c:find("^%s",e)do e=e-1 end;return c:sub(1,e)end;explode=function(c,v)v=v or"%s"local w,x={},1;for y in string.gmatch(c,"([^"..v.."]+)")do w[x]=y;x=x+1 end;return w end;str_replace=function(z,A,c,B)B=B or nil;return string.gsub(z,A,c,B)end;count=function(C)local count=0;for D in pairs(C)do count=count+1 end;return count end;in_table=function(E,t)for x,a in ipairs(E)do if a==t then return true end end;return false end;table_reverse=function(a)local A={}local x=#a;for s,t in ipairs(a)do A[x+1-s]=t end;return A end;function validate_table(F,G)G=G or{"table","number","boolean","string"}if not F then return false,"_file_not_set_"end;if not is_string(F)and not is_table(F)then return false,"_file_bad_type"end;if is_string(F)and not fileExists(F)then return false,"_file_not_found_"end;if is_table(F)then for s,t in pairs(F)do if in_table(G,gettype(t))then if is_table(t)then validate_table(t,G)end else return false,"_table_bad_format_"end end else local H,I,J=print,toast,print_r;print,toast,print_r=nil,nil,nil;local K,L=pcall(dofile,F)print,toast,print_r=H,I,J;if K then return validate_table(L,G)else return false,"_critical_"end end;return F end;is_dir=function(c)if is_string(c)and not c:match("(.+)%..+")then return true end;return false end;basename=function(M)local a=explode(M,"/")return a[#a]end;dirname=function(c)local a,A=explode(c,"/"),""for x,t in ipairs(a)do if x<#a then A=A..t.."/"end end;return A end;file_extension=function(N)local c=N;local a=""local A=""for x=c:len(),1,-1 do if c:sub(x,x)~="."then a=a..c:sub(x,x)else break end end;for O=a:len(),1,-1 do A=A..a:sub(O,O)end;return A end;mkdir=function(M)if os.execute("mkdir -p \""..M.."\"")==0 then return true end;return false end;rmdir=function(M)if os.execute("rm -rf \""..M.."\"")==0 then return true end;return false end;copy=function(c,v)if mkdir(v)and os.execute("cp -rf \""..c.."\" \""..v.."\"")==0 then return true end;return false end;function scandir(P,Q)Q=Q or"/sdcard/__temp/"local R=Q.."_scandir_"local S="ls "..P.." > "..R;if not mkdir(Q)then return false,"_mkdir_"end;if os.execute(S)~=0 then return false,"_list_"end;local T={}for U in io.lines(R)do T[#T+1]=U end;if not rmdir(R)then return false,"_rmdir_"end;return T end;pathinfo=function(M,V)local A={}local W=not V and 4 or 1;for x=1,W do if V=="PATHINFO_DIRNAME"or W==4 then A["dirname"]=dirname(M)end;if V=="PATHINFO_BASENAME"or W==4 then A["basename"]=basename(M)end;if V=="PATHINFO_EXTENSION"or W==4 then A["extension"]=file_extension(M)end;if V=="PATHINFO_FILENAME"or W==4 then A["filename"]=str_replace(basename(M),"(%.%w+)$","")end end;if W==1 then return A[string.lower(str_replace(V,"(.*)%_",""))]else return A end end;btn_home=function()keyevent(3)end;btn_back=function(x,X)x=x or 1;X=X or 0;while x>0 do keyevent(4)wait(X)x=x-1 end end;btn_switch=function(x,X)x=x or 0;X=X or 0;while x>0 do wait(X)keyevent(187)x=x-1 end end;clone_table=function(a)local copy;if is_table(a)then copy={}for Y,Z in next,a,nil do copy[clone_table(Y)]=clone_table(Z)end;setmetatable(copy,clone_table(getmetatable(a)))else copy=a end;return copy end;odd=function(e)return not(e%2==0)end;random_string=function(W)local _={}for x=48,57 do table.insert(_,string.char(x))end;for x=65,90 do table.insert(_,string.char(x))end;for x=97,122 do table.insert(_,string.char(x))end;math.randomseed(os.time())if W>0 then return random_string(W-1).._[math.random(1,#_)]else return""end end;location_to_string=function(a0)return tostring(string.format("Location(%d, %d)",a0:getX(),a0:getY()))end;region_to_string=function(A)return tostring(string.format("Region(%d, %d, %d, %d)",A:getX(),A:getY(),A:getW(),A:getH()))end;is_location=function(t)if gettype(t)=="Location"then return true end;return false end;is_region=function(t)if gettype(t)=="Region"then return true end;return false end;is_match=function(t)if gettype(t)=="Match"then return true end;return false end;is_pattern=function(t)if gettype(t)=="Pattern"then return true,t:getFileName()end;return false,"_none_"end;debug_r=function(a1,a2,a3)if DEBUG_R==true or DEBUG_R==nil then local a4,a5,X,a6=0,0,0,0;local a7=""a3=a3 or 3;if is_table(a2)then a4=a2[1]a5=a2[2]X=a2[3]or 10;a6=a2[4]or 10;a7=not a2[3]and"Table(Location)"or"Table(Region)"elseif is_region(a2)or is_match(a2)then a7=is_region(a2)and"Region"or"Match"a4=a2:getX()a5=a2:getY()X=a2:getW()a6=a2:getH()elseif is_location(a2)then a7="Location"a4=a2:getX()-10;a5=a2:getY()-10;X=20;a6=20 elseif is_pattern(a2)or is_string(a2)then a7=is_string(a2)and"String"or"Pattern"if exists(a2)then local a8=getLastMatch()local a9=a8:getTarget()local aa=a8:getCenter()a4=a8:getX()a5=a8:getY()X=a8:getW()a6=a8:getH()toast("IMG - Target | "..a1)Region(a9:getX()-10,a9:getY()-10,20,20):highlight(a3)toast("IMG - Center | "..a1)Region(aa:getX()-10,aa:getY()-10,20,20):highlight(a3)else toast("IMG not found")end end;toast(a7 .." | "..a1)Region(a4,a5,X,a6):highlight(a3)end end;img_r=function(t,a3)a3=a3 or 2;if not is_string(t)then toast("strign expected at img_r ->"..gettype(t))return t end;t=str_replace(t,".png","")..".png"if DEBUG_R==true or DEBUG_R==nil then local a=Timer()if exists(t)then debug_r(t.." - time elapsed: "..a:set(),getLastMatch(),a3)end end;return t end;table_to_string=function(table,ab)ab=ab or""local ac="{"for ad,p in pairs(table)do if not is_numeric(ad)then ac=ac.."\n\t"..ab..tostring(ad).." = "end;if gettype(p)=="Location"then ac=ac..location_to_string(p)elseif gettype(p)=="Region"then ac=ac..region_to_string(p)elseif is_table(p)then ac=ac..table_to_string(p,ab.."\t")elseif is_string(p)then ac=ac.."'"..p.."'"elseif is_bool(p)then ac=ac..tostring(p)else ac=ac..p end;ac=ac..","end;ac=ac.."\n"..ab.."}\n"return ac end;get_values=function(t)if is_location(t)then return{x=t:getX(),y=t:getY()}elseif is_region(t)then return{x=t:getX(),y=t:getY(),w=t:getW(),h=t:getH()}elseif is_match(t)then return{x=t:getX(),y=t:getY(),w=t:getW(),h=t:getH(),center=get_values(t:getCenter()),score=t:getScore(),target=get_values(t:getTarget())}elseif is_table(t)then local A={}for s,e in pairs(t)do A[#A+1]=e end;return A else return{}end end;is_timeout=function(ae,af)if ae:check()>af then return true end;return false end;get_clock=function(a)a=tonumber(a)local A={h=00,m=00,s=00}local c="00:00:00"if a>0 then A.h=string.format("%02.f",math.floor(a/3600))A.m=string.format("%02.f",math.floor(a/60-A.m*60))A.s=string.format("%02.f",math.floor(a-A.h*3600-A.m*60))c=A.h..":"..A.m..":"..A.s end;return c,A end;is_double=function(...)return is_float(...)end;is_array=function(...)return is_table(...)end;clone_array=function(...)return clone_table(...)end;array_to_string=function(...)return table_to_string(...)end;in_array=function(...)return in_table(...)end;array_reverse=function(...)return table_reverse(...)end;validate_array=function(...)return validate_table(...)end
gettype=function(a)local b=typeOf(a)if b=="userdata"then return a:typeOf()end;return b end;is_string=function(c)if typeOf(c)=="string"then return true end end;is_bool=function(d)if typeOf(d)=="boolean"then return true end;return false end;is_numeric=function(e)if tonumber(e)~=nil then return true end;return false end;is_float=function(e)if e~=math.floor(e)then return true end;return false end;is_table=function(a)if typeOf(a)=="table"then return true end;return false end;print_r=function(a,f,g)table.show=function(a,f,g)local h;local i;local function j(a)return next(a)==nil end;local function k(l)local m=tostring(l)if typeOf(l)=="function"then local n=debug.getinfo(l,"S")if n.what=="C"then return string.format("%q",m..", C function")else return string.format("%q",m..", defined in ("..n.linedefined.."-"..n.lastlinedefined..")"..n.source)end elseif typeOf(l)=="number"or typeOf(l)=="boolean"then return m else return string.format("%q",m)end end;local function o(p,f,g,q,r)g=g or""q=q or{}r=r or f;h=h..g..r;if typeOf(p)~="table"then h=h.." = "..k(p)..";\n"else if q[p]then h=h.." = {}; -- "..q[p].." (self reference)\n"i=i..f.." = "..q[p]..";\n"else q[p]=f;if j(p)then h=h.." = {};\n"else h=h.." = {\n"for s,t in pairs(p)do s=k(s)local u=string.format("%s[%s]",f,s)r=string.format("[%s]",s)o(t,u,g.." ",q,r)end;h=h..g.."};\n"end end end end;f=f or"__unnamed__"if typeOf(a)~="table"then return f.." = "..k(a)end;h,i="",""o(a,f,g)return h..i end;print(table.show(a,f,g))end;dprint=function(...)if DEVELOPER==true then print(...)end end;dprint_r=function(...)if DEVELOPER==true then print_r(...)end end;dtoast=function(...)if DEVELOPER==true then toast(...)end end;trim=function(c)return c:gsub("^%s*(.-)%s*$","%1")end;ltrim=function(c)return c:gsub("^%s*","")end;rtrim=function(c)local e=#c;while e>0 and c:find("^%s",e)do e=e-1 end;return c:sub(1,e)end;explode=function(c,v)v=v or"%s"local w,x={},1;for y in string.gmatch(c,"([^"..v.."]+)")do w[x]=y;x=x+1 end;return w end;str_replace=function(z,A,c,B)B=B or nil;return string.gsub(z,A,c,B)end;count=function(C)local count=0;for D in pairs(C)do count=count+1 end;return count end;in_table=function(E,t)for x,a in ipairs(E)do if a==t then return true end end;return false end;table_reverse=function(a)local A={}local x=#a;for s,t in ipairs(a)do A[x+1-s]=t end;return A end;function validate_table(F,G)G=G or{"table","number","boolean","string"}if not F then return false,"_file_not_set_"end;if not is_string(F)and not is_table(F)then return false,"_file_bad_type"end;if is_string(F)and not fileExists(F)then return false,"_file_not_found_"end;if is_table(F)then for s,t in pairs(F)do if in_table(G,gettype(t))then if is_table(t)then validate_table(t,G)end else return false,"_table_bad_format_"end end else local H,I,J,K,L,M=print,toast,print_r,dprint,dprint_r,dtoast;print,toast,print_r,dprint,dprint_r,dtoast=nil,nil,nil,nil,nil,nil;local N,O=pcall(dofile,F)print,toast,print_r,dprint,dprint_r,dtoast=H,I,J,K,L,M;if N then return validate_table(O,G)else return false,"_critical_"end end;return F end;is_dir=function(c)if is_string(c)and not c:match("(.+)%..+")then return true end;return false end;basename=function(P)local a=explode(P,"/")return a[#a]end;dirname=function(c)local a,A=explode(c,"/"),""for x,t in ipairs(a)do if x<#a then A=A..t.."/"end end;return A end;file_extension=function(Q)local c=Q;local a=""local A=""for x=c:len(),1,-1 do if c:sub(x,x)~="."then a=a..c:sub(x,x)else break end end;for R=a:len(),1,-1 do A=A..a:sub(R,R)end;return A end;mkdir=function(P)if os.execute("mkdir -p \""..P.."\"")==0 then return true end;return false end;rmdir=function(P)if os.execute("rm -rf \""..P.."\"")==0 then return true end;return false end;copy=function(c,v)if mkdir(v)and os.execute("cp -rf \""..c.."\" \""..v.."\"")==0 then return true end;return false end;function scandir(S,T)T=T or"/sdcard/__temp/"local U=T.."_scandir_"local V="ls "..S.." > "..U;if not mkdir(T)then return false,"_mkdir_"end;if os.execute(V)~=0 then return false,"_list_"end;local W={}for X in io.lines(U)do W[#W+1]=X end;if not rmdir(U)then return false,"_rmdir_"end;return W end;pathinfo=function(P,Y)local A={}local Z=not Y and 4 or 1;for x=1,Z do if Y=="PATHINFO_DIRNAME"or Z==4 then A["dirname"]=dirname(P)end;if Y=="PATHINFO_BASENAME"or Z==4 then A["basename"]=basename(P)end;if Y=="PATHINFO_EXTENSION"or Z==4 then A["extension"]=file_extension(P)end;if Y=="PATHINFO_FILENAME"or Z==4 then A["filename"]=str_replace(basename(P),"(%.%w+)$","")end end;if Z==1 then return A[string.lower(str_replace(Y,"(.*)%_",""))]else return A end end;btn_home=function()keyevent(3)end;btn_back=function(x,_)x=x or 1;_=_ or 0;while x>0 do keyevent(4)wait(_)x=x-1 end end;btn_switch=function(x,_)x=x or 0;_=_ or 0;while x>0 do wait(_)keyevent(187)x=x-1 end end;clone_table=function(a)local copy;if is_table(a)then copy={}for a0,a1 in next,a,nil do copy[clone_table(a0)]=clone_table(a1)end;setmetatable(copy,clone_table(getmetatable(a)))else copy=a end;return copy end;odd=function(e)return not(e%2==0)end;random_string=function(Z)local a2={}for x=48,57 do table.insert(a2,string.char(x))end;for x=65,90 do table.insert(a2,string.char(x))end;for x=97,122 do table.insert(a2,string.char(x))end;math.randomseed(os.time())if Z>0 then return random_string(Z-1)..a2[math.random(1,#a2)]else return""end end;location_to_string=function(a3)return tostring(string.format("Location(%d, %d)",a3:getX(),a3:getY()))end;region_to_string=function(A)return tostring(string.format("Region(%d, %d, %d, %d)",A:getX(),A:getY(),A:getW(),A:getH()))end;is_location=function(t)if gettype(t)=="Location"then return true end;return false end;is_region=function(t)if gettype(t)=="Region"then return true end;return false end;is_match=function(t)if gettype(t)=="Match"then return true end;return false end;is_pattern=function(t)if gettype(t)=="Pattern"then return true,t:getFileName()end;return false,"_none_"end;debug_r=function(a4,a5,a6)if DEBUG_R==true or DEBUG_R==nil then local a7,a8,_,a9=0,0,0,0;local aa=""a6=a6 or 3;if is_table(a5)then a7=a5[1]a8=a5[2]_=a5[3]or 10;a9=a5[4]or 10;aa=not a5[3]and"Table(Location)"or"Table(Region)"elseif is_region(a5)or is_match(a5)then aa=is_region(a5)and"Region"or"Match"a7=a5:getX()a8=a5:getY()_=a5:getW()a9=a5:getH()elseif is_location(a5)then aa="Location"a7=a5:getX()-10;a8=a5:getY()-10;_=20;a9=20 elseif is_pattern(a5)or is_string(a5)then aa=is_string(a5)and"String"or"Pattern"if exists(a5)then local ab=getLastMatch()local ac=ab:getTarget()local ad=ab:getCenter()a7=ab:getX()a8=ab:getY()_=ab:getW()a9=ab:getH()toast("IMG - Target | "..a4)Region(ac:getX()-10,ac:getY()-10,20,20):highlight(a6)toast("IMG - Center | "..a4)Region(ad:getX()-10,ad:getY()-10,20,20):highlight(a6)else toast("IMG not found")end end;toast(aa.." | "..a4)Region(a7,a8,_,a9):highlight(a6)end end;img_r=function(t,a6)a6=a6 or 2;if not is_string(t)then toast("strign expected at img_r ->"..gettype(t))return t end;t=str_replace(t,".png","")..".png"if DEBUG_R==true or DEBUG_R==nil then local a=Timer()if exists(t)then debug_r(t.." - time elapsed: "..a:set(),getLastMatch(),a6)end end;return t end;table_to_string=function(table,ae)ae=ae or""local af="{"for ag,p in pairs(table)do if not is_numeric(ag)then af=af.."\n\t"..ae..tostring(ag).." = "end;if gettype(p)=="Location"then af=af..location_to_string(p)elseif gettype(p)=="Region"then af=af..region_to_string(p)elseif is_table(p)then af=af..table_to_string(p,ae.."\t")elseif is_string(p)then af=af.."'"..p.."'"elseif is_bool(p)then af=af..tostring(p)else af=af..p end;af=af..","end;af=af.."\n"..ae.."}\n"return af end;get_values=function(t)if is_location(t)then return{x=t:getX(),y=t:getY()}elseif is_region(t)then return{x=t:getX(),y=t:getY(),w=t:getW(),h=t:getH()}elseif is_match(t)then return{x=t:getX(),y=t:getY(),w=t:getW(),h=t:getH(),center=get_values(t:getCenter()),score=t:getScore(),target=get_values(t:getTarget())}elseif is_table(t)then local A={}for s,e in pairs(t)do A[#A+1]=e end;return A else return{}end end;is_timeout=function(ah,ai)if ah:check()>ai then return true end;return false end;get_clock=function(a)a=tonumber(a)local A={h=00,m=00,s=00}local c="00:00:00"if a>0 then A.h=string.format("%02.f",math.floor(a/3600))A.m=string.format("%02.f",math.floor(a/60-A.m*60))A.s=string.format("%02.f",math.floor(a-A.h*3600-A.m*60))c=A.h..":"..A.m..":"..A.s end;return c,A end;preferencePutData=function(t,l)if is_region(l)then preferencePutString(t,string.format("Region(%d, %d, %d, %d)",l:getX(),l:getY(),l:getW(),l:getH()))elseif is_location(l)then preferencePutString(t,string.format("Location(%d, %d)",l:getX(),l:getY()))elseif is_table(l)then preferencePutString(t,table_to_string(l))else return false end;return true end;preferenceGetData=function(t,c)if is_string(c)and preferenceGetString(t,c)then return loadstring('return '..preferenceGetString(t,c))()end;return false end;is_double=function(...)return is_float(...)end;is_array=function(...)return is_table(...)end;clone_array=function(...)return clone_table(...)end;array_to_string=function(...)return table_to_string(...)end;in_array=function(...)return in_table(...)end;array_reverse=function(...)return table_reverse(...)end;validate_array=function(...)return validate_table(...)end;preferencePutRegion=function(...)return preferencePutData(...)end;preferencePutLocation=function(...)return preferencePutData(...)end;preferencePutTable=function(...)return preferencePutData(...)end;preferencePutArray=function(...)return preferencePutData(...)end;preferenceGetRegion=function(...)return preferenceGetData(...)end;preferenceGetLocation=function(...)return preferenceGetData(...)end;preferenceGetTable=function(...)return preferenceGetData(...)end;preferenceGetArray=function(...)return preferenceGetData(...)end;if preferenceGetBoolean("LOG_2017/08/21",true)then print("Lualib ChangeLog - 2017/08/21")print("\n#New#\n")print("- preferencePutData()")print("- preferenceGetData()")print("- dprint()")print("- dprint_r()")print("- dtoast()")print("- validate_table()")end;preferencePutBoolean("LOG_2017/08/21",false)

0 comments on commit 4c7e0fa

Please sign in to comment.