SlideShare una empresa de Scribd logo
1 de 35
Descargar para leer sin conexión
Lua: the world’s most infuriating language
October 17, 2013
The simplest way to a safer, faster and smarter website
My background
•  Lots of...
•  Assembly
•  C, C++ and Go
•  Perl, Tcl
•  LISP (and relations)

•  And lately...
•  Lua

2
My first Lua program

3
4
The End

5
CHDK on Canon A560

6
CHDK Lua Interface
•  Lua’s extensibility means it can control the camera
•  http://chdk.wikia.com/wiki/Lua
•  Functions added to Lua like
•  shoot() – takes a picture
•  press(), release() – press the shutter button (allows a partial press)
•  get_orientation_sensor() – figure out camera orientation
•  get_temperature() – get camera internal temperatures

7
-- Now enter a self-check of the manual mode settings
log( "Self-check started" )
assert_prop( 49, -32764, "Not in manual mode" )
assert_prop( 5,
0, "AF Assist Beam should be Off" )
assert_prop( 6,
0, "Focus Mode should be Normal" )
assert_prop( 8,
0, "AiAF Mode should be On" )
assert_prop( 21,
0, "Auto Rotate should be Off" )
assert_prop( 29,
0, "Bracket Mode should be None" )
assert_prop( 57,
0, "Picture Mode should be Superfine" )
assert_prop( 66,
0, "Date Stamp should be Off" )
assert_prop( 95,
0, "Digital Zoom should be None" )
assert_prop( 102,
0, "Drive Mode should be Single" )
assert_prop( 133,
0, "Manual Focus Mode should be Off" )
assert_prop( 143,
2, "Flash Mode should be Off" )
assert_prop( 149,
100, "ISO Mode should be 100" )
assert_prop( 218,
0, "Picture Size should be L" )
assert_prop( 268,
0, "White Balance Mode should be Auto" )
assert_gt( get_time("Y"), 2009, "Unexpected year" )
assert_gt( get_time("h"), 6, "Hour appears too early" )
assert_lt( get_time("h"), 20, "Hour appears too late" )
assert_gt( get_vbatt(), 3000, "Batteries seem low" )
assert_gt( get_jpg_count(), ns, "Insufficient card space" )
log( "Self-check complete" )

8
https://github.com/jgrahamc/gaga/tree/master/gaga-1/camera
if ( ok == 1 ) then
sleep(s)
log( "Starting picture capture" )
n = 0
while ( 1 ) do
tc = c
while ( tc > 0 ) do
shoot()
n = n + 1
log( string.format("Picture %i taken", n ))
tc = tc - 1
end
log( string.format("Temperatures: %i, %i, %i",
get_temperature(0), get_temperature(1), get_temperature(2) ))
log( string.format("Battery level %i", get_vbatt()))
sleep(i)
end
end
log( "Done" )
9
Initial Irritants
•  Seemed awfully verbose (bit like BASIC!)
•  if... then... else... end

•  Little shortcuts were missing
•  x += 1
•  p?a:b

•  Made it feel like a toy language

10
Irritant: +=
•  Happy not to have x++
•  But why no +=?

11
Irritant: ternary operator
•  Super useful to be able to do

local bird = duck?”It’s a duck”:”Not a duck”
•  Can’t.
•  Solution is the ugly

local bird = duck and “It’s a duck” or “Not a duck”
•  And it’s a bad solution

local thing = question and returnsfalse() or crash()

12
Irritant: not and ~=
•  Not equals is ~=
•  Which Perl programmers will confuse with =~

if x ~= 5 then print “Not five” end

•  But not is not ~ it’s not!

if not x == 5 then print “Not five” end
if ~(x == 5) then print “Not five” end
if not (x == 5) then print “Not five” end

13
Next Lua Program
•  Web Application Firewall
•  About 2,000 lines of Lua
•  Replaced 37,000 line C program!
•  Plus 3,000 of automatically generated Lua

•  Used by CloudFlare to process HTTP requests
•  Checks for XSS, CSRF, SQL injection
•  Bad browsers
•  Custom rules

•  Turns out Lua was great for this!
14
Really, really fast: 1 to 2ms per request

15
LuaJIT

16
LuaJIT FFI

17
Lulip
•  Line level profiler for Lua in Lua: https://github.com/jgrahamc/lulip/

