print("Hello World")
单行注释
全局变量:默认
局部变量:必带local
数据类型:nil、boolean、number、string、function、和 table
类型检测:type()
类型转换:tostring() tonumber()
boolean:true 和 false
可以用 [[]] 来表示一块字符串
lua 的所有下标是从1开始的
Invalid method 无效的方法
函数的定义,默认返回nil
function add(a,b)
return a+b
end
连续赋值: local a,b=1,2
交换变量:a,b=b,a
简单table结构:{1,"A",11.22}
复杂table结构:{ 姓名= "张三", 年龄 = "33}
字符串和简单的table都可以通过下标访问
s="qwdw77"
tab1={1,"A",11.22}
复杂table结构只能根据key来访问
tab2={ 姓名= "张三", 年龄 = "33} --->tab2["年龄"]
for i=1,#tab,1 do
print(tab[i])
sleep(1000)
break
end
for k,v in pairs(tab) do
print(k.." --- "..v)
end
for k,v in pairs(tab) do
print(k.." --- "..v)
end
exit() 退出
while (条件表达式) do
循环体
end
if 1==1 then
print(1)
elseif 1==2
print(2)
else
print(3)
end
关系运算符 == ~=
逻辑运算符 and or not
其他运算符
.. 连接成字符串
# 用来计算字符串或者简单table的长度
转义字符:\n 换行符
正则表达式通配符: %d %w + ? .
string.gsub("aaaa","v","z",3);
param1为要操作的字符串,
param2为被替换的字符,
param3要替换的字符,
param4替换次数(可以忽略,则全部替换),如:
返回值 替换好的字符串,不存在则返回 nil
s,e=string.find("Hello Lua user", "Lua", 1)
a=string.sub("史沐凡",4,6)
table操作insert remove
table.insert (table, [pos,] value)
table.remove (table [, pos])
模块调用 require "xxx" 不能带.lua
模拟器操作
runApp("包名")
click(100,700)
click(rule)
input(rule,s)
slid(100,100,700,700)
home()
back()
toast("要显示的文本")
toast("要显示的文本",5000)
talk("我是系统朗读的声音")
orderdata={
pwd="",
order_id="0876555",
task="1",
code="01",
people_mark="",
name="",
_id="63032494177264002585bf69",
phone_code="1234562",
status=0,
mark="145",
phone="13288843383",
channel="huawei"
}
function 显示运行时长()
local t1 = time()
t1=math.floor((t1-t0)/1000)
local h=t1//3600
local m=(t1-(h*3600))//60
local s=t1-(h*3600)-(m*60)
if h>0 then
toast("已运行:"..tostring(h).."时"..tostring(m).."分"..tostring(s).."秒")
elseif m>0 then
toast("已运行:"..tostring(m).."分"..tostring(s).."秒")
else
toast("已运行:"..tostring(s).."秒")
end
end
function trim(s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
function 文本分割(s, delimiter)
s = tostring(s)
delimiter = tostring(delimiter)
if (delimiter == "") then return false end
local pos, arr = 0, {}
for st, sp in function() return string.find(s, delimiter, pos, true) end do
table.insert(arr, string.sub(s, pos, st - 1))
pos = sp + 1
end
table.insert(arr, string.sub(s, pos))
return arr
end
function 等待颜色出现(c,t)
for i =1,t,1 do
print("等待区域颜色出现...")
local cReult = findColor(c);
if cReult then
print( '区域颜色出现' )
return true
end
sleep(1000)
end
print("等待区域颜色出现超时...")
end
function 等待颜色消失(c,t)
for i =1,t,1 do
print("等待区域颜色消失...")
local cReult = findColor(c);
if cReult==nil then
print( '区域颜色消失' )
return true
end
sleep(1000)
end
print("等待区域颜色消失超时...")
end
function 区域找色(c)
local p = findColor(c);
if p then
print('找到颜色')
return true
end
end
function 区域找色点击(c)
local p = findColor(c);
if p then
print('找色点击了')
click(p.x,p.y);
return true
end
end
function wait_node(r,t)
for i =0,t,1 do
print("等待节点出现")
if find(r) then
print("节点已出现")
return true
end
sleep(1000)
end
print("等待节点出现超时")
return false
end
function node_click(r)
local v=find(r)
if v then
print("node_click:find")
click((v.rect.left+v.rect.right)/2,(v.rect.top+v.rect.bottom)/2)
end
end
function node_click_rxry(r,rx,ry)
local v=find(r)
if v then
print("node_click_rxry:find")
click((v.rect.left+v.rect.right)/2+rx,(v.rect.top+v.rect.bottom)/2+ry)
end
end
function get_random()
local t = time()
t = tostring(t)
t = string.sub(t, #t, #t)
print("随机数:" .. t)
return tonumber(t)
end
function 读取文件(filename)
local file = io.open("/sdcard/"..filename..".txt","r")
if file then
local string = file:read("*a")
return string
else
print("文件不存在")
end
file:close()
end
function 写入文件(filename,s)
local file = io.open("/sdcard/"..filename..".txt","w")
file:write(s):close()
end
function show_ui()
屏幕=getScreen();
screen_x=屏幕.width
screen_y=屏幕.height
config ={
x = 1;
y = 1;
width= 250;
height=200;
color = "#00CCFF";
bgcolor ="#80000000";
mode = 3;
size = 10;
debug = false;
shadow = true;
};
logConfig(config);
nemuconfig ={
x = 0;
y =screen_y;
alpha = 0.4;
}
menuConfig(nemuconfig)
ui={
title="光遇代跑订单";
width =0;
views={
{title ="WEB_API",type="radio",value="*zhouze1|0000000",ore=1,id="wbapi"},
{title ="激活码",type="text",value=激活码,id="激活码"},
{title ="设备编号",type="edit",hint="请输入设置编号",value="01",id="设备编号"},
{title ="渠道",type="check",value="huawei|oppo|*official|xiaomi|vivo|application",ore=0,id="huawei|oppo|official|xiaomi|vivo|application"},
}
}
local ret = show( ui )
if ret then
print('用户选择了确认')
print("设备编号:"..设备编号)
channel_default=""
web_API=wbapi
if huawei then
channel_default=channel_default.."huawei"
end
if oppo then
channel_default=channel_default.."oppo"
end
if official then
channel_default=channel_default.."official"
end
if xiaomi then
channel_default=channel_default.."xiaomi"
end
if vivo then
channel_default=channel_default.."vivo"
end
if application then
channel_default=channel_default.."application"
end
print("channel:"..channel_default)
print("web_API:"..web_API)
else
print('用户选择了取消')
exit()
end
end