Lua programming language

This article is about the Lua Programming Language. For other usages, see Lua.
Missing image
Lua_programing_language_logo.gif
Lua's logo

The Lua (pronouced LOO-ah, or in IPA) programming language is a lightweight imperative and procedural language, designed as a scripting language with extensible semantics as a primary goal. The name is derived from the Portuguese word for moon.

Contents

History

Lua was created in 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes, members of the Computer Graphics Technology Group at the Pontifical University of Rio de Janeiro in Brazil. Versions of Lua prior to version 5.0 were released under a license similar to the BSD license. From version 5.0 onwards, Lua has been licensed under the MIT License.

Lua has been used in many commercial applications (e.g., in LucasArts' Escape from Monkey Island adventure game and robot control software) as well as non-commercial applications (like Angband and its variants). Some of its closest relatives include Icon for its design and Python for its ease of use by non-programmers.

Features

Lua is intended for use as an extension or scripting language, and is compact enough to fit on a variety of host platforms. It supports only a small number of atomic data structures such as boolean values, numbers (double-precision floating point by default), and strings. Typical data structures such as arrays, sets, hash tables, lists, and records can be represented using Lua's single native data structure, the table, which is essentially a heterogeneous map. Namespaces and objects can also be created using tables. By including only a minimum of data types, Lua attempts to strike a balance between power and size.

Lua's semantics can be extended and modified by redefining certain built-in functions in metatables. Furthermore, Lua supports advanced features such as higher-order functions and garbage collection. By combining many of its features, it is possible to write object-oriented programs in Lua.

Example code

The classic hello world program can be written as such:

print "Hello, world!"

The factorial is an example of a recursive function:

function factorial(n)
    if n == 0 then
        return 1
    end
    
    return n * factorial(n - 1)
end

Internals

Lua programs are not interpreted directly, but are compiled to bytecode which is then run on the Lua virtual machine. The compilation process is typically transparent to the user and is performed during run-time, but it can be done offline in order to increase performance or reduce the memory footprint of the host environment by leaving out the compiler.

This example is the bytecode listing of the factorial function described above (in Lua 5.0):

function <factorial.lua:1> (10 instructions, 40 bytes at 00326DA0)
1 param, 3 stacks, 0 upvalues, 1 local, 3 constants, 0 functions
    1   [2] EQ          0 0 250 ; compare value to 0
    2   [2] JMP         0 2     ; to line 5
    3   [3] LOADK       1 1     ; 1
    4   [3] RETURN      1 2 0
    5   [6] GETGLOBAL   1 2     ; fact
    6   [6] SUB         2 0 251 ; - 1
    7   [6] CALL        1 2 2
    8   [6] MUL         1 0 1
    9   [6] RETURN      1 2 0
    10  [7] RETURN      0 1 0

Applications

Lua features prominently in many games, such as World of Warcraft, a massively multiplayer online role-playing game, where users are able to customize its user interface, character animation and world appearance via Lua, and Bioware's Neverwinter Nights PC role-playing game, where it is used as a module scripting language. It also appears in some open-source games such as Daimonin and the roguelikes ToME and H-World.

Therescript, used to drive the vehicles and animations in There, is a slightly modified version of Lua.

The window manager Ion uses Lua for customization and extensibility.

The list of the reported lua users can be found here (http://www.lua.org/uses.html)

External links

ko:루아 프로그래밍 언어 pl:Lua pt:Lua (linguagem de programao) ru:Lua

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools