Add documentation and examples for new features.

This commit is contained in:
yabu76 2026-03-08 11:17:50 +09:00
parent 1b0ef08d95
commit 2316c0216a
7 changed files with 702 additions and 73 deletions

21
examples/lua/expects.lua Normal file
View file

@ -0,0 +1,21 @@
--
-- example of intaction with AT modem.
--
tio.write("AT\r")
local matches, all = tio.expect("OK", 1000)
if matches == nil then
tio.echo("no response 1\r\n")
os.exit(0)
end
msleep(200)
tio.read(1000, tio.C.NOWAIT)
tio.write("ATFANTASYCMD\r")
local idx, matches, all = tio.expects({"OK", "ERROR", "BUSY"}, 1000)
if idx == nil then
tio.echo("no response 2\r\n")
os.exit(0)
end
-- this display 2, ERROR
print(idx, matches[1])
os.exit(0)

View file

@ -0,0 +1,41 @@
--
-- tio's script-init file
--
-- Please add following to your tio config file.
--
-- script-init-file = /<<your-full-path>>/.tio-scipt-init.lua
--
-- note: tio module is already loaded.
--
function tio.conv_lf_to_crlf(str)
local new_str = str:gsub("\n", "\r\n")
return new_str
end
function tio.lprint(...)
local args = {...}
local argN = #args
for i = 1, argN - 1 do
io.write(tio.conv_lf_to_crlf(tostring(args[i])))
io.write("\t")
end
if argN > 0 then
io.write(tio.conv_lf_to_crlf(tostring(args[argN])))
end
io.write("\r\n")
end
function tio.banner()
local banner = [[
_ _ _ _ __
| |_ (_) ___ ___ | |_ __ _ _ __ | |_ _ \ \
| __|| | / _ \ / __|| __|/ _` || '__|| __| (_)_____ | |
| |_ | || (_) | \__ \| |_| (_| || | | |_ _ _|_____|| |
\__||_| \___/ |___/ \__|\__,_||_| \__|(_) (_) | |
/_/]]
tio.lprint(banner)
end
tio.banner()