API ideas for next version

Hello team,

first let me say, that Codify is a really nice app. For me, I think this app has very high potential of being a hit for programmers and (open source) gamers on iPad. I am Tapsi, I code on a advance wars clone for different plattforms and this one looks really nice and ( more important ) like a real way to port it to iOS as well.
So if I’m allowed, I would share my ideas of additional API with you. Feel free to discuss about it and give me hints as well. ^^

Network API:

Not much, but if we could connect two sockets into a session, than we could allow multi player games.

netHandler = socket()
netHandler.onMessage = f // sets the handler function, that will be called on incoming messages
netHandler.connect( ip, netHandler ) // connects to an IP
netHandler.sendMessage( msg ) // sends a message
netHandler.disconnect( ) // disconnects
netHandler.listen( port ) // listen on a port

but I don’t know exactly what ports allowed to be used by iOS programs…

Persistent Storage:

Real cool games would be nice, but I think they need the ability to store data on the device ( like save games )

// gives you a persistent storage object for a name ( this way would allow sharing data between projects )
persistStorage( String storageName )

// storage object functions
st.save( String key, String value )
st.get( String key ) returns the value
st.delete( String key )

Misc:

sleep( Number time ) // pauses the program
setFont( family, size, modifiers ) // sets the font for printing text on screen
drawText( String text ) // prints text on screen
getInput( keyboardType ) // open onscreen keyboard and get the text ( closed with ENTER or such )

Hope somebody can use that.
At all I like codify a lot, hopefully we get something like the above API to make serious open source games for iOS :stuck_out_tongue:

Greets Tapsi

+1 for sleep :slight_smile:

Even the 'ol really-big-for-loop-trick only gets you so far due to:

Lua program has exceeded instruction limit

Can you not just wrap your draw function (plus any watchers etc) in an “if(!paused){}” to handle the pause?

sleep() pauses the execution for a specified number of seconds (or sometimes milliseconds). Lua doesn’t have a built-in sleep, but there are a number of ways to handle it (though all require os.* or io.* or socket.*): http://lua-users.org/wiki/SleepFunction

Hmm - the problem with sleep is that Codify’s main loop is a draw loop, executed every 30th of a second. If you want to pause, you still need to redraw the screen.

Tapsi: awesome API suggestions. Really like them. I think what you have for networking might be a bit low level. I was thinking the network API might automatically bring up a session list, allowing the user to tap another Codea session to join, which would simply return an ID to your code so you can talk to it.

Good persistent storage, not sure if you need delete – just save( key, nil )

I suspect you can simulate sleep-like behaviour using coroutines.

+2 for networking

It would be preferable to be compatible with the existing standard Lua socket library.

A Codea specific higher-level multi-player gaming API could be built on-top (as mentioned by Simeon) for simplicity.

However, only having Codea specific networking would be a severe limitation, compared to general TCP/IP socket access.

I concur on general sockets; We can always build on top of that, but high level protocols may not allow the flexibility we’d need for other things. And - there’s a giant, obvious advantage in being compatable with the existing lua socket libraries…

Okay that sounds like a convincing argument. Perhaps some of what gets built on top of the sockets library can be put back into Codea as the official high level networking API.

@Bortels “Hmm - the problem with sleep is that Codify’s main loop is a draw loop, executed every 30th of a second. If you want to pause, you still need to redraw the screen.”

Not really :slight_smile:

Sleep should literally suspend execution of the process for the given amount of time. What if instead of drawing 30fps I want to only draw 15fps? or 1fps?

@Simeon “I suspect you can simulate sleep-like behaviour using coroutines.”

Somewhere I still need access to a clock so I know how long to suspend. I didn’t see any way to get that info.

@jgjuice: Next version has os.time(), os.clock(), os.date() exposed. Though in the current version you could check against ElapsedTime?

Side Note: The more native APIs you have exposed, the happier I’ll be. I like a high level API, but I like better the ability to “roll my own” if I need to. I can’t imagine Apple would be upset with exposing read-only stuff (like access to time, acceleration, the compass if it’s there, and [he says pushing it] music and photos). I can dream.

Thanks Simeon! I’ll give it a shot :smiley:

+1 For more native APIs, especially compass and location; those would open up some great new possibilities.

I’m a total newbie to the iPad and Lua but Codea is a very interesting concept to me. I would like to try and write an app that gives me distance, bearing, time to go, etc to some specific lat/Lon that is user selectable. Is there any future plans to be able to tap into the iPads current position, altitude, etc? Is it even possible to do with Codea or do I need to look elsewhere? TIA

Carlos

You can get acceleration (gravity and sudden movement) now. The iPad has gps - but it’s not exposed in Codea… Yet. hopefully TLL will add it at some point.

But you hit on an Interesting limitation of the iPad (and IPhone and android and so on) - there is no way to do absolute position. Gps will approximate it, but there’s no way to locate the iPad in space with a high resolution (ie within less than a few meters). And that includes altitude. And I know of no solution for that short of cameras (no access yet) and image processing.

Yes, I saw the accelerometer functions in the reference guide which prompted me to look for gps location type functions. It would be nice to have a high resolution position fix but I would be very happy simply having the gps lat and Lon plus altitude info. BTW, is there a full screen Codea reference available (web page maybe?). I am still trying to wrap my brain to this new environment. Thanks.

Codea, semi-kinda - go to the Codea home page, there’s a link to the Codea-specific docs.

For lua in general, look on the wiki for links to PIL (programming in lua) and the lua reference.

“I was thinking the network API might automatically bring up a session list, allowing the user to tap another Codea session to join, which would simply return an ID to your code so you can talk to it.” Yes. You finally got my point.