Why Lua?

I’m a relative newcomer to Corona SDK. Since starting to learn PHP in the early 2000’s, then ActionScript and JavaScript I’ve got used to the ECMA standard programming languages (curly braces, semi colons etc) which gives a head start when learning a new language based on the same standard.

I’m curious to understand why Lua was chosen. Its syntax and structures look pretty old fashioned (they remind me of Director Lingo and even BASIC) and, to my eyes at least, clunky. The only explanation I’ve heard is that it enables Corona to be lightweight and if that’s the main reason and no other lightweight language could be found then fine but I wondered if there is any other reason for the choice?

By the way, I’m enjoying Corona very much - I’m just curious about the choice of Lua. [import]uid: 95579 topic_id: 17245 reply_id: 317245[/import]

Hey, Kevin, here’s a thread that asks the same question:

https://developer.anscamobile.com/forum/2011/09/29/i-cant-understand

Naomi [import]uid: 67217 topic_id: 17245 reply_id: 65124[/import]

lua is easy enough to start making games in a few months with no prior coding experience at all

but whats real reason, i dont know) [import]uid: 16142 topic_id: 17245 reply_id: 65125[/import]

I, as well as Walter have discussed why we chose lua.

The two most important points

1). Adobe Photoshop Architect, Programmer Extraordinaire, Adobe Fellow Mark Hamburg is a big Lua fan. If Lua was good enough for him, well, then…

  1. Lua can fit in 100k or less of footprint. And with our experience running and managing FlashLite we learned that for mobile you have to start fresh. Using any of the scripting languages you mentioned, meant, carrying a lot of luggage which would not have been ideal for devices where every bit of memory is a concern.

You can also look for the interviews online. I go in great detail as well on other points.

C. [import]uid: 24 topic_id: 17245 reply_id: 65130[/import]

Carlos, tell us why not Cobol or RPG, they are so structured and non clunky. They would have made for some real solid good legacy code. We could even be programming mainframe computers with CoronaSDK. Plus we would have no more *noob* questions…

Thank god you guys chose Lua… otherwise I would also not have been a taker if it was Cobol or RPG

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 17245 reply_id: 65150[/import]

Carlos has a podcast that discusses this too, link on his website; http://carlosicaza.com

(PS - nice to see 10 rules for entrepreneurs has been translated!)

[import]uid: 52491 topic_id: 17245 reply_id: 65165[/import]

The sites that have interviews with carlos about this question will answer the “why”, but if you want to feel better about Lua as a choice for Corona in general, Eric Wing has an awesome explanation here:

https://developer.anscamobile.com/forum/2011/09/29/i-cant-understand#comment-58282 [import]uid: 52430 topic_id: 17245 reply_id: 65168[/import]

Technical reasons were already explained, so I’ll just mention:

The nice thing about Lua is that it doesn’t require you to understand large parts of the language to start coding. While the language is certainly not without quirks at the lower levels, a beginner is shielded from these issues until s/he is ready.

As for whether one likes if Lua uses end instead of } etc. it’s mostly subjective. I personally like it; ‘end’ is easier to type fast on a Swedish keyboard where {} are mapped to a low priority inconvenient location, and easier read at small fonts. In C++ I have to use {} all the time… [import]uid: 58849 topic_id: 17245 reply_id: 65410[/import]

I think Lua has a massive advantage that it is a scripting language that runs as fast as C code… but without the syntax hassle of more complex languages. You have a fine balance of power, control and yet simplicity. [import]uid: 33866 topic_id: 17245 reply_id: 65538[/import]

“Runs as fast as C code” is a bit of a misunderstanding. True, Lua is implemented in C but it’s still runs on top of a virtual machine. Even if you rather than using the embedded VM compile the Lua code to C/Java or even native machine code, the fundamental machinery must still be supported. It’s in many cases impossible to determine types of Lua values at compile time, which hinders optimization.

As an example, if I type:
c = a + b
in Lua, it cannot compile to a single add instruction for the native machine in the general case. In the general case types must be checked dynamically and the values’ metatables must be checked for metamethods. It’s even worse if the values are global.

Still, Lua code is higher level than C code so it’s not fair to make a straight comparison, in general you accomplish more per line of Lua code than in C.

So while Lua will never be a particularly good choice to implement demanding signal processing algorithms in, it’s however an awesome language for an event/reaction driven architecture like Corona where the real heavy work is done by the underlying system. :slight_smile: [import]uid: 58849 topic_id: 17245 reply_id: 65634[/import]

why choose Lua?

http://www.lua.org/about.html

[import]uid: 6459 topic_id: 17245 reply_id: 65706[/import]

I think Lua has a massive advantage that it is a scripting language that runs as fast as C code

Only if Ansca would JIT compile it, but they don’t. The big bottle neck in Corona is still LUA … besides the render engine. [import]uid: 5712 topic_id: 17245 reply_id: 65790[/import]

On a side note there are JIT compilers being developed for Lua, though last I checked they weren’t ready for production use yet. So I’m optimistic for the future. [import]uid: 58849 topic_id: 17245 reply_id: 65805[/import]