Codea/Lua only suitable for game apps?

@Luatee Of course you can, but the drawing will only occur when a touch is happening, and it might occur multiple times if multiple touches are happening. Also, the ellipse will disappear as soon as the touch is over, unless the backingMode is set to retained.

Alrighty then…thanks for all the advice. But you all that have done biz apps with codea, I am lookin at a blank slate, and would like to avoid reinventing the file I/O wheel. Might I find starter examples on GITHUB, or elsewhere?

That is quite simple. Here are some xamples

-- 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

@Luatee my experience is that you cannot draw ellipses from the touched function. Not sure why, but I have never been able to do it.


function draw()
if CurrentTouch.state == BEGAN then

@Northbeacher Have you looked at Cider7? The app, and the set of classes that support it, make a lot of the common interface bits & pieces easy to put together.

@CodeaNoob, @Kjell, @Luatee

This is what we mean. This will not draw an ellipse.

function setup()
    touches = {}

function touched(touch)
    if touch.state == ENDED then
        touches[] = nil
        touches[] = touch
        ellipse(touch.x, touch.y, 100, 100)

function draw()
    background(0, 0, 0, 255)
    for k,touch in pairs(touches) do
        -- ellipse(touch.x, touch.y, 100, 100)

@Kjell I tried drawing from touched a while back but it didn’t work, so I used setContext in the end…

@Luatee and @MrScience101 Drawing works fine from touched, but the touch function is only executed when there IS a touch.


function setup()

-- This function gets called once every frame
function touched(touch)
    if touch.state == BEGAN then
        ellipse(touch.x, touch.y, 100)

I understand that already, it just didn’t show up when I touched the screen, the touched function is called after draw so surely it would draw over anything in the draw function? Or does it draw it to the next frame?

Codea is fine for all kinds of apps. It was designed with games in mind, but can be used for business applications too. It has the file IO also, if you need to read/write files. Drawing and UIs are very simple and easy to make and use.

A Mac is only needed for if you want to put your app on the App Store. When you’ve found you’re ready, you long press on the project in the project selector, and select export. There you’ll get a variety of options such as the app icon and spritepacks to include in the bundle. Then it’ll generate an Xcode project file, and you can save it to Dropbox, sync it to your Mac, and open it up and use it on there.

So, if you want to play with it for now, Codea is all you need. If you think your app is polished enough for the App Store, then you need a Mac to get it out there. Note, to put it on the App Store from your Mac, you need an Apple Developer License, which cost $99 per year. (You can export it to your Mac and play with it there and with Obj-C addons for free, it’s only when you put it up on the App Store.)

@MrScience101 That code DOES draw an ellipse. It’s just that the background() function overwrites it before the ellipse has a chance to render. Comment out the background call, and preferably set the backingMode to RETAINED to see it work.

@SkyTheCoder and @Mark, ah that is magical. Thank you.

@SkyTheCoder ahh background that’s why, thanks

If you want to see something weird, remove the backingMode statement in my little snippet but don’t add a draw routine or background statement.

Yes, Codea could be used to write any kind of apps, including bussiness apps. But, should you? As a mainly bussiness app developer, I don’t think so. I agree with @causeless and @ignatz about Codea that it is more for graphics animation and game prototyping tool. For bussiness app that need standard UI and database processing, Pythonista is a bit better. I said “a bit” because Pythonista doesn’t have standard UI API as well.

For bussiness app development, Codea need:

  1. Standard UI. I don’t care whether it’s native or emulated (like Cider) as long as it exists.

  2. Database. SQLite support is the minimum. But I prefer embedded Firebird ( for better features and capabilities.

  3. Gesture. You don’t want to code every tap, swipe, and pinch.

I’ve been requesting those things since a long ago. Looking at TLL’s responses, I think it’s very unlikely to get those things in foreseeable future, if ever. :slight_smile:

@bee. 2/3 of those will be done in SkyUI.

Now I’ve got the idea for making my own database API!

@Briarfox there is simple way: the “url scheme” : once implemented you can call codea and pass it parameters (like project to run) from safari. Then it is easy to make an onscreen link to start this link. Pythonista has it, it works well. Codea doesnt. Yet. Simenon considered doing it 6 months ago, but i guess he had other priorities up to now.

@jmv38 Yeah I’d like that :slight_smile:

I always get a chuckle out of people suggesting what Codea should be used for. It presupposes that there’s a wrong answer, that there’s some task that’s reasonable on the ipad, but not reasonable for Codea.

The other day, I had to measure some flour by weight (cooking with my girls!) - but had no scale. I ended up using a ruler as a makeshift balance, and weighing my flour against a cup of water. Now - that ruler is for measuring distance, or maybe drawing a straight line - but it worked, and well, so who is to say that was wrong? Sometimes, to succeed, you need to think outside the box a bit.

Codea is fine for business apps. Or Games. or command-and-control (I know of a guy who used it to control a crane remotely). The real question to answer is “How comfortable are you using it to write an app?” - if you program in python day in and day out, pythonista may be better for you. But - if you loathe whitespace as a control structure, as I do, pythonista may be entirely unacceptable. I can tell you for sure, if you want a community around to talk to about the process, Codea can’t be beat.

More to the point - Codea can easily do what you described. So - it’s fine choice.

Now - if you’re planning on selling the app, know that to use the runtime is a non-trivial task. You’ll need a mac, and xcode, and a developer license from apple, and some fairly reasonable computer skills, and if you aren’t already comfortable with all of that, it can be very difficult. If you just want to share the code with others using Codea, there are options that are much easier to use.

Slight side topic that @Bortels got me thinking on with his comments about all thats needed to release to the App Store. The few apps I’ve done for business applications have been for a very small user base. If Codea had the ability to create a homescreen shortcut to a specific project that would run when clicked, I’d be in heaven. It was really a pain to get a compiled version of my project on a few ipads. If I could just install Codea and shortcut the app, I would be oh so happy.