Programming_in Lua_2nd_Edition.pdf
PropertyoflanBloss
ProgramminginLua
Secondedition
Robertolerusalimsch
PUC-Rio.brazil
ua.org
Riodejaneiro
PropertyoflanBloss
ProgramminginLua.SecondEdition
byRobertolerusalimschy
ISBN85903798-2-5
Copyright2006,2003byRobertoIerusalimschy.Allrightsreserved.
Theauthorcanbecontactedatrobertooluaorg
BookcoverandillustrationsbyDimaquina.lualogodesignbyAlexandreNako
TypesettingbytheauthorusingATEX
Althoughtheauthorusedhisbesteffortspreparingthisbook,heassumesno
responsibilityforerrorsoromissions,orforanydamagethatmayresultfrom
theuseoftheinformationpresentedhere.Allproductnamesmentionedinthis
bookaretrademarksoftheirrespectiveowners
CIP-BibliotecadoDepartamentodeInformatica,PUC-Rio
ferusalimschy,Roberto
I22
ProgramminginLua/Robertolerusalimschy.-2nded
Riodejaneiro.2006
xvi,308p.:25cm.
Includesindex
SBN85-9037982-5
1.Lua(Programminglanguage).I.Title
005.133-dc20
PropertyoflanBloss
toIdanoemiandAnalucia
PropertyoflanBloss
PropertyoflanBloss
Contents
Prefacexiii
TheLanguage
1GettingStarted3
1.1Chunks4
1.2SomeLexicalConventions5
1.3Globalvariables6
1.4TheStand-AloneInterpreter7
2Typesandvalues9
2.1Nil10
2.2Booleans10
2.3Numbers10
2.4Strings11
2.5Tables13
2.6Functions17
2.7UserdataandThreads17
3Expressions19
3.1ArithmeticOperators19
3.2RelationalOperators20
3.3LogicalOperators21
3.4Concatenation22
3.5Precedence22
3.6Tableconstructors22
PropertyoflanBloss
Conte
4Statements27
4.1Assignment27
4.2Localvariablesandblocks28
4.3Controlstructures30
4.4breakandreturn34
5
unctions35
5.1MultipleResults36
5.2VariableNumberofArguments39
5.3NamedArguments42
6MoreAboutFunctions45
6.1Closures47
6.2Non-GlobalFunctions50
6.3ProperTailcalls52
7Iteratorsandthegenericfor55
7.1Iteratorsandclosures55
7.2TheSemanticsofthegenericfor57
7.3Statelessiterators58
7.4IteratorswithComplexState60
7.5TrueIterators61
8Compilation,Execution,andErrors63
8.1Compilation63
8.2CCode67
8.3Errors67
8.4ErrorHandlingandExceptions69
8.5ErrorMessagesandtracebacks70
9Coroutines73
9.1Coroutinebasics73
9.2Pipesandfilters76
9.3Coroutinesasiterators79
9.4Non-PreemptiveMultithreading81
10CompleteExamples87
10.1DataDescription87
10.2MarkovChainAlgorithm91
ITablesandobjects95
11Datastructures97
11.1Arrays97
PropertyoflanBloss
11.2Matricesandmulti-DimensionalArrays98
11.3LinkedLists100
11.4Queuesanddoublequeues100
11.5SetsandBags10
11.6StringBuffers103
11.7Graphs104
12DataFilesandPersistence107
12.1DataFiles107
12.2Serialization109
13Metatablesandmetamethods117
13.1ArithmeticMetamethods118
13.2RelationalMetamethods120
13.3Library-DefinedMetamethods122
13.4Table-Accessmetamethods122
14TheEnvironment129
14.1GlobalVariableswithDynamicNames129
14.2Global-VariableDeclarations131
14.3Non-GlobalEnvironments132
15Modulesandpackages137
15.1TherequireFunction138
15.2TheBasicapproachforWritingmodules141
15.3UsingEnvironments143
15.4ThemoduleFunction144
15.5Submodulesandpackages145
16object-OrientedProgramming149
16.1Classes151
16.2Inheritance152
16.3MultipleInheritance154
16.4Privacy156
16.5TheSingle-MethodApproach158
17WeakTables161
17.1MemoizeFunctions163
17.2ObjectAttributes164
17.3Revisitingtableswithdefaultvalues165
lThestandardlibraries167
18TheMathematicalLibrary169
PropertyoflanBloss
下载地址
用户评论