33
\$\begingroup\$

As above really,

I'm writing an android based game in my spare time (android because it's free and I've no real aspirations to do anything commercial).

The game logic comes from a very typical component based model whereby entities exist and have components attached to them and messages are sent to and fro in order to make things happen.

Obviously the layer for actually performing that is thin, and if I were to write an iPhone version of this app, I'd have to re-write the renderer and core driver (of this component based system) in Objective C.

The entities are just flat files determining the names of the components to be added, and the components themselves are simple, single-purpose objects containing the logic for the entity.

Now, if I write all the logic for those components in Java, then I'd have to re-write them on Objective C if I decided to do an iPhone port. As the bulk of the application logic is contained within these components, they would, in an ideal world, be written in some platform-agnostic language/script/DSL which could then just be loaded into the app on whatever platform.

I've been led to believe however that this is not an ideal world though, and that Lua performance etc on mobile devices still isn't up to scratch, that the overhead is too much and that I'd run into troubles later if I went down that route?

Is this actually the case? Obviously this is just a hypothetical question, I'm happy writing them all in Java as it's simple and easy get things off the ground, but say I actually enjoy making this game (unlikely, given how much I'm currently disliking having to deal with all those different mobile devices) and I wanted to make a commercially viable game - would I use Lua or would I just take the hit when it came to porting and just re-write all the code?

\$\endgroup\$

6 Answers 6

17
\$\begingroup\$

As far as scripting languages go, Lua is very fast, but like anything it varies depending on the processor. For example, Lua would not be great on a console platform because it tends to be very branchy, and some console platforms branch very slowly. To best answer your question, I would suggest running some benchmarks. See how fast Lua performs some various algorithms on the device. I suspect you'd be fine as long as you're not doing any heavy math or iteration in your script code. (You shouldn't be doing that anyway. They're scripts. Do calculations in the engine.)

That said, scripting isn't a silver bullet for platform independence. You may need to rewrite in Obj-C anyway if you port to iPhone due to Apple's restrictions on executing dynamic code. I don't have a link offhand, but it may be worth reading into. Apple barely allows managed code (you have to get special permission to run a special distribution). They most certainly will not allow a Lua implementation into the app store.

[edit] Apparently I was mistaken about the Lua on iphone thing. Take a look at the comments below.

\$\endgroup\$
6
  • 9
    \$\begingroup\$ Lua is widely used in iPhone applications, and changes were made to the terms that allow it. See here: appleoutsider.com/2010/06/10/hello-lua \$\endgroup\$ Jul 15, 2010 at 14:35
  • 5
    \$\begingroup\$ Many console apps actually use LUA. Yes, it's branchy - but that doesn't matter if you control high-level logic. Just don't call it from your render loop ;) As far as I know, LUA for games is fine with the recent changes to the developer agreement - there are plenty of games that are driven by LUA. But as with any development on a closed platform, ask the platform owner (i.e. Apple) for definitive answers. Also, no need for Obj-C - the iPhone allows C/C++ just fine. (I recommend you do anything UIKit in Obj-C, though. Reduced pain factor) \$\endgroup\$ Jul 19, 2010 at 20:24
  • 7
    \$\begingroup\$ Go go magic soap box. Lua is a noun not an acronym, you would never write JAVA. Lua means moon. You would not write MOON. thanks - the Lau Nazi. \$\endgroup\$
    – deft_code
    Aug 20, 2010 at 8:29
  • 2
    \$\begingroup\$ Sadly I know plenty of people that write "JAVA". \$\endgroup\$
    – user744
    Mar 18, 2011 at 9:39
  • 1
    \$\begingroup\$ I did use lua heavily on NDS (that is far less powerful than an IPhone) and it worked quite fast. Fast enough for us to make more than half the logic of one game directly in lua. \$\endgroup\$
    – Klaim
    Apr 28, 2011 at 14:06
7
\$\begingroup\$

Lua's C implementation is specifically designed to run on embedded devices. It's small and fast (for a scripting language). I would have thought it was fine for at least light tasks.

\$\endgroup\$
4
\$\begingroup\$

Sure. Scripting logic is highly unlikely to be your bottleneck (you will actually profile with Shark or Instruments, right?). I worked on the iPhone version of Marooned, which used a lot of Lua for game logic. I did a lot of performance tuning, and basically Lua was 0%.

(Lua was a grey area when we released Marooned, but it’s since been officially blessed for iOS development.)

\$\endgroup\$
1
\$\begingroup\$

See http://code.google.com/p/android-scripting/ for the recommended way of doing scripting on Android. Lua still doesn't fit very well on the Android platform, since it requires C. Of course, you could use the NDK, but that is no silver bullet.

\$\endgroup\$
1
\$\begingroup\$

It does depend a bit how much of your game logic is embedded in scripts. In general LUA is used as high level glue but a lot of the grunt work happens through C(++). Yes, LUA is fast as far as scripting languages go - your still looking at a slowdown compared to native languages of about 30 to 50 times, so it really depends how much is happening in LUA.

\$\endgroup\$
0
\$\begingroup\$

You can actually write your entire game in Lua and avoid Java/ObjectiveC/C/C++ altogether.

For cross platform development use Corona. Its free to use until you plan to ship to the App Store or Android Marketplace.

If you want to target the iPhone/Pad/Touch take a look at wax.

Just as a side note @Sean Edwards: I've been involved in shipping five titles targeting Nintendo DS, Wii, Sony PSP, and Xbox360, all of which used the same engine and were scripted in Lua. Its widely used on consoles and mobiles.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .