SlideShare a Scribd company logo
1 of 67
Download to read offline
Lua
Topics
• History + background
• Key features
• Syntax
• Tables
• Embedding
• Usecase
Topics
• History + background
• Key features           Pictures

• Syntax                   Code
• Tables
• Embedding
• Usecase
1977-1992
 Trade Barriers
Pontifícia Universidade
  Católica do Rio de
         Janeiro
PUC
SOL (Simple Object Language)
             +
 DEL (Data Entry Language)
             =
            Lua
Sol
Lua
• Easy to write and understand (so no Lisp,
  TCL or Scheme), Python wasn’t good
  enough yet

• Diverse collection of computers (so highly
  portable, not -nix only)

• Should be provided as a library with a C-
  API
Influences
• Scheme
• Modula
• CLU
• C++
• SNOBOL
• AWK
in use by
etc.
Robust
Fast
Portable
Embeddable
Powerful (yet simple)
Small
Free
Awesome
Syntax
if/then

if true == false then
     print "foobar";
else
     print "Ponies";
end
while

while true do
    print "Ponies!";
end
repeat/until

repeat
    line = os.read()
until line ~= ""
print "Ponies";
Types

print(type("Ponies"))   -->   string
print(type(10.4*3))     -->   number
print(type(print))      -->   function
print(type(type))       -->   function
print(type(true))       -->   boolean
print(type(nil))        -->   nil
print(type(type(X)))    -->   string
Types

print(type(a))    --> nil
a = 10
print(type(a))    --> number
a = "Ponies!!"
print(type(a))    --> string
a = print         -- yes, this is valid!
a(type(a))        --> function
More

• ~= == !=
• ‘local’ for local variables (garbage
  collection)
• bytecode execution on Lua VM (.luac)
Tables
Tables
Functions
   Functions are anonymous, and are pointers
   to variables


a = {p = print}    -- create a table
a.p("Ponies!")     --> Ponies!
print = math.sin   -- `print' now refers to the 'sin' function
a.p(print(1))      --> 0.841470
sin = a.p          -- `sin' now refers to the print function
sin(10, 20)        --> 10       20
Tables

• Can be used to define anything you want
• Classes, objects, namespaces, you name it
• The only complex data structure available
Tables
                           As array

a = {}                -- create a table and reference it in 'a'
k = "x"
a[k] = 10             -- new entry, with key="x" and value=10
a[20] = "Ponies!!1"   -- new entry, key=20 and value="Ponies!!1"
print(a["x"])         --> 10
k = 20
print(a[k])           --> "Ponies!!1"
a["x"] = a["x"] + 1   -- increments entry "x"
print(a["x"])         --> 11
print(a.x)            --> 11
Tables
           As structures (objects)


point = { x = 10, y = 20 }   -- Create new table
print(point["x"])            -- Prints 10
print(point.x)               -- Prints 10
Tables
        As namespace


Point = {}
Point.new =   function (x, y)
  return {x   = x, y = y}
end
Point.set_x   = function (point, x)
  point.x =   x
end
MetaTables!

•   The power to override events on tables, built into
    the interpreter

•   Useful for namespacing, classes, inheritance, etc.
MetaTables!
t1 = {a = "Ponies!"}     --   t1   is   a table with one name-value pair.
t2 = {}                  --   t2   is   an empty table.
setmetatable(t1, t2)     --   t2   is   t1's metatable.
t3 = {c = "Rainbows!"}   --   t3   is   just another table like t1.

t2.__index = t3          -- when a lookup fails in t1, t2 will
                         -- look for a value in t3.

print(t1.a)              -- Ponies!
print(t1.b)              -- nil
print(t1.c)              -- Rainbows!
MetaTables!
                         Another example


t1 = {a = "Ponies!"}     --   t1   is   a table with one name-value pair.
t2 = {}                  --   t2   is   an empty table.
setmetatable(t1, t2)     --   t2   is   t1's metatable.
t3 = {c = "Rainbows!"}   --   t3   is   just another table like t1.

t2.__index = function (t, k)
    return k           -- When no value is found, return the key
end

print(t1.a)              -- Ponies!
print(t1.b)              -- b
print(t1.c)              -- c
Embedding
Python example
                       PyLux

import pylux

# Shorthand to run a Lua script with "lux('script')"
def lux(script):
    pylux.eval("gv", "dostring", script)

# Shorthand to define a Python proc as callback for Lua
def luxcb(name,func):
    pylux.eval("gvc", "setglobal", name, func)

