mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Overhaul Lua API
Lua API moved into a tio library table and names adjusted to Lua stdlib style. Regex in expect() replaced with Lua patterns so binary data can be handled. New tio.alwaysecho variable allows enabling and disabling echo to console. Read and write functions now manage complex retry and timeout logic internally, giving the user a simple "nil if fail" API like the rest of Lua. exit() was removed, os.exit() already exists in the Lua standard library.
This commit is contained in:
parent
8f33cff6ea
commit
114b69b68a
9 changed files with 318 additions and 465 deletions
|
|
@ -13,14 +13,13 @@ local logins = {
|
|||
},
|
||||
}
|
||||
|
||||
local found, match_str = expect("\\w+- login:", 10)
|
||||
if (1 == found) then
|
||||
local hostname = string.match(match_str, "^%w+")
|
||||
local hostname = tio.expect("^(%g+) login:", 10)
|
||||
if hostname then
|
||||
local login = logins[hostname]
|
||||
if (nil ~= login) then
|
||||
write(login.username .. "\n")
|
||||
expect("Password:")
|
||||
write(login.password .. "\n")
|
||||
tio.write(login.username .. "\n")
|
||||
tio.expect("Password:")
|
||||
tio.write(login.password .. "\n")
|
||||
else
|
||||
io.write("\r\nDon't know login info for " .. hostname .. "\r\n")
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue