Python vs Lua

i noticed that almost all game engine use “LUA” (90%)

only panda3d and BGE use python afaik , what is the difference and what you think is better?

as “style” seem pretty similar

This depends what you mean with “better”.

It is simply a different language.

The style may be similar, but the design concepts between Python and Lua are very very different.
Python’s syntax and libraries are richer and much more powerful, Lua is more minimalist.
Python has a lot of facilities to ‘assimilate’ external C code, making it feel as if it were written in Python in the first place. Lua wraps external C code more directly.

Lua appeals to programmers with a ‘C/C++ first’ attitude. They embed Lua in their engine, allowing ‘scripters’ to dynamically configure C objects using a simple API. Lua is light, easily embedded, easily sandboxed and easily compiled at runtime (LuaJIT).

Python appeals to programmers with a ‘Python first’ attitude. They want to create an API for people like themselves, giving the same power as the complete C API. They don’t embed Python, they wrap their C/C++ engine as a Python library. Even better, they wrap it as multiple libraries, so that people can mix and match different libraries for rendering, physics, etc. If you don’t want to give this kind of power to ‘scripters’, don’t use Python (Lua was the correct choice for WoW). Python is not easily compiled at runtime: Python philosophy is to find the 1% of your code where 99% of the time is spent, and write a C library for that 1%.

Short answer: Lua is for game engines that treat their scripters as kids. Python is for game engines that treat their scripters as programmers.

Short answer 2: Lua would have been a horrible choice for bpy, Python is infinitely superior there. Lua would have been a better choice than Python for the BGE in 2001, it follows the same philosophy about embedded scripting. I feel that this philosophy does not belong in the modern age, but that is obviously just my opinion.

While I know that a large percentage uses Lua, I don’t know if it’s as much as 90%; Panda3D uses Python, JMonkeyEngine 3 uses Javascript, Unity uses several languages (one of which is similar to Python, I believe), etc., etc.

I personally prefer Python, as Lua is very, very minimalist, as Sjoerd mentioned. There’s no class structure built into Lua, which can make things difficult to trouble-shoot to me. Many things are seen as a table, which is an interesting idea that I’d like to investigate, but I could never really get “into” Lua. I’d like to try it at some point, though.

@Monster :
originally my “better” was :
supposing to make a game of medium difficulty(FPS playable)
and you know both language , how many time take to do it with python and with Lua .

the one that require less time is the better :wink:
but reading the reply seem that depend much from the game engine that run Lua , not Lua directly…

@Sjoerd :
thanks for this good reply ,
now is a bit more clear something (as why i need to write “import bge” ? ie : what should be ? import photoshop? :))
yeah , because this is more a python that read bge , not the inverse (as i have thinked instead)

so with Lua basically you have to hope that all kind of problem here already covered form some premade tool, right? instead with python solve a problem is more easy.

@SolarLune :
yes the percentage was just for the game engine
the curiosity is coming from this extra-large number of engines that use Lua .

anyway to me like a lot python,seem strange that another language can be better :slight_smile:

Both are high level languages. So there is no real difference. If they are supposed to be used as scripting language they should not be used for low level development anyway.

How much time you need depends on the developers skills and the design of the custom code.

BTW: because a system is used a lot does not necessarily means it is the best. It is just used a lot - nothing less nothing more.

Even very good systems died because they weren’t used and bad systems survived instead.

I disagree with that. Many programmers believe (and it has been backed up by research) that their productivity is much higher when they use high-level languages. Scientific computing is mostly low-level development. Most scientists I know would gladly spend their time coding in Python instead of C and Fortran. The reason why high-level languages are not used for low-level development is that it is extremely hard to compile them to fast machine code. There are a lot of projects that aim for this: Cython, PyPy, Numba, Theano, Nuitka, Shedskin, RPythonic, …

I would consider Lua, PHP and JavaScript as embedded scripting languages with their own niches (games and web browsers/servers), and Python and Ruby as general-purpose high-level languages. I have yet to see the first Lua web framework, the first JavaScript library for scientific computing, or the first PHP game engine API.

You’re welcome, but remember that it is just my view, others may disagree :slight_smile:
For Python, it is easy to solve things yourself and there is a high chance that there is an existing tool also.
With Lua, you have to hope that your solution is possible with the Lua API that the game engine devs allow.
Lua is a really good scripting language. It is used a lot for MMORPGs to customize the UI. You don’t want to use Python there, far too easy to write a bot!

Though, once you can establish a communication protocol between one language and another, you’ve simply got to rely on developer imposed API restrictions!

I did not want to express low level programming needs low level languages. The current compilers are very good with this.

I wanted to express high level programming (as required for game specific behavior) benefits from high level languages, even if they might be a bit slower (e.g. when using interpreted or semi-interpreted languages). If they really need the performance of native code, it would be better to have them in a lower level (by compilation) and just call them from high level (e.g. from an interpreted script).