Penguin
Annotated edit history of Lua version 7, including all changes. View license author blame.
Rev Author # Line
6 AristotlePagaltzis 1 [Lua | http://www.lua.org] is a lightweight ProgrammingLanguage designed for extending applications, but also frequently used as a stand-alone language. It is implemented as a small library of [ANSI] [C] functions that compiles unmodified on all known platforms. The [API] that allows an application to exchange data with [Lua] programs and also to extend Lua with [C] functions. In this sense, [Lua] can be regarded as a language framework for building domain-specific languages. [Lua] programs are compiled to ByteCode. [Lua]'s implementation goals are simplicity, efficiency, portability, and low embedding cost. The result is a fast language engine with small footprint, making it ideal in embedded systems too. It is FreeSoftware, designed and implemented by a team at Tecgraf, the Computer Graphics Technology Group of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro in Brazil). Tecgraf is a laboratory of theDepartment of ComputerScience.
2
3 The language combines simple procedural syntax with powerful data description constructs based on associative arrays, is dynamically typed, and has automatic memory management with GarbageCollection, making it ideal for configuration, scripting, and rapid prototyping. A fundamental concept in the design of [Lua] is to provide meta-mechanisms for implementing features, instead of providing a host of features directly in the language. For example, although [Lua] does not contain ObjectOrientation, it does provide mechanisms for implementing classes and inheritance. This philosophy brings an economy of concepts and keeps the language small, while allowing unconventional extensions to its semantics.
4
7 AristotlePagaltzis 5 It is used as a scripting language for game engines by Lucas Soft, MicrosoftCorporation, etc (watch the conference at http://ll3.ai.mit.edu/).
6 AristotlePagaltzis 6
7 See also:
8 * [The Lua-Users wiki | http://lua-users.org/wiki]
9 * <tt>#lua</tt> on the [FreeNode] [IRC] network
10
11 ----
12
13 !! Sample [Lua] program
14
15 SourceCode::
16 <verbatim>
17 -- simple program that reads a config file in the format "a = b" and
18 -- prints them to the output as "a is b"
19
20 function fileexists( file )
21 local f = io.open( file, "r" )
22 if f then
23 io.close( f )
24 return true
25 else
26 return false
27 end
28 end
29
30 function loadconfig( file )
31 print( "+ reading config file " .. file )
32 if fileexists( file ) then
33 local cline = 1
34 for line in io.lines( file ) do
35 if string.sub( line, 0, 2 ) ~= "--" and line ~= "" then
36 local _,_,var, val = string.find( line, "(%S+)%s?=%s?(.*)" ) ;
37 if var == nil or val == nil then
38 print( "! malformed line on line " .. cline .. ", ignoring" )
39 else
40 print( var .. " is ".. val )
41 end
42 end
43 cline = cline + 1
44 end
45 else
46 print( "! " .. file .. " does not exist !" )
47 print( "! exiting.." )
48 os.exit()
49 end
50 end
51
52 loadconfig( "blah.conf" )
53 </verbatim>
54
55 Output::
56 <verbatim>
57 $ lua blah.lua
58 + reading config file blah.conf
59 a is b
60 var is val
61 ! malformed line on line 3, ignoring
62 nick is scope
63 </verbatim>
64
65 ----
66 CategoryProgrammingLanguages