Lua vs Python

Hi all

I have been having a great time learning lua and making random little games!

I came across another app similar to Codea that I won’t name, but it uses Python as the language. I am curious which language would be the most useful to learn? If my goal is making games and possibly utility apps for iOS, which language would be the most useful?

I’m really liking Lua but it seems like it’s mainly focused on making games, and making utility apps would be a challenge in Lua?

Any of you used both Lua and Python and can give some pros and cons for each language?

Codea definitely seems more polished than this other unnamed app.

@Crumble You can name the app. Other apps have been named in the past and I feel that anyone who’s here is because they like Codea and the support they get. It’s hard to give you an answer without being able to try that app. I don’t think making utility apps would be that hard. What kind of utility do you have in mind.

The app is Pythonista.

Just random non game apps, like a calculator, or a stopwatch, etc. Those are some of the demos that come with Pythonista. Seems like Python is more of a general use language, where as Lua is more focused on games?

Making a calculator would be extreamly easy. I’m sure there are several that have been made already.

One thing for sure is Lua reads more like English. Where as Python is hard to figure out what is doing what.

What about if you were trying to make a more in depth utility App like Pinterest or Instagram?

I guess I’m just trying to figure out the main differences between the languages. And the pros and cons.

The big difference is:
codea ++ for games and real time display (shaders).
pythonista ++ for huge available libraries, portability to pc and data apps.
@Briarfox plays on both sides, he could advise you.

I’ve used both Lua and Python professionally. Lua has gained traction as a easy to learn, lightweight,fast, general purpose scripting language for embedding within more complex software such as games engines. The small size of it interpreter and execution speed makes it ideal for developers to write scripts to configure and add extra functionality to existing software and its easy to see why TLL used it as its core scripting language within Codea.

Python whilst similar, is in my opinion a bit harder to pick up than Lua and has a more pedantic syntax (e.g. Indenting code is part of its syntactic structure and has a number of ‘gotchas’ to the uninitiated!). However, it has a rich set of programming constructs ‘out of the box’ that supports a wide range of software development paradigms (OOP, Functional, Procedural etc) and an extensive 3rd party set of modules/libraries which makes it incredibly powerful, especially for rapidly developing tools and utility software over more complex languages such as C/C++.

I would argue that Lua’s lightweight interpreter will outperform Python in terms of speed of execution, which makes it more suitable for games development and other application where performance is an issue.

I think in terms of penetration in the software development industry I’d say Python wins hands down over Lua in terms of popularity, power and of course - jobs! However, I do think Lua has carved a fantastic niche as an embedded scripting language - especially within the games industry.

For me - I love Python, but will always have a huge soft spot for Lua due to its simplicity and ease of use. :smiley:

Don’t confuse “python vs lua” with “Pythonista vs Codea”. Codea is more than lua and it may be that the attributes you’re assigning to lua (“it seems like it’s mainly focused on making games”) are really about Codea.

I’ve been using my experience with lua in Codea to write some simple lua scripts on my main computer that are about as far from “making games” as you can get - basically, some hard core mathematics.

Lua has some really neat features that make it a delight to program. I’ve very little experience with python, but as yet haven’t found a significant limitation with lua (or Codea) that has meant I’ve wanted to go looking for a different language.

I usually like to compare thing based on quality and features then opinion. I don’t have experience with Python (Lua is my first language and I mainly use it, I do have some basic C++ skills too.) However, from my perspective they are both the same thing. A tool used to communicate with a computer, but each has own unique traits. From what I have researched, Python seems to be the swift army knife of program languages. It is used in anything from games to Artificial Inteligence. I would definitely agree with @andymac3d that Python is superior to Lua in terms of demand in the job place. However Lua is designed to be embedded into C languages and is used in things that require visual effects. It is also very fast. One of the fastest out there. In conclusion on which I feel is better. The answer is it depends on what you are trying to do. If you are making a game or something with lots visual effects stick with Lua. If you want to make something that is used to lets say control a toy car wirelessly I’d go with Python. But I would encourage anyone who wants to to learn something new. If you don’t know Python and want to learn it. I say go for it.

But then again, the thing you are trying to make aren’t necessarily out of Codea’s or Lua’s capabilities. I’ve made a stop watch, kinda (it just counted up from zero) and I’m sure there are others who have made calculators with Codea

@Crumble Here’s a quick calculator I put together just to give you an example, so it’s still has bugs. Try calculations like

x * y =
x / y =
x + y =
x - y =
x ^ y =
x sin
x cos


displayMode(FULLSCREEN)
rectMode(CENTER)

function setup()
    b1tab={}
    table.insert(b1tab,button(100,600,100,50,"1"))
    table.insert(b1tab,button(200,600,100,50,"2"))
    table.insert(b1tab,button(300,600,100,50,"3"))
    table.insert(b1tab,button(100,550,100,50,"4"))
    table.insert(b1tab,button(200,550,100,50,"5"))
    table.insert(b1tab,button(300,550,100,50,"6")) 
    table.insert(b1tab,button(100,500,100,50,"7"))
    table.insert(b1tab,button(200,500,100,50,"8"))
    table.insert(b1tab,button(300,500,100,50,"9"))
    table.insert(b1tab,button(200,450,100,50,"0"))
    table.insert(b1tab,button(100,450,100,50,"*"))
    table.insert(b1tab,button(300,450,100,50,"+"))
    table.insert(b1tab,button(100,400,100,50,"/"))
    table.insert(b1tab,button(200,400,100,50,"^"))
    table.insert(b1tab,button(300,400,100,50,"-"))
    table.insert(b1tab,button(300,350,100,50,"="))
    table.insert(b1tab,button(100,350,100,50,"sin"))
    table.insert(b1tab,button(200,350,100,50,"cos"))
    str=""
    t1,t2=0,0
end

function draw() 
    background(40, 40, 50)
    for a,b in pairs(b1tab) do
        b:draw()
    end
    fill(255)
    rect(200,650,300,50)
    fill(255,0,0)
    text(str,200,650)
end

function touched(t)
    if t.state==BEGAN then
        if done then
            done=false
            str=""
            t1=0
            t2=0
        end
        for a,b in pairs(b1tab) do
            b:touched(t)
        end
    end
end                

button=class()

function button:init(x,y,w,h,desc)
    self.x=x
    self.y=y
    self.w=w
    self.h=h
    self.d=desc
end

function button:draw()
    fill(255)
    rect(self.x,self.y,self.w,self.h)
    fill(255,0,0)
    text(self.d,self.x,self.y)
end

function button:touched(t)
    if t.x>self.x-self.w/2 and t.x<self.x+self.w/2 then
        if t.y>self.y-self.h/2 and t.y<self.y+self.h/2 then
            if self.d=="sin" then
                str=math.sin(math.rad(t2))
                done=true
                return
            end
            if self.d=="cos" then
                str=math.cos(math.rad(t2))
                done=true
                return
            end
            if self.d=="*" or self.d=="^" or self.d=="/" or 
                        self.d=="+" or self.d=="-" then
                m=self.d
                t1=t2
                t2=""
                str=str..self.d
                return                  
            end
            if self.d== "=" then
                if m=="*" then
                    str=t1*t2
                end
                if m== "^" then
                    str=t1^t2
                end
                if m== "/" then
                    str=t1/t2
                end
                if m== "+" then
                    str=t1+t2
                end
                if m== "-" then
                    str=t1-t2
                end
                done=true
                return
            end
            if self.d>="0" and self.d<="9" then
                str=str..self.d
                t2=t2..self.d
            end
        end
    end
end

Both Lua and Python can be used successfully in a wide range of applications. Python is certainly currently viewed as more of a general tool. However, a lot it is coincidental, in my opinion. Python is very easy to pick up and start writing little programs in. It has beautiful and powerful support for lists and list operations built in. As a first language to learn - Python is one of the best.

The fact that Lua is so popular as a scripting language in game engines, somewhat masks the fact that it is actually a very well-designed general purpose programming language. It has several advanced features that you wouldn’t find in other modern languages. Just to give two examples: lexical scoping and coroutines. Anyone who have ever had to deal with Javascript functions and “this” - would welcome Lua functions and closures as a breath of fresh air. Coroutines make life easy for UI-type tasks and animations, but they also make Lua well-suited for writing high-performance server-side networking applications (as an alternative paradigm to callback-style made popular by NodeJS).

Also, if you ever have to write an extension for Lua in C, you will appreciate the elegance of Lua/C programmng interface and its focus on performance. In my view, Python loses out here, as its C-API is not as clean, although this is more of personal preference than hard facts.

I love lua and I love python.
Lua within Codea is great for games because of the libraries that Codea provides. Lua without Codea becomes more difficult to use. Lua is much smaller and lighter then python and works great on embedded systems. lua is also very fast.

Python has a very large amount of libraries. When you need to do something there is a library for that. No need to reinvent the wheel. From my understanding python is also heavily used in the science community. I can write a python module on my ipad and run it on my PC/Mac.

For developing games on the ipad I would say lua/Codea is a clear winner. Simeon and TLL have done an excelent job with that. However for utilities and projects that require specific libraries, python would be a great choice.

I do most of my coding over SSH with vim now in python.

I’ve seen the advice many times that serious programmers should learn multiple languages. From my own experience, learning new languages does broaden your knowledge and experience.

More importantly, each language has its strengths and weaknesses. For example, I would never code a serious business app in Codea (unless it was a graphic animation). You can do it, yes, but Codea has no UI, and limited connectivity, so if you want a normal business app, I would use Excel or Python. For serious data analysis, I would use R. And so on. They are designed for specific kinds of work, which not only makes development and maintenance easier, but when you move on, it is easier to find someone else to support the apps.

I still think Codea is the most fun I have ever had programming, but it’s not the best tool for every job.

Bottom line is that if you want to be a programmer (and not just graphics), then I think you definitely should learn Python. And more. But others are better placed than me to advise on specific languages.