local profiler = require 'lulip'
local p = profiler:new()
p:dont('some-module')
p:maxrows(25)
p:start()
-- execute code here
p:stop()
p:dump(output_file_name)

18
Lulip Output

19
Lulip Core
•  Nice things
•  Lua’s debug library
•  LuaJIT’s FFI for gettimeofday()
•  Closures

-- start: begin profiling
function start(self)
self:dont('lulip.lua')
self.start_time = gettimeofday()
self.current_line = nil
self.current_start = 0
debug.sethook(function(e,l) self:event(e, l) end, "l")
end
20
Performance Tricks
•  Wait til you’ve finished; Measure; Fix the slow things
•  Locals way faster than globals

local rand = math.random
local len = #t
for i=1,len do
...
end
•  . syntax faster than :

local slen = string.len
s:len() vs. slen(s)
•  Minimize closures

21
Autogenerated Code

22
nginx + Lua and OpenResty
•  http://wiki.nginx.org/HttpLuaModule
•  Control over all phases of nginx inside Lua
•  Very fast, very flexible, non-blocking (without callbacks!)
•  Sockets, coroutines, subrequests, shared in-memory caching
•  http://openresty.org/
•  Complete package of nginx, Lua and a set of libraries
•  Access to Redis, memcached, MySQL, Postgresql
•  JSON parsing, DNS, locks, ...

•  CloudFlare HTTP almost entirely nginx + Lua / OpenResty

23
CloudFlare WAF

24
Irritant: Arrays
•  Index starts at 1
•  # doesn’t do what you think

>
>
3
>
>
4
>
>
2

x = {"a", "b", "c"}
=#x
x = {"a", "b", nil, "c"}
=#x
x = {"a", "b", nil, "c", nil}
=#x

25
Irritant: escape characters
•  string.find, string.match
•  Lots of special characters just like regular expressions
•  Character classes: [a-z], [^a-z], .
•  Repetition: *, +, ?
•  Anchors: ^ and $
•  Groups and alternation: (foo|bar)

•  And then... %
•  %d, %u, %D, %s

•  Although %b and %f are cool

26
Awesome: tables
•  Anything can be a key; anything can be a value
•  Tables as values for nesting
•  Functions as values

x = {“a”, “b”, “c”}
y = {subtable=x, double=function(v) return v*2 end}
•  Tables are references

function f(t, v) t.subtable = v end
f(y, {“1”, “2”, “3”})

27
Tables aren’t cool... metatables are cool

28
metatables to make a table read-only
local t = {a = “A”}
local _t = t
t = {}
local ro = {
__index = _t,
__newindex = function() error(“R/O”) end
}
setmetatable(t, ro)

print(t.a)
t.a = “B”

29
metatables for lazy loading
local t = {}
local loader = {
__index=function(_t, _v)
_t[_v] = docostlyload(_v)
return _t[_v]
end}
setmetatable(t, loader)

print(t.expensive)

30
metatables to make objects
local C = {}
C.__index = C
function C.new(d)
local newObject = {data=d}
return setmetatable(newObject, C)
end
function C.get_data(self)
return self.data
end
local o = C.new(“hello”)
print(o:get_data())

31
metatables to sandbox code #1
local env = { print = print }
local envmeta = { __index={}, __newindex=function() end }
setmetatable(env, envmeta)
function run(code)
local f = loadstring(code)
setfenv(f, env)
pcall(f)
end
run([[
local x = “Hello, World!”
print(x)
local y = string.len(x)
]])

32
metatables to sandbox code #2
local env = { print = print, string = { len = string.len } }
local envmeta = { __index={}, __newindex=function() end }
setmetatable(env, envmeta)
function run(code)
local f = loadstring(code)
setfenv(f, env)
pcall(f)
end
run([[
local x = “Hello, World!”
print(x)
local y = string.len(x)
]])

33
metatables for undefined variable detection
function doubler(x) return X*2 end
print(doubler(2))
t.lua:1: attempt to perform arithmetic on global 'X' (a nil value)

function doubler(x) return X*2 end
catcher={__index=function(t,v) error(v .. “ undefined”) end,
__newindex=function(t,k,v) error(v .. “ undefined”) end}
setmetatable(_G, catcher)
print(doubler(2))
lua: t.lua:2: Tried to read undefined X

34
Conclusion
•  Get past initial irritation!
•  Lua is a GREAT language for embedding in large

