cac function
user_8567946
abc
3 years ago
2.8 kB
8
Indexable
function readFile(path)
local file = io.open(path,"r");
if file then
local _list = {};
for l in file:lines() do
table.insert(_list,l)
end
file:close();
return _list
end
end
function readFileString(path)
local file = io.open(path,"rb");
if file then
local content = file:read "*a"
file:close();
return content
end
end
function ReadFileWithSpecChar(path,specchar)
local file = io.open(path,"r");
if file then
local _list = {};
for l in file:lines() do
table.insert(_list,splitString(l,specchar))
end
file:close();
return _list
end
end
function writeFile(path,text,mode)
local file = io.open(path,mode);--a:append mode, w:replace mode
if file then
file:write(text.."\n");
file:close();
end
end
function writeFileTable(path,Table)
os.remove(path);
sleep(1000);
local file = io.open(path,"w");--a:append mode,
if file then
for _,l in ipairs(Table) do
--table.insert(_list,l)
file:write(l.."\n");
end
file:close();
end
end
function sleepWithToast(x,mess)
local timeslepp = x
repeat
toast(mess.." "..timeslepp/1000);
timeslepp = timeslepp - 1000
usleep(1000000);
until timeslepp <= 0
end
function waitImage(imagePath, failRepeat)
local repeatTIme = failRepeat;-- số lần tìm kiếm lập lại
repeat
repeatTIme = repeatTIme - 1;
if repeatTIme == 0 then --khi lập lại giảm tới 0 sẽ thông báo với auto pc lập lại vòng mới, và dừng script bằng assert()
return false;
end
local result = findImage(imagePath, 0, 0.95, nil, false);
for i, v in pairs(result) do
return result;
end
usleep(1000000);-- nghỉ 1 giây
return false;
until 1 == 2
end
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
function splitString(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
function removeSpaceString(data)
local codeRef2 = string.gsub(data, '%s+', ''); --remove khoảng trắng
codeRef2 = codeRef2:gsub('%s+', '');--remove khoảng trắng
codeRef2 = codeRef2:gsub("%s$", "");--remove khoảng trắng
codeRef2 = codeRef2:gsub("\n", "");--remove xún dòng
return codeRef2;
end
function sleep(x)
usleep(x*1000);
end
function checkSDTdaguichua()
if waitImage(currentPath().."/images/KyHieuDaTungGuiTrongDB.PNG",2) ~= false then
toast("So da gui roi",3)
tap(1112, 221);
return false
end
endEditor is loading...