函数:controller_injection 注入中控器运行

方法名称:注入中控器运行

方法功能:注入中控器运行代码

调用方法

ok,msg = ts_enterprise_lib:controller_injection(code);

参数 类型 字段 说明
code string 必填 注入代码内容
返回值 类型 说明
ok boolean 操作结果,成功返回 true,失败返回 false
msg string 操作结果详情,失败返回失败原因

简单的发账号示例

--[[
    请注意注入代码的安全,不安全的代码会导致中控器崩溃
        简单的发账号示例
        script/account.txt内保存账号密码
    --]]
ts_enterprise_lib = require("ts_enterprise_lib")
assert(ts_enterprise_lib,"无法引入企业专用库")
local ok,account =  ts_enterprise_lib:controller_injection(
    [[
        local f = io.open("script/account.txt", "r")
        if f then
            local account_tab = {} 
            local account = f:read()
            while account do 
                table.insert(account_tab,account) 
                account = f:read() 
            end
            f:close()
            if #account_tab > 0 then
                local f = io.open("script/account.txt", "w")
                if f then
                    for i = 2,#account_tab do
                        f:write(account_tab[i].."\n")
                    end
                    f:close()
                end
                return account_tab[1]
            else
                return false
            end     
        end
        return false
    ]]
)
assert(ok,account)
if account then
    nLog("获取账号:"..account)
    toast("获取账号:"..account)
else
    nLog("获取账号失败")
    toast("获取账号失败")
end
mSleep(1000)

封装中控器读写函数

function writeEEFile(str,path,mode) --写入文件内容,路径,类型,默认路径企业版目录 scriptData/playLog.text 下,自定义路径请把 \ 改为 /。默认类型追加,覆盖第三个参数写 "wb"
mode = mode or "a"
local telib = require("ts_enterprise_lib")
assert(telib,"无法引入企业专用库")
if path==nil then
local ok,msg = telib:controller_injection(
[[
require("lfs").mkdir("scriptData")
local f = io.open("scriptData/playLog.text","a")
if f then
f:write("]]..str..[[\r\n")
f:close()
end
]]
)
else
local ok,msg = telib:controller_injection(
[[
local f = io.open("]]..path..[[","]]..mode..[[")
if f then
f:write("]]..str..[[\r\n")
f:close()
end
]]
)
end
end
function findEEFile(path,tsType) --读取文件内容,读取方式(string 或 table)
path = path or "scriptData/playLog.text"
tsType = tsType or "string"
local telib = require("ts_enterprise_lib")
assert(telib,"无法引入企业专用库")
local ok,account
if tsType=="table" then
ok,account = telib:controller_injection(
[[
local f = io.open("]]..path..[[", "r")
if f then
local account_tab = {} 
local account = f:read()
while account do 
table.insert(account_tab,account) 
account = f:read() 
end
f:close()
return account_tab
end
return false
]]
)
else
ok,account = telib:controller_injection(
[[
local f = io.open("]]..path..[[", "r")
if f then
local account = f:read("*all")
f:close()
return account
end
return false
]]
)
end
return account
end
Copyright 北京帮你玩科技有限公司 2020 all right reserved,powered by Gitbook该文章修订时间: 2020-05-22 16:16:31

results matching ""

    No results matching ""