systems
•  Fast
•  Lots of functionality
•  Good standard library
•  Small
•  Extensible both from C and to C

35

Más contenido relacionado

La actualidad más candente

Get started with Lua programming
Get started with Lua programmingGet started with Lua programming
Get started with Lua programmingEtiene Dalcol
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simplerAlexander Mostovenko
 
Mastering Kotlin Standard Library
Mastering Kotlin Standard LibraryMastering Kotlin Standard Library
Mastering Kotlin Standard LibraryNelson Glauber Leal
 
RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolvedtrxcllnt
 
Aplicações assíncronas no Android com Coroutines & Jetpack
Aplicações assíncronas no Android com Coroutines & JetpackAplicações assíncronas no Android com Coroutines & Jetpack
Aplicações assíncronas no Android com Coroutines & JetpackNelson Glauber Leal
 
Aplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e JetpackAplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e JetpackNelson Glauber Leal
 
Functional Stream Processing with Scalaz-Stream
Functional Stream Processing with Scalaz-StreamFunctional Stream Processing with Scalaz-Stream
Functional Stream Processing with Scalaz-StreamAdil Akhter
 
FS2 for Fun and Profit
FS2 for Fun and ProfitFS2 for Fun and Profit
FS2 for Fun and ProfitAdil Akhter
 
シェル芸でライフハック(特論)
シェル芸でライフハック(特論)シェル芸でライフハック(特論)
シェル芸でライフハック(特論)Yuki Shimazaki
 
Something about Golang
Something about GolangSomething about Golang
Something about GolangAnton Arhipov
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackAplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackNelson Glauber Leal
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackAplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackNelson Glauber Leal
 
Go Concurrency Basics
Go Concurrency Basics Go Concurrency Basics
Go Concurrency Basics ElifTech
 
Add Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJSAdd Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJSRyan Anklam
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonAlex Payne
 
sbt: core concepts and updates (Scala Love 2020)
sbt: core concepts and updates (Scala Love 2020)sbt: core concepts and updates (Scala Love 2020)
sbt: core concepts and updates (Scala Love 2020)Eugene Yokota
 
GoとElixir、同時開発した時の気づき
GoとElixir、同時開発した時の気づきGoとElixir、同時開発した時の気づき
GoとElixir、同時開発した時の気づきTakahiro Kobaru
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event LoopDesignveloper
 
Compositional I/O Stream in Scala
Compositional I/O Stream in ScalaCompositional I/O Stream in Scala
Compositional I/O Stream in ScalaC4Media
 
Parallel Computing in R
Parallel Computing in RParallel Computing in R
Parallel Computing in Rmickey24
 

La actualidad más candente (20)

Get started with Lua programming
Get started with Lua programmingGet started with Lua programming
Get started with Lua programming
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simpler
 
Mastering Kotlin Standard Library
Mastering Kotlin Standard LibraryMastering Kotlin Standard Library
Mastering Kotlin Standard Library
 
RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolved
 
Aplicações assíncronas no Android com Coroutines & Jetpack
Aplicações assíncronas no Android com Coroutines & JetpackAplicações assíncronas no Android com Coroutines & Jetpack
Aplicações assíncronas no Android com Coroutines & Jetpack
 
Aplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e JetpackAplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e Jetpack
 
Functional Stream Processing with Scalaz-Stream
Functional Stream Processing with Scalaz-StreamFunctional Stream Processing with Scalaz-Stream
Functional Stream Processing with Scalaz-Stream
 
FS2 for Fun and Profit
FS2 for Fun and ProfitFS2 for Fun and Profit
FS2 for Fun and Profit
 
シェル芸でライフハック(特論)
シェル芸でライフハック(特論)シェル芸でライフハック(特論)
シェル芸でライフハック(特論)
 
Something about Golang
Something about GolangSomething about Golang
Something about Golang
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackAplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & Jetpack
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackAplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & Jetpack
 
Go Concurrency Basics
Go Concurrency Basics Go Concurrency Basics
Go Concurrency Basics
 
Add Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJSAdd Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJS
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
 
sbt: core concepts and updates (Scala Love 2020)
sbt: core concepts and updates (Scala Love 2020)sbt: core concepts and updates (Scala Love 2020)
sbt: core concepts and updates (Scala Love 2020)
 
