io Library
The io library has been simplified and only a subset of functions and their functionality is available. What follows is a complete reference of io functions that are available to EdgeTX scripts

Available functions:

  • io.open()
  • io.close()
  • io.read()
  • io.write()
  • io.seek()

Examples

Read the whole file

1
-- this is a stand-alone script
2
3
local function run(event)
4
print("lua io.read test") -- print() statements are visible in Debug output window
5
local f = io.open("foo.bar", "r")
6
while true do
7
local data = io.read(f, 10) -- read up to 10 characters (newline char also counts!)
8
if #data == 0 then break end -- we get zero length string back when we reach end of the file
9
print("data: "..data)
10
end
11
io.close(f)
12
return 1
13
end
14
15
return { run=run }
Copied!

Append data to file

1
-- this is a stand-alone script
2
3
local function run(event)
4
print("lua io.write test")
5
local f = io.open("foo.bar", "a") -- open file in append mode
6
io.write(f, "first line\r\nsecond line\r\n")
7
io.write(f, 4, "\r\n", 35.6778, "\r\n") -- one can write multiple items at the same time
8
local foo = -4.45
9
io.write(f, foo, "\r\n")
10
io.close(f)
11
return 1 -- this will end the script execution
12
end
13
14
return { run=run }
Copied!