luxGlobals=[]
luxcb("luxAppend", luxGlobals.append)
lux("""
  for i,v in globals() do
     luxAppend(i)
  end
""")
luxGlobals.sort()
print luxGlobals
Ruby example
                   rubyluabridge et all


require 'rubyluabridge'
l = Lua::State.new         # Create a new state for the bridge
                           # (this is your 'sandbox')

l.eval("return 1")         # 1
l.n = 5
l.eval("return n")         # 5
l.eval("s='Ponies!'")
print l.s                  # Ponies!
Usecase
Background
• Medianetwork
• max 10gbit/s
• Millions of request/day (10 million+)
• Only binary data
• Custom solution built in CProxy (old)
• Needed new feature set
• API with several subsystems
Background

• Needed easy maintenance
• Scalable, lightweight, fast
• Future proof
• Features!
• No exposure of backend storage
Decisions

• nginx
• mod_lua
• mod_cache
• mod_proxy
• LuaSockets
Bitmovr.lua

• Lua
• Memcached
• Supports only GET
• Proxy
• Using filesinks => bitmovr
Architecture

                             Loadbalancer




                     lighttpd                edge
                        lighttpd
                           lighttpd
                              lighttpd
                                 lighttpd
                                    lighttpd
                                       nginx




      Loadbalancer




  MediaTool                                         Castor
LuaSocket
-- include libraries
socket = require("socket");

-- create a TCP socket and bind it to the local host at the given port
server = assert(socket.bind('0.0.0.0',50000))

-- loop forever waiting for clients
while 1 do

      -- wait for a connection from any client
      local client = server:accept()

      -- make sure we don't block waiting for this client's line
      client:settimeout(10)

      -- receive the line
      local line, err = client:receive()

      -- if there was no error, send it back to the client
      if not err then

            -- send the same response as was send
            client:send(line);

            -- close the connection
            client:close()
      end
end
LTN12
Sinks, Pumps, Filters, Chains, etc.




-- load the ltn12 module
local ltn12 = require("ltn12")

-- copy a file
ltn12.pump.all(
  ltn12.source.file(io.open("original.png")),
  ltn12.sink.file(io.open("copy.png"))
)
LTN12
     Sinks, Pumps, Filters, Chains, etc.




local outputSink = socket.sink("close-when-done", client)

local r, c, h = socket.http.request{
    sink = outputSink,
    method = 'GET',
    url = storageLocation,
    redirect = true
}
Conclusion

• Fast, simple, elegant, flexible
• A bit of a hurdle
• Sandboxing is interesting
Questions?

More Related Content

What's hot

Kotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime PerformanceKotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime Performanceintelliyole
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlinintelliyole
 
ITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingIstanbul Tech Talks
 
Scala introduction
Scala introductionScala introduction
Scala introductionvito jeng
 
Lua London Meetup 2013
Lua London Meetup 2013Lua London Meetup 2013
Lua London Meetup 2013Cloudflare
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimizationg3_nittala
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance PythonIan Ozsvald
 
Odessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonOdessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonMax Klymyshyn
 
Mastering Kotlin Standard Library
Mastering Kotlin Standard LibraryMastering Kotlin Standard Library
Mastering Kotlin Standard LibraryNelson Glauber Leal
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with ScalaDenis
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedSusan Potter
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Leonardo Borges
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015Michiel Borkent
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the webMichiel Borkent
 
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
 

What's hot (20)

Kotlin, why?
Kotlin, why?Kotlin, why?
Kotlin, why?
 
Kotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime PerformanceKotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime Performance
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
ITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function Programming
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Python
PythonPython
Python
 
Lua London Meetup 2013
Lua London Meetup 2013Lua London Meetup 2013
Lua London Meetup 2013
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance Python
 
Odessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonOdessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and Python
 
Mastering Kotlin Standard Library
Mastering Kotlin Standard LibraryMastering Kotlin Standard Library
Mastering Kotlin Standard Library
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
 
Meet scala
Meet scalaMeet scala
Meet scala
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
 
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
 

Viewers also liked

Web development with Lua and Sailor @ GeeCon 2015
Web development with Lua and Sailor @ GeeCon 2015Web development with Lua and Sailor @ GeeCon 2015
Web development with Lua and Sailor @ GeeCon 2015Etiene Dalcol
 
Lua as a business logic language in high load application
Lua as a business logic language in high load applicationLua as a business logic language in high load application
Lua as a business logic language in high load applicationIlya Martynov
 
LuaConf 2016 - Becoming a Lua Powered Super Hero
LuaConf 2016 - Becoming a Lua Powered Super HeroLuaConf 2016 - Becoming a Lua Powered Super Hero
LuaConf 2016 - Becoming a Lua Powered Super HeroCharles McKeever
 