GoとElixir、同時開発した時の気づき
GoとElixir、同時開発した時の気づきGoとElixir、同時開発した時の気づき
GoとElixir、同時開発した時の気づき
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
Compositional I/O Stream in Scala
Compositional I/O Stream in ScalaCompositional I/O Stream in Scala
Compositional I/O Stream in Scala
 
Parallel Computing in R
Parallel Computing in RParallel Computing in R
Parallel Computing in R
 

Destacado

La luna y la vaca
La luna y la vacaLa luna y la vaca
La luna y la vacaginasua
 
Dualacy chap 2 soph
Dualacy chap 2 sophDualacy chap 2 soph
Dualacy chap 2 sophSimpony
 
CMC Teacher Education SIG Presentation; Masats & Ambròs
CMC Teacher Education SIG Presentation; Masats & AmbròsCMC Teacher Education SIG Presentation; Masats & Ambròs
CMC Teacher Education SIG Presentation; Masats & AmbròsCmcTchrEdSIG
 
Summer 1
Summer 1Summer 1
Summer 1Simpony
 
Pregnancy five
Pregnancy fivePregnancy five
Pregnancy fiveSimpony
 
Dualacy chap 2 winter
Dualacy chap 2 winterDualacy chap 2 winter
Dualacy chap 2 winterSimpony
 
Presentatie JCI ledenvergadering
Presentatie JCI ledenvergaderingPresentatie JCI ledenvergadering
Presentatie JCI ledenvergaderingNicoudDM
 
Spring 3 goodie
Spring 3 goodieSpring 3 goodie
Spring 3 goodieSimpony
 
Pregnancy six
Pregnancy sixPregnancy six
Pregnancy sixSimpony
 
rowell resperatory powerpiont
rowell resperatory powerpiont rowell resperatory powerpiont
rowell resperatory powerpiont rowellcabate
 
Prezentangielskizrobiona 110509171449-phpapp02
Prezentangielskizrobiona 110509171449-phpapp02Prezentangielskizrobiona 110509171449-phpapp02
Prezentangielskizrobiona 110509171449-phpapp02monia1989
 
Clop 00237 a_co_p-2011_24mar2011
Clop 00237 a_co_p-2011_24mar2011Clop 00237 a_co_p-2011_24mar2011
Clop 00237 a_co_p-2011_24mar2011vinillaxue
 
Smith, lit poems 1
Smith, lit poems 1Smith, lit poems 1
Smith, lit poems 1CH1ST1NA
 
Spring 2 cooke
Spring 2 cookeSpring 2 cooke
Spring 2 cookeSimpony
 
CMC Teacher Education SIG Presentation; Egwurube
CMC Teacher Education SIG Presentation; EgwurubeCMC Teacher Education SIG Presentation; Egwurube
CMC Teacher Education SIG Presentation; EgwurubeCmcTchrEdSIG
 
Summer 3 vega
Summer 3 vegaSummer 3 vega
Summer 3 vegaSimpony
 
Financial analyse of the Apple Inc. Company
Financial analyse of the Apple Inc. CompanyFinancial analyse of the Apple Inc. Company
Financial analyse of the Apple Inc. Companyanthdcor
 
The City Conversation - Closing the Back Door
The City Conversation - Closing the Back DoorThe City Conversation - Closing the Back Door
The City Conversation - Closing the Back Dooronthecity
 
Chapter 5 b
Chapter 5 bChapter 5 b
Chapter 5 bSimpony
 
To The President Of SIMT
 To The President Of SIMT To The President Of SIMT
To The President Of SIMTVipin Kumar
 

Destacado (20)

La luna y la vaca
La luna y la vacaLa luna y la vaca
La luna y la vaca
 
Dualacy chap 2 soph
Dualacy chap 2 sophDualacy chap 2 soph
Dualacy chap 2 soph
 
CMC Teacher Education SIG Presentation; Masats & Ambròs
CMC Teacher Education SIG Presentation; Masats & AmbròsCMC Teacher Education SIG Presentation; Masats & Ambròs
CMC Teacher Education SIG Presentation; Masats & Ambròs
 
Summer 1
Summer 1Summer 1
Summer 1
 
Pregnancy five
Pregnancy fivePregnancy five
Pregnancy five
 
Dualacy chap 2 winter
Dualacy chap 2 winterDualacy chap 2 winter
Dualacy chap 2 winter
 
Presentatie JCI ledenvergadering
Presentatie JCI ledenvergaderingPresentatie JCI ledenvergadering
Presentatie JCI ledenvergadering
 
