Standard LUA io library has been simplified and only a subset of functions and their functionality is available.
Available functions:
io.open()
io.close()
io.read()
io.write()
io.seek()
Examples
Read the whole file
-- this is a One-time scriptlocalfunctionrun(event)print("lua io.read test") -- print() statements are visible in Debug output windowlocal f =io.open("foo.bar", "r")whiletruedolocal data =io.read(f, 10) -- read up to 10 characters (newline char also counts!)if#data ==0thenbreakend-- we get zero length string back when we reach end of the fileprint("data: "..data)endio.close(f)return1endreturn { run=run }
Append data to file
-- this is a One-time scriptlocalfunctionrun(event)print("lua io.write test")local f =io.open("foo.bar", "a") -- open file in append modeio.write(f, "first line\r\nsecond line\r\n")io.write(f, 4, "\r\n", 35.6778, "\r\n") -- one can write multiple items at the same timelocal foo =-4.45io.write(f, foo, "\r\n")io.close(f)return1-- this will end the script executionendreturn { run=run }