Cours the design of Lua

Cours the design of Lua, tutoriel & guide de travaux pratiques en pdf.

Why tables
• VDM: maps, sequences, and (finite) sets
• collections
• any one can represent the others
• only maps represent the others with simple and efficient code
Data structures
• tables implement most data structures in a simple and efficient way
• records: syntactical sugar t.x for t[« x »]:
t = {} t.x = 10 t.y = 20 print(t.x, t.y) print(t[« x »], t[« y »])
Data Structures
• arrays: integers as indices
• sets: elements as indices
a = {} for i=1,n do a[i] = 0 end
t = {} t[x] = true — t = t ∪ {x} if t[x] then — x ∈ t? …
Other constructions
• tables also implement modules
• print(math.sin(3))
• tables also implement objects
• with the help of a delegation mechanism and some syntactic sugar
function a:foo (x) … end
a.foo = function (self,x) … end
a:foo(x) a.foo(a,x)
Objects
• first-class functions + tables ≈ objects
• syntactical sugar for methods
• handles self
Delegation
• field-access delegation (instead of method-call delegation)
• when a delegates to b, any field absent in a is got from b
• a[k] becomes (a[k] or b[k])
• allows prototype-based and class-based objects
• allows single inheritance

Cours gratuitTélécharger le cours complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *