Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
Get started with
Lua programming


Etiene Dalcol
@etiene_d
@etiene_dTopConf Tallinn 2015
@etiene_d
@etiene_dTopConf Tallinn 2015
Sailor!
An MVC web framework in Lua

sailorproject.org
@etiene_dTopConf Tallinn 2015
Lua Ladies

A female Lua user group

lualadies.org
@etiene_dTopConf Tallinn 2015
Google Summer of Code
LabLua
@etiene_dTopConf Tallinn 2015
What’s Lua
Why Lua
Key Concepts
Going further
@etiene_dTopConf Tallinn 2015
@etiene_dTopConf Tallinn 2015
• Script Language
• Duck-typed
• Multi-paradigm
• procedural, OO, functional
• Garbage colle...
@etiene_dTopConf Tallinn 2015
Why Lua?
Powerful.
@etiene_dTopConf Tallinn 2015
Why Lua?
Size
(docs included)
First-class functions

+
Lexical scoping
+
Metatables
Native C...
@etiene_dTopConf Tallinn 2015
Simple.Powerful.
Why Lua?
@etiene_dTopConf Tallinn 2015
_G
_VERSION
assert
collectgarbage
dofile
error
getmetatable
ipairs
load
loadfile
next
pairs
...
@etiene_dTopConf Tallinn 2015
TopConf Tallinn 2015 @etiene_d
"Since Lua itself is so
simple, it tends to
encourage you to solve
problems simply."
Ragnar...
@etiene_dTopConf Tallinn 2015
Fast.Simple.Powerful.
Why Lua?
@etiene_dTopConf Tallinn 2015
http://www.humbedooh.com/presentations/ACNA%20-%20mod_lua.odp Introducing mod_lua by Daniel ...
@etiene_dTopConf Tallinn 2015
My Reasons
• It looks cool
(I heard you could make games with it)
Better
@etiene_dTopConf Tallinn 2015
Better Reasons
• It looks cool
(I heard you could make games with it)
• It’s made in my home...
@etiene_dTopConf Tallinn 2015
• It looks cool
(I heard you could make games with it)
• It’s made in my home country
(In my...
@etiene_dTopConf Tallinn 2015
• The index starts at 1
• There’s no continue
• The non-equality operator is ~=
• null is ni...
@etiene_dTopConf Tallinn 2015
@etiene_dTopConf Tallinn 2015
• The index starts at 1
• There’s no continue
• The non-equality operator is ~=
• null is ni...
@etiene_dTopConf Tallinn 2015
Quick idioms
• a, b = b, a
• There’s no ternary operator but you can 

return x==1 and “yes”...
@etiene_dTopConf Tallinn 2015
Using Lua: three approaches
Embedded Scripting General-purpose
@etiene_dTopConf Tallinn 2015
Getting Lua
• lua.org > download
• OS package manager
• apt-get install lua
• brew install l...
@etiene_dTopConf Tallinn 2015
Key Concepts
@etiene_dTopConf Tallinn 2015


• The only way to structure data
• Array, dictionary, object, list, queue, module…
• Any v...
@etiene_dTopConf Tallinn 2015
Tables
Header
key value
“x” 9.2
nil
value
100
200
300
nil
@etiene_dTopConf Tallinn 2015


• The only way to structure data
• Array, dictionary, object, list, queue, module…
• Any v...
@etiene_dTopConf Tallinn 2015
Tables
local a = { 1, 3, 5, 7, 9}
local sum = 0
for i=1,#a do
sum = sum + a[i]
end
print(sum...
@etiene_dTopConf Tallinn 2015
local a = { 1, 3, 5, 7, 9}
local sum = 0
for i=1,#a do
sum = sum + a[i]
end
print(sum) -- 25...
@etiene_dTopConf Tallinn 2015
local a = { 1, 3, 5, 7, 9}
local sum = 0
for i=1,#a do
sum = sum + a[i]
end
print(sum) -- 25...
@etiene_dTopConf Tallinn 2015
local a = { 1, 3, 5, 7, 9}
local sum = 0
for i=1,#a do
sum = sum + a[i]
end
print(sum) -- 25...
@etiene_dTopConf Tallinn 2015
-- Cipher module
--[[ Based on algorithms/caesar_cipher.lua
by Roland Yonaba ]]
local cipher...
@etiene_dTopConf Tallinn 2015
-- Cipher module
--[[ Based on algorithms/caesar_cipher.lua
by Roland Yonaba ]]
local cipher...
@etiene_dTopConf Tallinn 2015
-- Cipher module
--[[ Based on algorithms/caesar_cipher.lua
by Roland Yonaba ]]
local cipher...
@etiene_dTopConf Tallinn 2015
-- Cipher module
--[[ Based on algorithms/caesar_cipher.lua
by Roland Yonaba ]]
local cipher...
@etiene_dTopConf Tallinn 2015
-- Cipher module
--[[ Based on algorithms/caesar_cipher.lua
by Roland Yonaba ]]
local cipher...
@etiene_dTopConf Tallinn 2015


• Overload operators
• Override built-in functions such as tostring
• Treat missing fields...
@etiene_dTopConf Tallinn 2015
local mt = {}
local function new(r, i)
return setmetatable({ real = r or 0, im = i or 0}, mt...
@etiene_dTopConf Tallinn 2015
local mt = {}
local function new(r, i)
return setmetatable({ real = r or 0, im = i or 0}, mt...
@etiene_dTopConf Tallinn 2015
local mt = {}
local function new(r, i)
return setmetatable({ real = r or 0, im = i or 0}, mt...
@etiene_dTopConf Tallinn 2015
local mt = {}
local function new(r, i)
return setmetatable({ real = r or 0, im = i or 0}, mt...
@etiene_dTopConf Tallinn 2015
local mt = {}
local function new(r, i)
return setmetatable({ real = r or 0, im = i or 0}, mt...
@etiene_dTopConf Tallinn 2015
local mt = {}
local function new(r, i)
return setmetatable({ real = r or 0, im = i or 0}, mt...
@etiene_dTopConf Tallinn 2015
local square = { x = 10, y = 20, side = 25 }
function square.move(obj, dx, dy)
obj.x = obj.x...
@etiene_dTopConf Tallinn 2015
local square = { x = 10, y = 20, side = 25 }
function square.move(obj, dx, dy)
obj.x = obj.x...
@etiene_dTopConf Tallinn 2015
local square = { x = 10, y = 20, side = 25 }
function square.move(obj, dx, dy)
obj.x = obj.x...
@etiene_dTopConf Tallinn 2015
local square = { x = 10, y = 20, side = 25 }
function square.move(obj, dx, dy)
obj.x = obj.x...
@etiene_dTopConf Tallinn 2015
local square = { x = 10, y = 20, side = 25 }
function square.move(obj, dx, dy)
obj.x = obj.x...
@etiene_dTopConf Tallinn 2015
local square = { x = 10, y = 20, side = 25 }
function square.move(obj, dx, dy)
obj.x = obj.x...
@etiene_dTopConf Tallinn 2015
local Square = {}
function Square:new(x, y, side)
local o = { x = x, y = y, side = side}
set...
@etiene_dTopConf Tallinn 2015
local Square = {}
function Square:new(x, y, side)
local o = { x = x, y = y, side = side}
set...
@etiene_dTopConf Tallinn 2015
local Square = {}
function Square:new(x, y, side)
local o = { x = x, y = y, side = side}
set...
@etiene_dTopConf Tallinn 2015
local Square = {}
function Square:new(x, y, side)
local o = { x = x, y = y, side = side}
set...
@etiene_dTopConf Tallinn 2015
local Square = {}
function Square:new(x, y, side)
local o = { x = x, y = y, side = side}
set...
@etiene_dTopConf Tallinn 2015
Going further
@etiene_dTopConf Tallinn 2015
• Books
• Programming in Lua: http://www.lua.org/pil/
• Lua Programming Gems: http://www.lua...
@etiene_dTopConf Tallinn 2015


• Hardware
• eLua: http://www.eluaproject.net/
• nodemcu: http://nodemcu.com

• Math and s...
@etiene_dTopConf Tallinn 2015


• Game development
• Love2D: https://love2d.org/
• Defold: http://www.defold.com/
• Cocos2...
@etiene_dTopConf Tallinn 2015
• IDE
• ZeroBrane Studio: http://studio.zerobrane.com/

• Testing
• Busted: http://olivinela...
Thank you!
etiene.net

github.com/Etiene/
dalcol@etiene.net
@etiene_d
Próxima SlideShare
Cargando en…5
×

Get started with Lua programming

1.288 visualizaciones

Publicado el

Talk given during TopConf Tallinn on 19th November 2015, Estonia

Publicado en: Software
  • Programming in Lua, Second Edition --- http://amzn.to/1SaSFbk
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí
  • Lua Programming --- http://amzn.to/25cMpah
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí
  • Programming in Lua --- http://amzn.to/1Mv1ok6
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí

Get started with Lua programming

  1. 1. Get started with Lua programming 
 Etiene Dalcol @etiene_d
  2. 2. @etiene_dTopConf Tallinn 2015 @etiene_d
  3. 3. @etiene_dTopConf Tallinn 2015 Sailor! An MVC web framework in Lua
 sailorproject.org
  4. 4. @etiene_dTopConf Tallinn 2015 Lua Ladies
 A female Lua user group
 lualadies.org
  5. 5. @etiene_dTopConf Tallinn 2015 Google Summer of Code LabLua
  6. 6. @etiene_dTopConf Tallinn 2015 What’s Lua Why Lua Key Concepts Going further
  7. 7. @etiene_dTopConf Tallinn 2015
  8. 8. @etiene_dTopConf Tallinn 2015 • Script Language • Duck-typed • Multi-paradigm • procedural, OO, functional • Garbage collection • Coroutines • First-class functions • Lexical scoping • Proper tail calls • MIT License What is Lua?
  9. 9. @etiene_dTopConf Tallinn 2015 Why Lua? Powerful.
  10. 10. @etiene_dTopConf Tallinn 2015 Why Lua? Size (docs included) First-class functions
 + Lexical scoping + Metatables Native C API 276 Kb Object Orientation Ada, Fortran, Java, Smalltalk, C#, Perl, Ruby etc. +
  11. 11. @etiene_dTopConf Tallinn 2015 Simple.Powerful. Why Lua?
  12. 12. @etiene_dTopConf Tallinn 2015 _G _VERSION assert collectgarbage dofile error getmetatable ipairs load loadfile next pairs pcall print rawequal rawget rawlen rawset require select setmetatable tonumber tostring type xpcall bit32.arshift bit32.band bit32.bnot bit32.bor bit32.btest bit32.bxor bit32.extract bit32.lrotate bit32.lshift bit32.replace bit32.rrotate bit32.rshift coroutine.create coroutine.resume coroutine.running coroutine.status coroutine.wrap coroutine.yield debug.debug debug.getuservalue debug.gethook debug.getinfo debug.getlocal debug.getmetatable debug.getregistry debug.getupvalue debug.setuservalue debug.sethook debug.setlocal debug.setmetatable debug.setupvalue debug.traceback debug.upvalueid debug.upvaluejoin io.close io.flush io.input io.lines io.open io.output io.popen io.read io.stderr io.stdin io.stdout io.tmpfile io.type io.write file:close file:flush file:lines file:read file:seek file:setvbuf file:write math.abs math.acos math.asin math.atan math.atan2 math.ceil math.cos math.cosh math.deg math.exp math.floor math.fmod math.frexp math.huge math.ldexp math.log math.max math.min math.modf math.pi math.pow math.rad math.random math.randomseed math.sin math.sinh math.sqrt math.tan math.tanh os.clock os.date os.difftime os.execute os.exit os.getenv os.remove os.rename os.setlocale os.time os.tmpname package package.config package.cpath package.loaded package.loadlib package.path package.preload package.searchers package.searchpath string.byte string.char string.dump string.find string.format string.gmatch string.gsub string.len string.lower string.match string.rep string.reverse string.sub string.upper table.concat table.insert table.pack table.remove table.sort table.unpack
  13. 13. @etiene_dTopConf Tallinn 2015
  14. 14. TopConf Tallinn 2015 @etiene_d "Since Lua itself is so simple, it tends to encourage you to solve problems simply." Ragnar Svensson - Lead Developer at King (Lua Workshop Oct 15 2015)
  15. 15. @etiene_dTopConf Tallinn 2015 Fast.Simple.Powerful. Why Lua?
  16. 16. @etiene_dTopConf Tallinn 2015 http://www.humbedooh.com/presentations/ACNA%20-%20mod_lua.odp Introducing mod_lua by Daniel Gruno
  17. 17. @etiene_dTopConf Tallinn 2015 My Reasons • It looks cool (I heard you could make games with it) Better
  18. 18. @etiene_dTopConf Tallinn 2015 Better Reasons • It looks cool (I heard you could make games with it) • It’s made in my home country (In my university to be more precise)
  19. 19. @etiene_dTopConf Tallinn 2015 • It looks cool (I heard you could make games with it) • It’s made in my home country (In my university to be more precise) • It’s easy to learn Better Reasons
  20. 20. @etiene_dTopConf Tallinn 2015 • The index starts at 1 • There’s no continue • The non-equality operator is ~= • null is nil • Comments are - - • Only nil and false are equivalent to false • Functions can genuinely return multiple values • Variables are global by default • Pattern matching is not regular expression • The concatenation operator is .. What’s different
  21. 21. @etiene_dTopConf Tallinn 2015
  22. 22. @etiene_dTopConf Tallinn 2015 • The index starts at 1 • There’s no continue • The non-equality operator is ~= • null is nil • Comments are - - • Only nil and false are equivalent to false • Functions can genuinely return multiple values • Variables are global by default • Pattern matching is not regular expression • The concatenation operator is .. What’s different
  23. 23. @etiene_dTopConf Tallinn 2015 Quick idioms • a, b = b, a • There’s no ternary operator but you can 
 return x==1 and “yes” or “no” • The access to local variables is faster than global local match = string.match
  24. 24. @etiene_dTopConf Tallinn 2015 Using Lua: three approaches Embedded Scripting General-purpose
  25. 25. @etiene_dTopConf Tallinn 2015 Getting Lua • lua.org > download • OS package manager • apt-get install lua • brew install lua LuaRocks • luarocks.org > install • OS package manager • apt-get install luarocks
  26. 26. @etiene_dTopConf Tallinn 2015 Key Concepts
  27. 27. @etiene_dTopConf Tallinn 2015 
 • The only way to structure data • Array, dictionary, object, list, queue, module… • Any value can be a key, except nil and nan • Behind the scenes: array or hash table • Passed as reference • The length operator: # • pairs(t) x ipairs(t) Tables
  28. 28. @etiene_dTopConf Tallinn 2015 Tables Header key value “x” 9.2 nil value 100 200 300 nil
  29. 29. @etiene_dTopConf Tallinn 2015 
 • The only way to structure data • Array, dictionary, object, list, queue, module… • Any value can be a key, except nil • Behind the scenes: array or hash table • Passed as reference • The length operator: # • pairs(t) x ipairs(t) Tables
  30. 30. @etiene_dTopConf Tallinn 2015 Tables local a = { 1, 3, 5, 7, 9} local sum = 0 for i=1,#a do sum = sum + a[i] end print(sum) -- 25
  31. 31. @etiene_dTopConf Tallinn 2015 local a = { 1, 3, 5, 7, 9} local sum = 0 for i=1,#a do sum = sum + a[i] end print(sum) -- 25 Tables local a = {} a[1] = 1 a[2] = 3 -- etc local sum = 0 for _, x in ipairs(a) do sum = sum + x end print(sum)
  32. 32. @etiene_dTopConf Tallinn 2015 local a = { 1, 3, 5, 7, 9} local sum = 0 for i=1,#a do sum = sum + a[i] end print(sum) -- 25 local a, x = 10, “y” local point = { x = a, y = 25} print(point[“x”], point[“y”]) -- 10 25 print(point[x], point[y]) -- 25 nil print(point.x, point.y) -- 10 25 Tables
  33. 33. @etiene_dTopConf Tallinn 2015 local a = { 1, 3, 5, 7, 9} local sum = 0 for i=1,#a do sum = sum + a[i] end print(sum) -- 25 local a, x = 10, “y” local point = { x = a, y = 25} print(point[“x”], point[“y”]) -- 10 25 print(point[x], point[y]) -- 25 nil print(point.x, point.y) -- 10 25 -- sets and multisets local ips = { “5.101.112.0” = true, “213.35.128.0” = true } local connections = { “5.101.112.0” = 5, “213.35.128.0” = 2 } Tables
  34. 34. @etiene_dTopConf Tallinn 2015 -- Cipher module --[[ Based on algorithms/caesar_cipher.lua by Roland Yonaba ]] local cipher = {} local function ascii_base(s) return s:lower() == s and ('a'):byte() or ('A'):byte() end function cipher.caesar( str, key ) return str:gsub('%a', function(s) local base = ascii_base(s) return string.char(((s:byte() - base + key) % 26) + base) end) end return cipher Modules
  35. 35. @etiene_dTopConf Tallinn 2015 -- Cipher module --[[ Based on algorithms/caesar_cipher.lua by Roland Yonaba ]] local cipher = {} local function ascii_base(s) return s:lower() == s and ('a'):byte() or ('A'):byte() end function cipher.caesar( str, key ) return str:gsub('%a', function(s) local base = ascii_base(s) return string.char(((s:byte() - base + key) % 26) + base) end) end return cipher Modules
  36. 36. @etiene_dTopConf Tallinn 2015 -- Cipher module --[[ Based on algorithms/caesar_cipher.lua by Roland Yonaba ]] local cipher = {} local function ascii_base(s) return s:lower() == s and ('a'):byte() or ('A'):byte() end function cipher.caesar( str, key ) --cipher.caesar = function(str,key) return str:gsub('%a', function(s) local base = ascii_base(s) return string.char(((s:byte() - base + key) % 26) + base) end) end return cipher Modules public
  37. 37. @etiene_dTopConf Tallinn 2015 -- Cipher module --[[ Based on algorithms/caesar_cipher.lua by Roland Yonaba ]] local cipher = {} local function ascii_base(s) return s:lower() == s and ('a'):byte() or ('A'):byte() end function cipher.caesar( str, key ) return str:gsub('%a', function(s) local base = ascii_base(s) return string.char(((s:byte() - base + key) % 26) + base) end) end return cipher Modules private
  38. 38. @etiene_dTopConf Tallinn 2015 -- Cipher module --[[ Based on algorithms/caesar_cipher.lua by Roland Yonaba ]] local cipher = {} local function ascii_base(s) return s:lower() == s and ('a'):byte() or ('A'):byte() end function cipher.caesar( str, key ) return str:gsub('%a', function(s) local base = ascii_base(s) return string.char(((s:byte() - base + key) % 26) + base) end) end return cipher Modules local cipher = require “cipher” print(cipher.caesar(“test”,3) -- whvw
  39. 39. @etiene_dTopConf Tallinn 2015 
 • Overload operators • Override built-in functions such as tostring • Treat missing fields or intercept new field creation • Call table as a function • Metamethods:
 __add, __sub, __mul, __div, __mod, __pow, __unm, __concat, __len, __eq, __lt, __le, __index, __newindex, __call, __tostring, __ipairs, __pairs, __gc Metatables
  40. 40. @etiene_dTopConf Tallinn 2015 local mt = {} local function new(r, i) return setmetatable({ real = r or 0, im = i or 0}, mt) end local function is_complex(v) return getmetatable(v) == mt end local function add(c1, c2) if not is_complex(c1) then return new(c2.real + c1, c2.im) elseif not is_complex(c2) then return new(c1.real + c2, c1.im) end return new(c1.real + c2.real, c1.im + c2.im) end local function tos(c) return tostring(c.real) .. "+".. tostring(c.im) .. "i" end mt.__add = add mt.__tostring = tos Complex numbers
  41. 41. @etiene_dTopConf Tallinn 2015 local mt = {} local function new(r, i) return setmetatable({ real = r or 0, im = i or 0}, mt) end local function is_complex(v) return getmetatable(v) == mt end local function add(c1, c2) if not is_complex(c1) then return new(c2.real + c1, c2.im) elseif not is_complex(c2) then return new(c1.real + c2, c1.im) end return new(c1.real + c2.real, c1.im + c2.im) end local function tos(c) return tostring(c.real) .. "+".. tostring(c.im) .. "i" end mt.__add = add mt.__tostring = tos Complex numbers
  42. 42. @etiene_dTopConf Tallinn 2015 local mt = {} local function new(r, i) return setmetatable({ real = r or 0, im = i or 0}, mt) end local function is_complex(v) return getmetatable(v) == mt end local function add(c1, c2) if not is_complex(c1) then return new(c2.real + c1, c2.im) elseif not is_complex(c2) then return new(c1.real + c2, c1.im) end return new(c1.real + c2.real, c1.im + c2.im) end local function tos(c) return tostring(c.real) .. "+".. tostring(c.im) .. "i" end mt.__add = add mt.__tostring = tos Complex numbers
  43. 43. @etiene_dTopConf Tallinn 2015 local mt = {} local function new(r, i) return setmetatable({ real = r or 0, im = i or 0}, mt) end local function is_complex(v) return getmetatable(v) == mt end local function add(c1, c2) if not is_complex(c1) then return new(c2.real + c1, c2.im) elseif not is_complex(c2) then return new(c1.real + c2, c1.im) end return new(c1.real + c2.real, c1.im + c2.im) end local function tos(c) return tostring(c.real) .. "+".. tostring(c.im) .. "i" end mt.__add = add mt.__tostring = tos Complex numbers
  44. 44. @etiene_dTopConf Tallinn 2015 local mt = {} local function new(r, i) return setmetatable({ real = r or 0, im = i or 0}, mt) end local function is_complex(v) return getmetatable(v) == mt end local function add(c1, c2) if not is_complex(c1) then return new(c2.real + c1, c2.im) elseif not is_complex(c2) then return new(c1.real + c2, c1.im) end return new(c1.real + c2.real, c1.im + c2.im) end local function tos(c) return tostring(c.real) .. "+".. tostring(c.im) .. "i" end mt.__add = add mt.__tostring = tos Complex numbers
  45. 45. @etiene_dTopConf Tallinn 2015 local mt = {} local function new(r, i) return setmetatable({ real = r or 0, im = i or 0}, mt) end local function is_complex(v) return getmetatable(v) == mt end local function add(c1, c2) if not is_complex(c1) then return new(c2.real + c1, c2.im) elseif not is_complex(c2) then return new(c1.real + c2, c1.im) end return new(c1.real + c2.real, c1.im + c2.im) end local function tos(c) return tostring(c.real) .. "+".. tostring(c.im) .. "i" end mt.__add = add mt.__tostring = tos >local c1 = new(2,3)
 >print( c1 + 5 )
 7+3i Complex numbers
  46. 46. @etiene_dTopConf Tallinn 2015 local square = { x = 10, y = 20, side = 25 } function square.move(obj, dx, dy) obj.x = obj.x + dx obj.y = obj.y + dy end function square:area() return self.side ^ 2 end print(square:area()) -- 625 Objects
  47. 47. @etiene_dTopConf Tallinn 2015 local square = { x = 10, y = 20, side = 25 } function square.move(obj, dx, dy) obj.x = obj.x + dx obj.y = obj.y + dy end function square:area() return self.side ^ 2 end print(square:area()) -- 625 Objects
  48. 48. @etiene_dTopConf Tallinn 2015 local square = { x = 10, y = 20, side = 25 } function square.move(obj, dx, dy) obj.x = obj.x + dx obj.y = obj.y + dy end function square:area() return self.side ^ 2 end print(square:area()) -- 625 Objects
  49. 49. @etiene_dTopConf Tallinn 2015 local square = { x = 10, y = 20, side = 25 } function square.move(obj, dx, dy) obj.x = obj.x + dx obj.y = obj.y + dy end function square:area() return self.side ^ 2 end print(square:area()) -- 625 Objects
  50. 50. @etiene_dTopConf Tallinn 2015 local square = { x = 10, y = 20, side = 25 } function square.move(obj, dx, dy) obj.x = obj.x + dx obj.y = obj.y + dy end function square:area() return self.side ^ 2 end print(square:area()) -- 625 local square2 = (x = 30, y = 5, side = 10} print(square.area(square2)) -- 100 Objects
  51. 51. @etiene_dTopConf Tallinn 2015 local square = { x = 10, y = 20, side = 25 } function square.move(obj, dx, dy) obj.x = obj.x + dx obj.y = obj.y + dy end function square:area() return self.side ^ 2 end print(square:area()) -- 625 local square2 = (x = 30, y = 5, side = 10} print(square.area(square2)) -- 100 Objects
  52. 52. @etiene_dTopConf Tallinn 2015 local Square = {} function Square:new(x, y, side) local o = { x = x, y = y, side = side} setmetatable(o, self) self.__index = self return o end function Square:move(dx, dy) self.x = self.x + dx self.y = self.y + dy end function Square:area() return self.side ^ 2 end return Square Object Orientation
  53. 53. @etiene_dTopConf Tallinn 2015 local Square = {} function Square:new(x, y, side) local o = { x = x, y = y, side = side} setmetatable(o, self) self.__index = self return o end function Square:move(dx, dy) self.x = self.x + dx self.y = self.y + dy end function Square:area() return self.side ^ 2 end return Square Object Orientation
  54. 54. @etiene_dTopConf Tallinn 2015 local Square = {} function Square:new(x, y, side) local o = { x = x, y = y, side = side} setmetatable(o, self) self.__index = self return o end function Square:move(dx, dy) self.x = self.x + dx self.y = self.y + dy end function Square:area() return self.side ^ 2 end return Square Object Orientation
  55. 55. @etiene_dTopConf Tallinn 2015 local Square = {} function Square:new(x, y, side) local o = { x = x, y = y, side = side} setmetatable(o, self) self.__index = self return o end function Square:move(dx, dy) self.x = self.x + dx self.y = self.y + dy end function Square:area() return self.side ^ 2 end return Square Object Orientation
  56. 56. @etiene_dTopConf Tallinn 2015 local Square = {} function Square:new(x, y, side) local o = { x = x, y = y, side = side} setmetatable(o, self) self.__index = self return o end function Square:move(dx, dy) self.x = self.x + dx self.y = self.y + dy end function Square:area() return self.side ^ 2 end return Square local Square = require “square” local s1 = Square:new(10,20,25) local s2 = Square:new(30,5,10) print(s1:area()) -- 625 print(s2:area()) -- 100 Object Orientation
  57. 57. @etiene_dTopConf Tallinn 2015 Going further
  58. 58. @etiene_dTopConf Tallinn 2015 • Books • Programming in Lua: http://www.lua.org/pil/ • Lua Programming Gems: http://www.lua.org/gems/ • Tutorials • Lua Style Guide: 
 http://lua-users.org/wiki/LuaStyleGuide • Lua Missions: https://github.com/kikito/lua_missions
 • Misc • CodeCombat: https://codecombat.com • Community • Lua mail list: http://www.lua.org/lua-l.html Resources
  59. 59. @etiene_dTopConf Tallinn 2015 
 • Hardware • eLua: http://www.eluaproject.net/ • nodemcu: http://nodemcu.com
 • Math and scientific computing • SciLua http://www.scilua.org/ • Torch: http://torch.ch • GSL Shell: http://www.nongnu.org/gsl-shell/ Cool tools in Lua
  60. 60. @etiene_dTopConf Tallinn 2015 
 • Game development • Love2D: https://love2d.org/ • Defold: http://www.defold.com/ • Cocos2d: http://www.cocos2d-x.org/ • Corona: https://coronalabs.com
 • Web development • OpenResty http://openresty.org • Lapis: http://leafo.net/lapis/ • Luvit: https://luvit.io/ • Sailor: http://sailorproject.org/ • Moonshine: http://moonshinejs.org/ Cool tools in Lua
  61. 61. @etiene_dTopConf Tallinn 2015 • IDE • ZeroBrane Studio: http://studio.zerobrane.com/
 • Testing • Busted: http://olivinelabs.com/busted/ • Package management • LuaRocks http://luarocks.org
 • Misc • Moonscript: http://moonscript.org/ • Awesome Lua:
 https://github.com/LewisJEllis/awesome-lua Cool tools in Lua
  62. 62. Thank you! etiene.net
 github.com/Etiene/ dalcol@etiene.net @etiene_d

×