Lua, the Programming Language

Have you noticed the moon is a bit like a parenthesis?

Things of amazing beauty were invented by humans: first it was Lisp, then it was Forth, and then it was Lua - if there were other good languages, please let me know

Language Year of Release Keywords
Lisp 1960 defun, cons, car, cdr, lambda, eval, cond
Forth 1970 :, dup, drop, pick, roll
Smalltalk 1972 new, yourself, super
Scheme 1975 define, call/cc, set!, define-syntax
Common Lisp 1984 defun, defmacro, defparameter, defclass, defpackage, loop
Python 1991 def, class, nonlocal, async, yield, import
Lua 1993 function, local
Table 1. Various languages.

The good thing about being a 1993 language is that you can be influenced by every other language that was released before that date. In Lua, I personally sense a great influence of every language mentioned in Table 1, and I like these influences

conf: __index, __add, __le, __mode -- __init__, __str__, __add__

conf: _G -- globals()

They say there's a man in the moon - if you look closely enough into moon's surface, you will see a face. In case of Lua, the face you see in the moon is of Roberto Ierusalimski [Wikipedia]. When I say this, I always want to add "it's the same guy who made D" but D was made by Andrei Aleksandresku [Wikipedia], an entirely different person1

1 No wonder I keep getting them confused, their last names both end with /sk[ui]$/

One thing that comes to mind first when thinking about Lua is that it begins indexing its arrays (aka tables) with 1 as opposed to 0, the starting index of choice of 99% other programming languages. Both are nice choices, one is more intuitive when thinking about high-level problems, the other is more intuitive when dealing with things like memory or anything with an "offset". A truly bad choice would be using -1 or 2 as base index

The reason behind this is that Lua was indeed designed to be used by non-programmers, who needed a very simple language to automate their daily computations. It's a small niche, and we don't usually target it anymore when developing software. We kind of collectively assume that programming is the job of a programmer, and now that we have a lot of programmers, why would you code instead of them?

Another instance of this is that every assignment to a free variable introduces a global binding, visible across all modules. If you're a novice programmer, this is a win for you because you don't have to wonder why your variable suddenly became nil, and if you're an experienced developer, you probably care about lexical scoping and should by default make every variable you use with local. You also need to be careful not to assign to undeclared variables, but your IDE

Metatables are the continuation of theme "we're giving you one multi-purpose tool instead of many single-purpose utilities" that table has begun. Metatables are your meta-programming tool, and with meta-programming you may achieve object oriented programming (OOP) and other good stuff. Lua doesn't have macros, but metatables make it possible to introduce custom syntax to a degree. Personally I recommend against going for the urge of rolling out Your Own Object System because it's not a natural style for Lua: whatever you need an object system for (inheritance, overriding behavior, polymorphism), there are other, more straightforward ways to implement these. Lua isn't very like Smalltalk, it's almost trying to be the opposite of Smalltalk while pursuing similar goals in its design