io.write i this version(1.5)?

Can we use the io functions in version 1.5?

I only ask because prior to the update for this version we could not. If not then when we are able to will we be able to have it write code right into a new specified tab (using the io.write function)?

1/ you can use io.* library.
2/ there are specific function in this version to write into a tab:

-- Create a tab named "Test"
-- In the current project
saveProjectTab("Test", "-- This is a test!")

Hi @jmv38,

I’m sure someone’s already demonstrated this by either putting errors or watched variable values into an added tab. Very recent since introduction of 1.5.



I also used !ruilov’s GitHub code to pull down entire projects into Codea; this was before the saveProjectTab() functiron existed, and it worked perfectly.

Can you guys show me where the io.write functions are documented in Codea?

I’ve tried to search them out in the in app reference, no results. Is there any reason to believe that they have been enabled prior to now?

Can someone provide an example of and io.write for the iPad. I can’t seem to get them to work. I have no problem with a couple of other apps that allow the io functions.

My current understanding is

--# Main
-- test io

-- Use this function to perform your initial setup
function setup()

print("--------- test 1 ---------------")
-- this works
local file = os.getenv("HOME").."/Documents/my.txt"
local txt = "This is\
some sample text\
for Lua."
writeTest(file,txt)  -- comment this line and restart to check the file is there

print("--------- test 2 ---------------")
-- this SEEMS to work, because read works, but the file is actually not writen on disk
-- if the program is run again with the write commented, then nothing reads.
-- so you cam write in root folder, but not subfolders
file = os.getenv("HOME").."/Documents/test_io_simple.codea/my.txt"
writeTest(file,txt)  -- comment this line and restart to check the file is there

-- binary test
print("--------- test 2 ---------------")
print("--- binary read test ----")
print("--- from text file :")
test = readBinary(file)


function writeTest(file,txt)
    print("------------------------ ")
    print("write in "..file)
    print("---- write done ----")
function readTest(file)
    print("------------------------ ")
    print("read from "..file)
    local li
    for i in io.lines() do print(i) end
    -- no close needed: done by io.lines()
    print("---- read done ----")

-- found on web
function readBinary(file)
    local hBinaryFile =, "rb");
    local sBinaryContent = "";
            local block = hBinaryFile:read(512); -- Read only 512 bytes per iteration
            if(not block)then break;end
            sBinaryContent = sBinaryContent..block
    local t = {}
    for i=1,sBinaryContent:len() do
        t[i] = sBinaryContent:byte(i)
    return t
function writeBinary(file,sBinaryContent)
    -- Now lets output it again.
    local hBinaryOutput =, "wb");
         hBinaryOutput:write(sBinaryContent); --You could do it in parts, but oh.

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

    -- This sets the line thickness

    -- Do your drawing here

Thanks @Jmv38 for the example. That explaines a lot and things work OK. I was using the, open, and write commands like you have, but I was messing up os.getenv(). Is there a directory function or any way to look in Documents to see what files are there.

Edit: @Jmv38 I changed the line “print(table.concat(test,”-“)” to “print(table.concat(test,” “))” in – binary test and “t[i] = sBinaryContent:byte(i)” to “t[i]=string.format(”%02x",sBinaryContent:byte(i))" in function readBinary(file) so that it prints out the actual 2 byte hex values.