Viewers also liked (6)

What's wrong with web
What's wrong with webWhat's wrong with web
What's wrong with web
 
Web development with Lua and Sailor @ GeeCon 2015
Web development with Lua and Sailor @ GeeCon 2015Web development with Lua and Sailor @ GeeCon 2015
Web development with Lua and Sailor @ GeeCon 2015
 
Lua and its Ecosystem
Lua and its EcosystemLua and its Ecosystem
Lua and its Ecosystem
 
Lua as a business logic language in high load application
Lua as a business logic language in high load applicationLua as a business logic language in high load application
Lua as a business logic language in high load application
 
Lua vs python
Lua vs pythonLua vs python
Lua vs python
 
LuaConf 2016 - Becoming a Lua Powered Super Hero
LuaConf 2016 - Becoming a Lua Powered Super HeroLuaConf 2016 - Becoming a Lua Powered Super Hero
LuaConf 2016 - Becoming a Lua Powered Super Hero
 

Similar to Lua first steps

Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...GeeksLab Odessa
 
From Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksFrom Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksSeniorDevOnly
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivitynklmish
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, SwiftYandex
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming LanguageNicolò Calcavecchia
 
Reactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwiftReactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwiftFlorent Pillet
 
Functional Programming - Past, Present and Future
Functional Programming - Past, Present and FutureFunctional Programming - Past, Present and Future
Functional Programming - Past, Present and FuturePushkar Kulkarni
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present FutureIndicThreads
 
Pydiomatic
PydiomaticPydiomatic
Pydiomaticrik0
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring frameworkSunghyouk Bae
 
AutoDesk
AutoDeskAutoDesk
AutoDeskSE3D
 

Similar to Lua first steps (20)

Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
 
From Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksFrom Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risks
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivity
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming Language
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Reactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwiftReactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwift
 
Functional Programming - Past, Present and Future
Functional Programming - Past, Present and FutureFunctional Programming - Past, Present and Future
Functional Programming - Past, Present and Future
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present Future
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Spark workshop
Spark workshopSpark workshop
Spark workshop
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
Redis Lua Scripts
Redis Lua ScriptsRedis Lua Scripts
Redis Lua Scripts
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
2015 555 kharchenko_ppt
2015 555 kharchenko_ppt2015 555 kharchenko_ppt
2015 555 kharchenko_ppt
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring framework
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
AutoDesk
AutoDeskAutoDesk
AutoDesk
 
N flavors of streaming
N flavors of streamingN flavors of streaming
N flavors of streaming
 

