Ok, ok… When I started with Lua I hated it. I've come from a C# & Python background so (In my opinion) have used the two best 'learning' languages. Python for its simplicity and flexibility, C# just being awesome (I'm writing Java at the moment and it makes me realise how much the .Net team got right).
However, I've come to almost love Lua, I'll go though these points one by one:
So yeah, I've been doing some metatables lately and felt like ranting a bit.
__index: What the actual f, lua devs? A bloody function which name indicates that it is run every time a field in table is indexed, but no no no! That would be too easy to use, wouldn't it? So instead of doing a normal index handler let's do one that is called whenever indexed field is nonexistent! Great idea! So instead of doing
Well, the trouble with Lua tables is that they aren't designed for how this type of (ab)use. __index is wonderful. Most of the time I use it to inherit environments (
setmetatable({}, {__index = getfenv()})) or classes. I almost never use it to track access to a key.
Almost every other language uses a similar principal. Python has __getattr__, PHP has __get, I'm sure many other languages have a similar thing.
local: Oh yes, local variables. This keyword shouldn't exist. Because there should be no need for it's existence! Every goddamn variable should be local by default! And if You need global variable (what happens never very rarely with proper design) you cloud use for example a "global" keyword, uh?
Yep, agree with that. Sometimes it is useful because you can see when you define variables, however the first thing I check with any program is if it uses locals or not.
String concatenation. When I first used Lua, I tried to do this:
"Hello " + "World"
But no, that's too complex for such a lightweight language. We have to do this:
"Hello " .. "World"
In any normal language I would agree, but some languages (Lua, VB, I'm sure there are others - maybe ActionScript and PHP) have type conversion things. This is the trouble:
"1" + "1" -- 2
But I wanted 11! These are strings, but we get a number out of it? Explicitly defining addition or concatenation is really the only solution.
Anyway, it isn't as bad as some languages:
Spoiler
I'm going to suggest reading these
two articles by the co-creator of StackOverflow. The general point is 'Language design is
hard'. Despite Lua's many odd things, I do quite like it now.
Anyway! It is more fun writing massively complicated programs in a slightly obscure language then it is in one that actually works!
Sorry for the long post.