Spring 3 goodie
Spring 3 goodieSpring 3 goodie
Spring 3 goodie
 
Pregnancy six
Pregnancy sixPregnancy six
Pregnancy six
 
rowell resperatory powerpiont
rowell resperatory powerpiont rowell resperatory powerpiont
rowell resperatory powerpiont
 
Prezentangielskizrobiona 110509171449-phpapp02
Prezentangielskizrobiona 110509171449-phpapp02Prezentangielskizrobiona 110509171449-phpapp02
Prezentangielskizrobiona 110509171449-phpapp02
 
Clop 00237 a_co_p-2011_24mar2011
Clop 00237 a_co_p-2011_24mar2011Clop 00237 a_co_p-2011_24mar2011
Clop 00237 a_co_p-2011_24mar2011
 
Smith, lit poems 1
Smith, lit poems 1Smith, lit poems 1
Smith, lit poems 1
 
Spring 2 cooke
Spring 2 cookeSpring 2 cooke
Spring 2 cooke
 
CMC Teacher Education SIG Presentation; Egwurube
CMC Teacher Education SIG Presentation; EgwurubeCMC Teacher Education SIG Presentation; Egwurube
CMC Teacher Education SIG Presentation; Egwurube
 
Summer 3 vega
Summer 3 vegaSummer 3 vega
Summer 3 vega
 
Financial analyse of the Apple Inc. Company
Financial analyse of the Apple Inc. CompanyFinancial analyse of the Apple Inc. Company
Financial analyse of the Apple Inc. Company
 
The City Conversation - Closing the Back Door
The City Conversation - Closing the Back DoorThe City Conversation - Closing the Back Door
The City Conversation - Closing the Back Door
 
Chapter 5 b
Chapter 5 bChapter 5 b
Chapter 5 b
 
To The President Of SIMT
 To The President Of SIMT To The President Of SIMT
To The President Of SIMT
 

Similar a Lua London Meetup 2013

Monitoring and Debugging your Live Applications
Monitoring and Debugging your Live ApplicationsMonitoring and Debugging your Live Applications
Monitoring and Debugging your Live ApplicationsRobert Coup
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...GeeksLab Odessa
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵Wanbok Choi
 
AutoDesk
AutoDeskAutoDesk
AutoDeskSE3D
 
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014ryanerickson
 
Game Development with Corona SDK and Lua - Lua Workshop 2014
Game Development with Corona SDK and Lua - Lua Workshop 2014Game Development with Corona SDK and Lua - Lua Workshop 2014
Game Development with Corona SDK and Lua - Lua Workshop 2014SergeyLerg
 
Use of Lua in Lab Devices
Use of Lua in Lab DevicesUse of Lua in Lab Devices
Use of Lua in Lab DevicesClaus Kühnel
 
Pylons + Tokyo Cabinet
Pylons + Tokyo CabinetPylons + Tokyo Cabinet
Pylons + Tokyo CabinetBen Cheng
 
Intro to Spark - for Denver Big Data Meetup
Intro to Spark - for Denver Big Data MeetupIntro to Spark - for Denver Big Data Meetup
Intro to Spark - for Denver Big Data MeetupGwen (Chen) Shapira
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to DartRamesh Nair
 
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++Mohammad Shaker
 
Big data shim
Big data shimBig data shim
Big data shimtistrue
 
Ehsan parallel accelerator-dec2015
Ehsan parallel accelerator-dec2015Ehsan parallel accelerator-dec2015
Ehsan parallel accelerator-dec2015Christian Peel
 
ruby2600 - an Atari 2600 emulator written in Ruby
ruby2600 - an Atari 2600 emulator written in Rubyruby2600 - an Atari 2600 emulator written in Ruby
ruby2600 - an Atari 2600 emulator written in RubyCarlos Duarte do Nascimento
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Yuren Ju
 
Rubinius @ RubyAndRails2010
Rubinius @ RubyAndRails2010Rubinius @ RubyAndRails2010
Rubinius @ RubyAndRails2010Dirkjan Bussink
 
The internals of Spark SQL Joins, Dmytro Popovich
The internals of Spark SQL Joins, Dmytro PopovichThe internals of Spark SQL Joins, Dmytro Popovich
The internals of Spark SQL Joins, Dmytro PopovichSigma Software
 

Similar a Lua London Meetup 2013 (20)

