Lua (programming language)

[5] Lua originated in 1993 as a language for extending software applications to meet the increasing demand for customization at the time.

[7] They had been independently developed at Tecgraf in 1992–1993 to add some flexibility into two different projects (both were interactive graphical programs for engineering applications at Petrobras company).

There was a lack of any flow-control structures in SOL and DEL, and Petrobras felt a growing need to add full programming power to them.

In The Evolution of Lua, the language's authors wrote:[6] In 1993, the only real contender was Tcl, which had been explicitly designed to be embedded into applications.

Lua syntax for control structures was mostly borrowed from Modula (if, while, repeat/until), but also had taken influence from CLU (multiple assignments and multiple returns from function calls, as a simpler alternative to reference parameters or explicit pointers), C++ ("neat idea of allowing a local variable to be declared only where we need it"[6]), SNOBOL and AWK (associative arrays).

[8] Lua semantics have been increasingly influenced by Scheme over time,[6] especially with the introduction of anonymous functions and full lexical scoping.

Lua is commonly described as a "multi-paradigm" language, providing a small set of general features that can be extended to fit different problem types.

In general, Lua strives to provide simple, flexible meta-features that can be extended as needed, rather than supply a feature-set specific to one programming paradigm.

As a result, the base language is light; the full reference interpreter is only about 247 kB compiled[4] and easily adaptable to a broad range of applications.

Lua implements a small set of advanced features such as first-class functions, garbage collection, closures, proper tail calls, coercion (automatic conversion between string and number values at run time), coroutines (cooperative multitasking) and dynamic module loading.

A comment in Lua starts with a double-hyphen and runs to the end of the line, similar to Ada, Eiffel, Haskell, SQL and VHDL.

The factorial function is implemented in this example: Lua has one type of conditional test: if then end with optional else and elseif then execution control constructs.

[13] Extensible semantics is a key feature of Lua, and the metatable concept allows powerful customization of tables.

Inheritance (both single and multiple) can be implemented with metatables, delegating nonexistent methods and fields to a parent object.

[3][4] Like most CPUs, and unlike most virtual machines (which are stack-based), the Lua VM is register-based, and therefore more closely resembles most hardware design.

[18] This example is the bytecode listing of the factorial function defined above (as shown by the luac 5.1 compiler):[19] Lua is intended to be embedded into other applications, and provides a C API for this purpose.

Advanced functions are provided by the auxiliary library, which consists largely of preprocessor macros which assist with complex table operations.

Extension modules are shared objects which can be used to extend the functions of the interpreter by providing native facilities to Lua scripts.

A growing set of modules termed rocks are available through a package management system named LuaRocks,[23] in the spirit of CPAN, RubyGems and Python eggs.

In video game development, Lua is widely used as a scripting language, mainly due to its perceived easiness to embed, fast execution, and short learning curve.

[25] Notable games which use Lua include Roblox,[26] Garry's Mod, World of Warcraft, Payday 2, Phantasy Star Online 2, Dota 2, Crysis,[27] and many others.

Some games that do not natively support Lua programming or scripting, have this function added by mods, as ComputerCraft does for Minecraft.

[29] On 12 January 2012, Lua was announced as a winner of the Front Line Award 2011 from the magazine Game Developer in the category Programming Tools.

[30] Many non-game applications also use Lua for extensibility, such as LuaTeX, an implementation of the TeX type-setting language, Redis, a key-value database, ScyllaDB, a wide-column store, Neovim, a text editor, Nginx, a web server, Wireshark, a network packet analyzer and Pure Data, a visual audio programming language (through the pdlua extension).

Through the Scribunto extension, Lua is available as a server-side scripting language in the MediaWiki software that runs Wikipedia and other wikis.