Home >> Computers >> Programming >> Languages >> Lua




A Lua (pronouced LOO-ah, or even within IPA) programming language is a lightweight, reflective, imperative and procedural language, designed as a scripting language with extensible semantics as a primary goal. A title is from either a Portuguese word for moon.

Philosophy

Lua is ordinarily described as a "multi-paradigm" language, providing the little placed of general features that may be touch healthy different condition types, like than providing a supplementary complex & rigid specification to match one paradigm. Lua, for example, doesn't contain expressed trend lines for inheritance, but allows it to exist as implemented comparatively easy sustaining pullout. Likewise, Lua allows software engineer to implement namespaces, classes, and more related features applying its only table implementation; first class functions allow the employment of numerous mighty techniques from either functional programming; and to the full lexical scoping allows fine-grained information hiding to enforce the principle of least privilege.

Generally, Luthe strives to provide flexible meta-features that may be extended equally required, like than supply a featureset specific to a single programming paradigm. Following, the base language is light—in fact, a fully information interpreter is simply just about 150KB compiled—and well reaffiliation to a wide range of applications.

History

Lua was created around 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes, members of a Computer Graphics Technology Group at the Pontifical University of Rio de Janeiro in Brazil. Versions of Lua before version Quintet.Nought were freed under the license similar to the BSD license. From either version Quintuplet.Nought forwards, Lua has been licensed under a MIT License.

Lua has been utilized inside numerous commercial applications (e.g., inside LucasArts' Escape from Monkey Island adventure game and robot control software system) too when non-commercial applications (rather Angband and its variants). A bit of of its nearest relatives include Icon for its design & Python for its ease of use by non-programmers.

Features

Lua is arranged for utilize as an extension or scripting language, and is compact plenty to healthy in the kind of persons platforms. It supports just the little total of atomlike information structures like boolean values, numbers (double-precision floating point by default), and strings. Average information structures like arrays, sets, hash tables, lists, and records can be represented using Lua's only native information structure, the table, which is basically a heterogeneous map. Namespaces & objects can besides exist as created utilizing tables. By including simply the minimum of information types, Luthe tries to strike a balance between power & size.

Lua's semantics may be extended & modified by redefining certainherent built-within functions in metatables. What is more, Lua supports advanced features like higher-order functions and garbage collection. By combining numerous of its features, these are imaginable to write object-oriented programs in Lua.

Example code

A classic hello world program can be written as follows:

print "Hello, world!"

A factorial is an example of the recursive function:

work factorial(north) inorth case n == Nought then go to 1 end go to north * factorial(north - One) end

Lua's professional assistance of functions when number one class variables is shown in a as punishment lesson, in which the print work's behavior is modified:

do local oldprint = print print = work (s) whenever s == "foo" so oldprint("bar") else oldprint(s) end end end

Any first calls to "print" might at present become routed through the recently work, & thanks to Lua's lexical scoping, a old print work might just become accessible per newly, limited print.

Extensile semantics occurs as key feature of Lua, & a "metatable" conception allows Lua's tables to become customized around mighty & unique ways. A as a consequence case demonstrates an "infinite" table. For any north, tarradiddle[n] might give a n-th Fibonacci number.

tarradiddle = -- Initial values for taradiddle[1] & taradiddle[2]. setmetatable(tale, )

Internals

Lua computer program are non interpreted directly, but come compiled to bytecode which is then redo on the Lua virtual machine. A compilation do is generally transparent to the user & is performed in the period of run-time, but it may be done offline sequentially to increase performance or even reduce a memory footprint of a hikers environment by allowing retired the compiler.

This case is the bytecode list of the factorial work described above (around Lua Five.Cipher):

work (Ten videos, Xl bytes at 00326DA0) Ace param, Leash stacks, Zero upvalues, Unity local, Terzetto constants, Cypher functions Unity [2] Equivalent 0 0 250 ; compare value to 0 Two [2] JMP 0 Two ; to line 5 Threesome [3] LOADK One One ; 1 Quatern [3] Link to One Two 0 Quintet [6] GETGLOBAL One Two ; fact Sestet [6] SUB Two 0 251 ; - 1 Septenary [6] Call for One Two 2 Ogdoad [6] MUL One 0 1 Ix [6] Link to One Two 0 Ten [7] Go to 0 One 0

Applications

Lua features conspicuously inside numerous games, like Far Cry, a first-person shooter, World of Warcraft, a massively multiplayer online role-playing game, where users come entity to customize its interface, character animation & globe appearance via Lua, & Bioware's Baldur's Gate series and MDK2 video games, where it is used as a module scripting language. It as well appears around a bit of open-source games like Daimonin and the roguelikes ToME and H-World.

Therescript, used to cause a vehicles & animations inside There, is Lua plus a bit of application-specific functions.

A window manager Ion uses Lua for customization and extensibility.

The names of projects known to utilize Lua is placed [http://www.lua.org/uses.html here].

Books

[http://www.inf.puc-rio.br/~roberto/book/ Programming in Lua] [http://www.amazon.com/exec/obidos/tg/detail/-/1584504048/002-9327550-7786415?v=glance/ Game Development with Lua] [http://www.woundedbadger.com/news.html Author Blog]

Lua Reference Manual
Reference Manual of the Lua programming language

Lua FAQ
Frequently Asked Questions about Lua

Lua-an extensible extension language
An overview of Lua.

Lua-users.org
Lua-users Wiki, collaborative site for Lua programmers; Lua-l archive, searchable body of official Lua mailing list; Lua-users.org mini charter.

Yindo
A internet game platform that combines Lua, OpenGL and OpenAL.

Lua Programming Language
Home site; lightweight, made to extend programs, often used for general-purpose, standalone use; simple procedural syntax, powerful data description constructs use associative arrays, extensible semantics; dynamically typed, bytecode interpreted, garbage collected; great for configuration, scripting, rapid prototyping. [Open Source]

LuaSocket
A Lua extension library that provides support for the TCP and UDP transport layers within the Lua language.

Plua
A port of Lua 4.0 (plus a small IDE) for PalmOS handheld devices.

Rozek: Notes about Lua
Andreas Rozek's Kua page. Lua in brief. Lua distributions. Modules and examples. Applications.

Ldb
A debugger for Lua. [Free for pure academic, non profit use]


Computers: Programming: Languages: Garbage Collected
Computers: Programming: Languages: Interpreted: Bytecode
Computers: Programming: Languages: Leda
Computers: Programming: Languages: Multiparadigm
Computers: Programming: Languages: Object-Oriented: Prototype-based
Computers: Programming: Languages: Pliant
Computers: Programming: Languages: Procedural
Computers: Programming: Languages: Reflective




© 2005 GeneralAnswers.org