Monitoring and Debugging your Live Applications
Monitoring and Debugging your Live ApplicationsMonitoring and Debugging your Live Applications
Monitoring and Debugging your Live Applications
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
 
AutoDesk
AutoDeskAutoDesk
AutoDesk
 
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
 
Game Development with Corona SDK and Lua - Lua Workshop 2014
Game Development with Corona SDK and Lua - Lua Workshop 2014Game Development with Corona SDK and Lua - Lua Workshop 2014
Game Development with Corona SDK and Lua - Lua Workshop 2014
 
Use of Lua in Lab Devices
Use of Lua in Lab DevicesUse of Lua in Lab Devices
Use of Lua in Lab Devices
 
Pylons + Tokyo Cabinet
Pylons + Tokyo CabinetPylons + Tokyo Cabinet
Pylons + Tokyo Cabinet
 
Intro to Spark - for Denver Big Data Meetup
Intro to Spark - for Denver Big Data MeetupIntro to Spark - for Denver Big Data Meetup
Intro to Spark - for Denver Big Data Meetup
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to Dart
 
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++
 
Big data shim
Big data shimBig data shim
Big data shim
 
Ehsan parallel accelerator-dec2015
Ehsan parallel accelerator-dec2015Ehsan parallel accelerator-dec2015
Ehsan parallel accelerator-dec2015
 
ruby2600 - an Atari 2600 emulator written in Ruby
ruby2600 - an Atari 2600 emulator written in Rubyruby2600 - an Atari 2600 emulator written in Ruby
ruby2600 - an Atari 2600 emulator written in Ruby
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
 
Return of c++
Return of c++Return of c++
Return of c++
 
2015 555 kharchenko_ppt
2015 555 kharchenko_ppt2015 555 kharchenko_ppt
2015 555 kharchenko_ppt
 
Rubinius @ RubyAndRails2010
Rubinius @ RubyAndRails2010Rubinius @ RubyAndRails2010
Rubinius @ RubyAndRails2010
 
The internals of Spark SQL Joins, Dmytro Popovich
The internals of Spark SQL Joins, Dmytro PopovichThe internals of Spark SQL Joins, Dmytro Popovich
The internals of Spark SQL Joins, Dmytro Popovich
 
Debugging Apache Spark
Debugging Apache SparkDebugging Apache Spark
Debugging Apache Spark
 

Más de Cloudflare

Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)Cloudflare
 
Close your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with CloudflareClose your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with CloudflareCloudflare
 
Why you should replace your d do s hardware appliance
Why you should replace your d do s hardware applianceWhy you should replace your d do s hardware appliance
Why you should replace your d do s hardware applianceCloudflare
 
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable WebinarDon't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable WebinarCloudflare
 
Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021Cloudflare
 
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...Cloudflare
 
Zero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fastZero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fastCloudflare
 
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...Cloudflare
 
Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...Cloudflare
 
Scaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-serviceScaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-serviceCloudflare
 
Application layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare dataApplication layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare dataCloudflare
 
Recent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respondRecent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respondCloudflare
 
Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)Cloudflare
 
Strengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providersStrengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providersCloudflare
 
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS AttacksKentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS AttacksCloudflare
 
Stopping DDoS Attacks in North America
Stopping DDoS Attacks in North AmericaStopping DDoS Attacks in North America
Stopping DDoS Attacks in North AmericaCloudflare
 
It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?Cloudflare
 
Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)Cloudflare
 
Bring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teamsBring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teamsCloudflare
 
Accelerate your digital transformation
Accelerate your digital transformationAccelerate your digital transformation
Accelerate your digital transformationCloudflare
 

Más de Cloudflare (20)

Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)
 
Close your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with CloudflareClose your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with Cloudflare
 
Why you should replace your d do s hardware appliance
Why you should replace your d do s hardware applianceWhy you should replace your d do s hardware appliance
Why you should replace your d do s hardware appliance
 
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable WebinarDon't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
 
Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021
 
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
 
Zero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fastZero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fast
 
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
 
Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...
 
Scaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-serviceScaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-service
 
Application layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare dataApplication layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare data
 
Recent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respondRecent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respond
 
Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)
 
Strengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providersStrengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providers
 
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS AttacksKentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
 
Stopping DDoS Attacks in North America
Stopping DDoS Attacks in North AmericaStopping DDoS Attacks in North America
Stopping DDoS Attacks in North America
 
