节点精灵通用模块总结和lua学习笔记

print("Hello World")

单行注释  --  ctrl+/

全局变量:默认

局部变量:必带local

数据类型:nil、boolean、number、string、function、和 table

类型检测:type() 

类型转换:tostring()  tonumber()

boolean:truefalse

可以用 [[]] 来表示一块字符串

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"-->s[3]
tab1={1,"A",11.22}--->tab1[2]

复杂table结构只能根据key来访问
tab2={ 姓名= "张三", 年龄 = "33} --->tab2["年龄"] 

--简单table遍历 1
for i=1,#tab,1 do   --包前包后
    print(tab[i])
    sleep(1000)  --单位毫秒
    break --跳出当前循环(for|while)
end

--简单table遍历 2
for k,v in pairs(tab) do
	print(k.." --- "..v)--k是下标 v是值value
end

--复杂table遍历 1
for k,v in pairs(tab) do
	print(k.." --- "..v)--k是键key v是值value
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("包名")--启动一个app

click(100,700)--点击

click(rule)--根据节点规则点击

input(rule,s)--根绝节点规则输入内容s

slid(100,100,700,700)--滑动

home()--到首页

back()--返回

toast("要显示的文本")--弹窗提示文本

toast("要显示的文本",5000)--弹窗提示文本,5秒后消失

talk("我是系统朗读的声音")--朗读文本
--节点精灵通用模块总结
--全局配置
orderdata={
    pwd="",--密码
    order_id="0876555",--订单号
    task="1",--任务
    code="01",--设备编号
    people_mark="",--人工备注
    name="",--账号
    _id="63032494177264002585bf69",--这个作为唯一索引
    phone_code="1234562",--手机验证码
    status=0,--0(未处理) 1(待处理)2(未登录)3(待验证)4(处理中)5(已完成)6(异常)
    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); -- 坐标点击方法 需 Android 7.0 以上系统支持 (包含7.0)
        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()
    --获取1位随机数
    local t = time()
    t = tostring(t)
    t = string.sub(t, #t, #t)
    print("随机数:" .. t)
    return tonumber(t)
end
function 读取文件(filename)
    --读取文件txt
    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)
    --写入文件txt
    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; -- 位置x
        y = 1; --位置y
        width= 250; --宽度
        height=200; --高度
        color = "#00CCFF";--ARGB 字体颜色
        bgcolor ="#80000000"; --背景颜色(ARGB);传统RGB 颜色前加两位可代表透明度 00-FF【16进制】 ,00代表完全透明
        mode = 3; --模式 :1= 显示可点击,2=显示不可点击,3=隐藏
        size = 10;-- 字体大小
        debug = false; --是否输出系统日志 false =不输出,true = 输出
        shadow = true; --是否显示阴影,false:不显示 true 显示;
    };
    logConfig(config);
    nemuconfig ={
        x = 0; -- x坐标
        y =screen_y; -- y坐标
        alpha = 0.4; -- 透明度不能小于0.4,否则不生效
    }
    menuConfig(nemuconfig)
    ui={
        title="光遇代跑订单";--Author:QQ736592720
        width =0;
        -- height= -1;
        -- time = 1;
        views={
            --{title ="设备信息",type="text",value="小米MI 8 6G 6.21英寸 2248*1080 MIUI12.5.1"},
            --{title ="app顺序",type="edit",value="1华为>2oppo>3官服>4小米>5vivo"},
            --6186181
            {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)
        -- exit()
        -- 重启时间 = tonumber(重启时间) * 60
      else
        print('用户选择了取消')
        exit()
    end
end


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

光明有我16620122910

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值