Recs.
Updated
SpecsUpdate
Pros
Pro Straightforward and simple
Lua's syntax is very simple and straightforward. Because of this, you can quickly write code without much fuss, and is part of the reason why it's so popular as an embedded scripting language in many video games.
Pro Fast and lightweight
Lua is light and faster than most other scripting languages, especially with LuaJIT, a Lua compiler that can even run code faster than some compiled programming languages in some cases.
Pro Tables
It has tables. Once you use tables, you never go back. You will miss them everywhere else.
Pro Prototype based object oriented programming
Prototype based OOP was designed to be a more clear and easy to understand alternative to class based OOP, the creators of prototypes seeing classes as an unnecessary and complex way of handling classes. As such, it may be an ideal way to introduce a beginner to OOP concepts.
Pro Fast
Lua's performance compares very well to other languages, If performance needs to be further improved you can:
- Implement critical parts in C
- Use the LuaJIT compiler. The LuaJIT compiler is a drop in replacement for the stock compiler and provides significant performance improvements. From the overview page:
LuaJIT speeds can rival code written in C.
Pro Then and end instead of { }
For new users, being able to write out "then" and "end" makes all the difference. If you do this, THEN do this. End.
Pro Portable
Lua can be built on any platform with a ANSI C compiler.
Other than that, Lua is extremely small. For example, the tarball for Lua 5.2.1 is only 245K compressed and 960K uncompressed (including documentation).
When built on Linux, the Lua interpreter built with the standard libraries takes 182K and the Lua library takes 243K.
The small size and the ability to build with a C compiler make Lua an extremely portable language that can run on a lot of different systems and computers.
Pro Very easy to integrate with C and C++
One of the best features of Lua is its very well designed C API. This is very useful if you have an existing C library you need to integrate with Lua or quickly get a Lua script running on the C side of the game.
Finally Lua plays so nice with C that if you need to optimise for speed you can re-write it in C a lot easier than other languages.
Pro Clean and simple syntax suitable for beginners
The Lua syntax is modeled from Modula, a language known for being a fantastic introduction to programming.
The Lua syntax also has the following key characteristics:
- Semicolon as a statement separator is optional (mostly used to resolve ambiguous cases as in a = f; (g).x(a)).
- Syntactic sugar for function calls (f'string', f"string", f[[string]], and f{table}) and method calls (obj:m()).
Pro Prototype-based Inheritance
Lua uses the prototype-based OOP, which is also used by JavaScript, REBOL, and AHK. More generalized OO is used in many newer languages such as Golang, Vlang, Odin, Zip, etc... In many ways prototype-based OOP is easier to use and reason about than class-based OOP, some argue it's even better.
Cons
Con 1-indexed Arrays
Defying conventions from most other programming languages, Lua uses arrays that start at 1, rather than 0. While seemingly beginner friendly, this can complicate some logic, and sets beginners up for confusion when looking at code from other languages.
Con No += operator
Programmers coming from C, C++, Javascript or similar may reach for the += operator, and experience a moment of confusion when it is not available.
Con Undeclared variables are global
When writing a function, if a programmer forgets to declare a variable, that variable will be declared at global scope. The code will seem to run fine at first, but if another function uses a variable with the same name, but fails to declare it, it will create subtle, incredibly difficult to find bugs.
Con Widely used only in game industry as result it is difficult to find first job
Recommendations
Comments
Flagged Pros + Cons
Con Easy to make mistakes when declaring variables
When writing a function, if a programmer forgets to declare a variable, that variable will be declared at global scope. The code will seem to run fine at first, but if another function uses a variable with the same name, but fails to declare it, it will create subtle, incredibly difficult to find bugs.
Con Not very commonly used outside of the Game Industry
Lua is used very often as an extension language for video games, but outside of that niche, it doesn't see much use in industry.
Con Some concepts may not be applied to other "mainstream" programming languages
Lua features a prototye-based inheritance model. While this is also used by Javascript, it's not used by many other mainstream languages, and so some of the concepts learned while learning Lua won't be very applicable to other languages.
Another thing that makes Lua different from other programming languages, is the fact that Arrays start at 1 instead of 0. While helpful for beginners, it can complicate logic and make it very confusing when switching languages.