It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?
 
Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)
 
Bring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teamsBring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teams
 
Accelerate your digital transformation
Accelerate your digital transformationAccelerate your digital transformation
Accelerate your digital transformation
 

Último

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Último (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Lua London Meetup 2013

  • 1. Lua: the world’s most infuriating language October 17, 2013 The simplest way to a safer, faster and smarter website
  • 2. My background •  Lots of... •  Assembly •  C, C++ and Go •  Perl, Tcl •  LISP (and relations) •  And lately... •  Lua 2
  • 3. My first Lua program 3
  • 4. 4
  • 6. CHDK on Canon A560 6
  • 7. CHDK Lua Interface •  Lua’s extensibility means it can control the camera •  http://chdk.wikia.com/wiki/Lua •  Functions added to Lua like •  shoot() – takes a picture •  press(), release() – press the shutter button (allows a partial press) •  get_orientation_sensor() – figure out camera orientation •  get_temperature() – get camera internal temperatures 7
  • 8. -- Now enter a self-check of the manual mode settings log( "Self-check started" ) assert_prop( 49, -32764, "Not in manual mode" ) assert_prop( 5, 0, "AF Assist Beam should be Off" ) assert_prop( 6, 0, "Focus Mode should be Normal" ) assert_prop( 8, 0, "AiAF Mode should be On" ) assert_prop( 21, 0, "Auto Rotate should be Off" ) assert_prop( 29, 0, "Bracket Mode should be None" ) assert_prop( 57, 0, "Picture Mode should be Superfine" ) assert_prop( 66, 0, "Date Stamp should be Off" ) assert_prop( 95, 0, "Digital Zoom should be None" ) assert_prop( 102, 0, "Drive Mode should be Single" ) assert_prop( 133, 0, "Manual Focus Mode should be Off" ) assert_prop( 143, 2, "Flash Mode should be Off" ) assert_prop( 149, 100, "ISO Mode should be 100" ) assert_prop( 218, 0, "Picture Size should be L" ) assert_prop( 268, 0, "White Balance Mode should be Auto" ) assert_gt( get_time("Y"), 2009, "Unexpected year" ) assert_gt( get_time("h"), 6, "Hour appears too early" ) assert_lt( get_time("h"), 20, "Hour appears too late" ) assert_gt( get_vbatt(), 3000, "Batteries seem low" ) assert_gt( get_jpg_count(), ns, "Insufficient card space" ) log( "Self-check complete" ) 8
  • 9. https://github.com/jgrahamc/gaga/tree/master/gaga-1/camera if ( ok == 1 ) then sleep(s) log( "Starting picture capture" ) n = 0 while ( 1 ) do tc = c while ( tc > 0 ) do shoot() n = n + 1 log( string.format("Picture %i taken", n )) tc = tc - 1 end log( string.format("Temperatures: %i, %i, %i", get_temperature(0), get_temperature(1), get_temperature(2) )) log( string.format("Battery level %i", get_vbatt())) sleep(i) end end log( "Done" ) 9
  • 10. Initial Irritants •  Seemed awfully verbose (bit like BASIC!) •  if... then... else... end •  Little shortcuts were missing •  x += 1 •  p?a:b •  Made it feel like a toy language 10
  • 11. Irritant: += •  Happy not to have x++ •  But why no +=? 11
  • 12. Irritant: ternary operator •  Super useful to be able to do local bird = duck?”It’s a duck”:”Not a duck” •  Can’t. •  Solution is the ugly local bird = duck and “It’s a duck” or “Not a duck” •  And it’s a bad solution local thing = question and returnsfalse() or crash() 12
  • 13. Irritant: not and ~= •  Not equals is ~= •  Which Perl programmers will confuse with =~ if x ~= 5 then print “Not five” end •  But not is not ~ it’s not! if not x == 5 then print “Not five” end if ~(x == 5) then print “Not five” end if not (x == 5) then print “Not five” end 13
  • 14. Next Lua Program •  Web Application Firewall •  About 2,000 lines of Lua •  Replaced 37,000 line C program! •  Plus 3,000 of automatically generated Lua •  Used by CloudFlare to process HTTP requests •  Checks for XSS, CSRF, SQL injection •  Bad browsers •  Custom rules •  Turns out Lua was great for this! 14
  • 15. Really, really fast: 1 to 2ms per request 15
  • 18. Lulip •  Line level profiler for Lua in Lua: https://github.com/jgrahamc/lulip/ local profiler = require 'lulip' local p = profiler:new() p:dont('some-module') p:maxrows(25) p:start() -- execute code here p:stop() p:dump(output_file_name) 18
  • 20. Lulip Core •  Nice things •  Lua’s debug library •  LuaJIT’s FFI for gettimeofday() •  Closures -- start: begin profiling function start(self) self:dont('lulip.lua') self.start_time = gettimeofday() self.current_line = nil self.current_start = 0 debug.sethook(function(e,l) self:event(e, l) end, "l") end 20
  • 21. Performance Tricks •  Wait til you’ve finished; Measure; Fix the slow things •  Locals way faster than globals local rand = math.random local len = #t for i=1,len do ... end •  . syntax faster than : local slen = string.len s:len() vs. slen(s) •  Minimize closures 21
  • 23. nginx + Lua and OpenResty •  http://wiki.nginx.org/HttpLuaModule •  Control over all phases of nginx inside Lua •  Very fast, very flexible, non-blocking (without callbacks!) •  Sockets, coroutines, subrequests, shared in-memory caching •  http://openresty.org/ •  Complete package of nginx, Lua and a set of libraries •  Access to Redis, memcached, MySQL, Postgresql •  JSON parsing, DNS, locks, ... •  CloudFlare HTTP almost entirely nginx + Lua / OpenResty 23
  • 25. Irritant: Arrays •  Index starts at 1 •  # doesn’t do what you think > > 3 > > 4 > > 2 x = {"a", "b", "c"} =#x x = {"a", "b", nil, "c"} =#x x = {"a", "b", nil, "c", nil} =#x 25
  • 26. Irritant: escape characters •  string.find, string.match •  Lots of special characters just like regular expressions •  Character classes: [a-z], [^a-z], . •  Repetition: *, +, ? •  Anchors: ^ and $ •  Groups and alternation: (foo|bar) •  And then... % •  %d, %u, %D, %s •  Although %b and %f are cool 26
  • 27. Awesome: tables •  Anything can be a key; anything can be a value •  Tables as values for nesting •  Functions as values x = {“a”, “b”, “c”} y = {subtable=x, double=function(v) return v*2 end} •  Tables are references function f(t, v) t.subtable = v end f(y, {“1”, “2”, “3”}) 27
  • 28. Tables aren’t cool... metatables are cool 28
  • 29. metatables to make a table read-only local t = {a = “A”} local _t = t t = {} local ro = { __index = _t, __newindex = function() error(“R/O”) end } setmetatable(t, ro) print(t.a) t.a = “B” 29
  • 30. metatables for lazy loading local t = {} local loader = { __index=function(_t, _v) _t[_v] = docostlyload(_v) return _t[_v] end} setmetatable(t, loader) print(t.expensive) 30
  • 31. metatables to make objects local C = {} C.__index = C function C.new(d) local newObject = {data=d} return setmetatable(newObject, C) end function C.get_data(self) return self.data end local o = C.new(“hello”) print(o:get_data()) 31
  • 32. metatables to sandbox code #1 local env = { print = print } local envmeta = { __index={}, __newindex=function() end } setmetatable(env, envmeta) function run(code) local f = loadstring(code) setfenv(f, env) pcall(f) end run([[ local x = “Hello, World!” print(x) local y = string.len(x) ]]) 32
  • 33. metatables to sandbox code #2 local env = { print = print, string = { len = string.len } } local envmeta = { __index={}, __newindex=function() end } setmetatable(env, envmeta) function run(code) local f = loadstring(code) setfenv(f, env) pcall(f) end run([[ local x = “Hello, World!” print(x) local y = string.len(x) ]]) 33
  • 34. metatables for undefined variable detection function doubler(x) return X*2 end print(doubler(2)) t.lua:1: attempt to perform arithmetic on global 'X' (a nil value) function doubler(x) return X*2 end catcher={__index=function(t,v) error(v .. “ undefined”) end, __newindex=function(t,k,v) error(v .. “ undefined”) end} setmetatable(_G, catcher) print(doubler(2)) lua: t.lua:2: Tried to read undefined X 34
  • 35. Conclusion •  Get past initial irritation! •  Lua is a GREAT language for embedding in large systems •  Fast •  Lots of functionality •  Good standard library •  Small •  Extensible both from C and to C 35