Recently uploaded

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Recently uploaded (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

Lua first steps

  • 1. Lua
  • 2. Topics • History + background • Key features • Syntax • Tables • Embedding • Usecase
  • 3. Topics • History + background • Key features Pictures • Syntax Code • Tables • Embedding • Usecase
  • 4.
  • 5.
  • 6.
  • 7.
  • 9. Pontifícia Universidade Católica do Rio de Janeiro
  • 10. PUC
  • 11.
  • 12. SOL (Simple Object Language) + DEL (Data Entry Language) = Lua
  • 13. Sol
  • 14. Lua
  • 15. • Easy to write and understand (so no Lisp, TCL or Scheme), Python wasn’t good enough yet • Diverse collection of computers (so highly portable, not -nix only) • Should be provided as a library with a C- API
  • 16. Influences • Scheme • Modula • CLU • C++ • SNOBOL • AWK
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25. etc.
  • 26.
  • 28. Fast
  • 32. Small
  • 33. Free
  • 36. if/then if true == false then print "foobar"; else print "Ponies"; end
  • 37. while while true do print "Ponies!"; end
  • 38. repeat/until repeat line = os.read() until line ~= "" print "Ponies";
  • 39. Types print(type("Ponies")) --> string print(type(10.4*3)) --> number print(type(print)) --> function print(type(type)) --> function print(type(true)) --> boolean print(type(nil)) --> nil print(type(type(X))) --> string
  • 40. Types print(type(a)) --> nil a = 10 print(type(a)) --> number a = "Ponies!!" print(type(a)) --> string a = print -- yes, this is valid! a(type(a)) --> function
  • 41. More • ~= == != • ‘local’ for local variables (garbage collection) • bytecode execution on Lua VM (.luac)
  • 44. Functions Functions are anonymous, and are pointers to variables a = {p = print} -- create a table a.p("Ponies!") --> Ponies! print = math.sin -- `print' now refers to the 'sin' function a.p(print(1)) --> 0.841470 sin = a.p -- `sin' now refers to the print function sin(10, 20) --> 10 20
  • 45. Tables • Can be used to define anything you want • Classes, objects, namespaces, you name it • The only complex data structure available
  • 46. Tables As array a = {} -- create a table and reference it in 'a' k = "x" a[k] = 10 -- new entry, with key="x" and value=10 a[20] = "Ponies!!1" -- new entry, key=20 and value="Ponies!!1" print(a["x"]) --> 10 k = 20 print(a[k]) --> "Ponies!!1" a["x"] = a["x"] + 1 -- increments entry "x" print(a["x"]) --> 11 print(a.x) --> 11
  • 47. Tables As structures (objects) point = { x = 10, y = 20 } -- Create new table print(point["x"]) -- Prints 10 print(point.x) -- Prints 10
  • 48. Tables As namespace Point = {} Point.new = function (x, y) return {x = x, y = y} end Point.set_x = function (point, x) point.x = x end
  • 49. MetaTables! • The power to override events on tables, built into the interpreter • Useful for namespacing, classes, inheritance, etc.
  • 50. MetaTables! t1 = {a = "Ponies!"} -- t1 is a table with one name-value pair. t2 = {} -- t2 is an empty table. setmetatable(t1, t2) -- t2 is t1's metatable. t3 = {c = "Rainbows!"} -- t3 is just another table like t1. t2.__index = t3 -- when a lookup fails in t1, t2 will -- look for a value in t3. print(t1.a) -- Ponies! print(t1.b) -- nil print(t1.c) -- Rainbows!
  • 51. MetaTables! Another example t1 = {a = "Ponies!"} -- t1 is a table with one name-value pair. t2 = {} -- t2 is an empty table. setmetatable(t1, t2) -- t2 is t1's metatable. t3 = {c = "Rainbows!"} -- t3 is just another table like t1. t2.__index = function (t, k) return k -- When no value is found, return the key end print(t1.a) -- Ponies! print(t1.b) -- b print(t1.c) -- c
  • 53. Python example PyLux import pylux # Shorthand to run a Lua script with "lux('script')" def lux(script): pylux.eval("gv", "dostring", script) # Shorthand to define a Python proc as callback for Lua def luxcb(name,func): pylux.eval("gvc", "setglobal", name, func) luxGlobals=[] luxcb("luxAppend", luxGlobals.append) lux(""" for i,v in globals() do luxAppend(i) end """) luxGlobals.sort() print luxGlobals
  • 54. Ruby example rubyluabridge et all require 'rubyluabridge' l = Lua::State.new # Create a new state for the bridge # (this is your 'sandbox') l.eval("return 1") # 1 l.n = 5 l.eval("return n") # 5 l.eval("s='Ponies!'") print l.s # Ponies!
  • 56. Background • Medianetwork • max 10gbit/s • Millions of request/day (10 million+) • Only binary data • Custom solution built in CProxy (old) • Needed new feature set • API with several subsystems
  • 57. Background • Needed easy maintenance • Scalable, lightweight, fast • Future proof • Features! • No exposure of backend storage
  • 58. Decisions • nginx • mod_lua • mod_cache • mod_proxy • LuaSockets
  • 59. Bitmovr.lua • Lua • Memcached • Supports only GET • Proxy • Using filesinks => bitmovr
  • 60. Architecture Loadbalancer lighttpd edge lighttpd lighttpd lighttpd lighttpd lighttpd nginx Loadbalancer MediaTool Castor
  • 61.
  • 62.
  • 63. LuaSocket -- include libraries socket = require("socket"); -- create a TCP socket and bind it to the local host at the given port server = assert(socket.bind('0.0.0.0',50000)) -- loop forever waiting for clients while 1 do -- wait for a connection from any client local client = server:accept() -- make sure we don't block waiting for this client's line client:settimeout(10) -- receive the line local line, err = client:receive() -- if there was no error, send it back to the client if not err then -- send the same response as was send client:send(line); -- close the connection client:close() end end
  • 64. LTN12 Sinks, Pumps, Filters, Chains, etc. -- load the ltn12 module local ltn12 = require("ltn12") -- copy a file ltn12.pump.all( ltn12.source.file(io.open("original.png")), ltn12.sink.file(io.open("copy.png")) )
  • 65. LTN12 Sinks, Pumps, Filters, Chains, etc. local outputSink = socket.sink("close-when-done", client) local r, c, h = socket.http.request{ sink = outputSink, method = 'GET', url = storageLocation, redirect = true }
  • 66. Conclusion • Fast, simple, elegant, flexible • A bit of a hurdle • Sandboxing is interesting