SlideShare a Scribd company logo
1 of 27
Download to read offline
Lua and its Ecosystem                    (45’)




   François Perrad
   francois.perrad@gadz.org



                   fperrad@OSDC.fr2011
Overview
   Lua is a powerful, fast, lightweight,
    embeddable scripting language.
   from Brazil (PUC-Rio) since 1993
   Open Source, but closed development
   A core team (academic)
       Roberto Ierusalimschy
       Luiz Henrique de Figueiredo
       Waldemar Celes
   MIT License
   A mailing list since 1997
   lastest Workshop on September 8–9, 2011

                   fperrad@OSDC.fr2011
History of recent releases




          fperrad@OSDC.fr2011
Lua is small
   Reference Manual
       < 100 pages
   Grammar EBNF
       1 page
   Code size : Sloccount -> 12.5 KLoC of C
   Binary ~150 kB
   8 types
       nil, boolean, number, string, function, userdata,
        thread, table
   21 keywords
       No builtin function,
       only standard libraries


                    fperrad@OSDC.fr2011
Lua is portable
   Only C89
   Linux, OSX, Windows
   Android, iOS
       Corona SDK
   eLua runs on the "bare-metal"
       LEGO Mindstorm NXT
       …




                fperrad@OSDC.fr2011
Alternate Implementations
   LuaJIT
          Very fast, full compatible
   LLVM-Lua
   Mochalua
          Java JME
   Jill
          Java JME, JSE




                      fperrad@OSDC.fr2011
Lua is powerful
   function as first class
   closure
   exception (as library)
   coroutine (as library)
   iterator
   regex (with its own dialect)
   some OO mechanisms (prototype based)
   tail call


              fperrad@OSDC.fr2011
Factorial - Loop
function factorial (n)
    local a = 1
    for i = 1, n, 1 do
        a = a * i
    end
    return a
end

print(factorial(7))         --> 5040

           fperrad@OSDC.fr2011
Factorial – recursive
function factorial (n)
    if n == 0 then
         return 1
    else
         return n * factorial(n-1)
    end
end

print(factorial(7))         --> 5040

           fperrad@OSDC.fr2011
Factorial - Iter
function factorial    (n)
    local function    iter (prod, cnt)
        if cnt > n    then
            return    prod
        else
            return    iter(cnt*prod, cnt+1)
        end
    end
    return iter(1,    1)
end

print(factorial(7)) --> 5040

             fperrad@OSDC.fr2011
Fibonacci - iterator
local function fibo_iterator ()
    local x, y = 0, 1
    return function ()
        local res = x
        x, y = y, x+y
        return res
    end
end

for v in fibo_iterator() do
    print(v)
    if v >= 144 then break end
end
             fperrad@OSDC.fr2011
Fibonacci - Coroutine
local function fibo_generator ()
    local x, y = 0, 1
    while true do
        coroutine.yield(x)
        x, y = y, x+y
    end
end

local function fibo_iterator ()
    return coroutine.wrap(fibo_generator)
end

for v in fibo_iterator() do
    print(v)
    if v >= 144 then break end
end

               fperrad@OSDC.fr2011
Fibonacci – metamethods
local fibo = setmetatable({
    [0] = 0,
    [1] = 1,
}, {
    __index =   function (t, n)
                     local res = t[n-1] + t[n-2]
                     t[n] = res -- memoize
                     return res
                end,
    __call =    function (t, n)
                     return t[n]
                end,
})

for i = 0, 12 do
    print(fibo(i))
end

                     fperrad@OSDC.fr2011
Lua is embeddable / extensible
   Designed to be integrated with software
    writen in C

   C API
       Comprehensible
       Well documented
       Stack model

   All standard libraries are built with

   Userdata is a core type and allows
    metatable/metamethods

                  fperrad@OSDC.fr2011
Lua Module Land / Heterogenority
   Build system
      nothing
      Makefile
      CMake
   Documentation
      LuaDoc : à la JavaDoc
      LuaPOD : with Perl
   QA – Test
      assert
      lunit : à la xUnit
      Lunity
      lua-TestMore : à la Perl (Test Anything Protocol)
   Packaging / Deployment
      LuaDist (CMake)
      LuaRocks

                     fperrad@OSDC.fr2011
A rockspec sample (plain Lua)
package = 'lua-CodeGen'
version = '0.2.2-1'
source = {
   url = 'http://cloud.github.com/downloads/fperrad/lua-CodeGen/lua-codegen-0.2.2.tar.gz',
   md5 = '782a40b6ac55ee3077e10f302e301706',
   dir = 'lua-CodeGen-0.2.2',
}
description = {
   summary = "a template engine",
   detailed = [[
        lua-CodeGen is a "safe" template engine.
        lua-CodeGen enforces a strict Model-View separation.
        lua-CodeGen allows to split template in small chunk, and encourages the reuse of them by inheri
        lua-CodeGen is not dedicated to HTML, it could generate any kind of textual code.
   ]],
   homepage = 'http://fperrad.github.com/lua-CodeGen',
   maintainer = 'Francois Perrad',
   license = 'MIT/X11'
}
dependencies = {
   'lua >= 5.1',
   'lua-testmore >= 0.2.3',
}
build = {
   type = 'builtin',
   modules = {
       ['CodeGen']         = 'src/CodeGen.lua',
       ['CodeGen.Graph']   = 'src/CodeGen/Graph.lua',
   },
   copy_directories = { 'doc', 'test' },
}

                               fperrad@OSDC.fr2011
Binding modules
   LuaSocket : socket, http, smtp
   LuaSec : https
   LuaPOSIX
   LuaExpat : XML
   LuaSQL : mysql, postgres, sqlite, …
   wxLua : wxWidget
   LuaGnome : GTK
   LuaZMQ
   …

               fperrad@OSDC.fr2011
Other modules / projects
   Kepler : web development platform
       Orbit : an MVC web framework
       WSAPI : à la WSGI, Rack, PSGI/Plack
       Sputnik : a wiki engine
   Lpeg : Parsing Expression Grammars
   LuaJSON
   Lua Lanes - multithreading in Lua
   OiL : an Object Request Broker (CORBA)

    …



                  fperrad@OSDC.fr2011
Use case : textadept
   Textadept is a fast, minimalist, and
    ridiculously extensible text editor for Linux,
    Mac OSX, and Windows
   Lead dev : Mitchell
   started on 2007, 1.0 on Jan 2009
   2 KLoC of C + 6 KLoc of Lua
   Textadept 4.0 embeds
       Lua 5.1.4
       LPeg 0.9
       LuaFileSystem 1.4.1
       Scintilla 2.28 / GTK+
   MIT License

                    fperrad@OSDC.fr2011
Use case : wireshark
   Wireshark (Ethereal) is the world's
    foremost network protocol analyzer
   > 2 MLoC of C
   Lua can be used to write dissectors,
    post-dissectors and taps.
   Lua introduced around 0.99.4
   GPL License




               fperrad@OSDC.fr2011
Use case : LuaTeX
   LuaTeX is an extended version of
    pdfTeX using Lua as an embedded
    scripting language.
   started on 2007
   source size
       300 KLoC of C
       200 KLoc of C++
       10 KLoC of Lua
   GPL License


                 fperrad@OSDC.fr2011
Use case : awesome
   awesome is an extensible, highly
    configurable window manager for X.
   started on 2007
   10 KLoC of C + 7 KLoC of Lua
   It's extremely fast, small, dynamic
    and heavily extensible using the Lua
    programming language.
   GPL License



               fperrad@OSDC.fr2011
Use case : Redis
   Redis is an open-source, networked, in-
    memory, persistent, journaled, key-value
    data store
   Lead dev : antirez
   started on 2009
   30 KLoC of C
   Scripting branch released on May 2011
       Server-side scripting with Lua
       Easy to embed, and FAST
       scripting.c : 500 LoC
   will available with Redis 2.6
   License : BSD

                    fperrad@OSDC.fr2011
Sponsors
   Adobe
       Photoshop Lightroom
         40% is written in Lua
         Penlight : A Portable Lua Library
       The workshop 2005 held at Adobe’s
        headquarters in San José, California
   SocialMediaPress
   CSTUG
   Océ
       Printer, copier, plotter
       The workshop 2006 held at Océ's R&D
        department in Venlo, The Netherlands

                    fperrad@OSDC.fr2011
Philosophy of Lua

   Mechanisms instead of policies

   Zen of Lua :
       Doing more with less.




                  fperrad@OSDC.fr2011
Conclusion

   An embeddable scripting language
    that is simple, efficient, portable and
    lightweight

   supports several paradigm of
    programming :
       procedural
       Object-Oriented
       functional
       data-driven

                 fperrad@OSDC.fr2011
Bibliography / Webography
   www.lua.org
   the Lua 5.1 Reference Manual
   www.luafaq.org
   http://lua-users.org/wiki/
   The evolution of Lua
   Small is Beautiful: the design of Lua
   Lua Short Reference
   Programming in Lua
   Lua programming Gems
   LuaForge (frozen since 2009)



                   fperrad@OSDC.fr2011

More Related Content

What's hot

Fluentd meetup dive into fluent plugin (outdated)
Fluentd meetup dive into fluent plugin (outdated)Fluentd meetup dive into fluent plugin (outdated)
Fluentd meetup dive into fluent plugin (outdated)N Masahiro
 
Reversing the dropbox client on windows
Reversing the dropbox client on windowsReversing the dropbox client on windows
Reversing the dropbox client on windowsextremecoders
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)goccy
 
Python for System Administrators
Python for System AdministratorsPython for System Administrators
Python for System AdministratorsRoberto Polli
 
嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain艾鍗科技
 
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016Susan Potter
 
Scaling mysql with python (and Docker).
Scaling mysql with python (and Docker).Scaling mysql with python (and Docker).
Scaling mysql with python (and Docker).Roberto Polli
 
NovaProva, a new generation unit test framework for C programs
NovaProva, a new generation unit test framework for C programsNovaProva, a new generation unit test framework for C programs
NovaProva, a new generation unit test framework for C programsGreg Banks
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksEueung Mulyana
 
Java Hates Linux. Deal With It.
Java Hates Linux.  Deal With It.Java Hates Linux.  Deal With It.
Java Hates Linux. Deal With It.Greg Banks
 
POCO C++ Libraries Intro and Overview
POCO C++ Libraries Intro and OverviewPOCO C++ Libraries Intro and Overview
POCO C++ Libraries Intro and OverviewGünter Obiltschnig
 
Async programming and python
Async programming and pythonAsync programming and python
Async programming and pythonChetan Giridhar
 
Kernel bug hunting
Kernel bug huntingKernel bug hunting
Kernel bug huntingAndrea Righi
 
Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and ExecutionChong-Kuan Chen
 
Memory Management In Python The Basics
Memory Management In Python The BasicsMemory Management In Python The Basics
Memory Management In Python The BasicsNina Zakharenko
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelDivye Kapoor
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John StevensonJAX London
 

What's hot (20)

Fluentd meetup dive into fluent plugin (outdated)
Fluentd meetup dive into fluent plugin (outdated)Fluentd meetup dive into fluent plugin (outdated)
Fluentd meetup dive into fluent plugin (outdated)
 
The Internals of "Hello World" Program
The Internals of "Hello World" ProgramThe Internals of "Hello World" Program
The Internals of "Hello World" Program
 
Reversing the dropbox client on windows
Reversing the dropbox client on windowsReversing the dropbox client on windows
Reversing the dropbox client on windows
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
 
Simulating TUM Drone 2.0 by ROS
Simulating TUM Drone 2.0  by ROSSimulating TUM Drone 2.0  by ROS
Simulating TUM Drone 2.0 by ROS
 
Python for System Administrators
Python for System AdministratorsPython for System Administrators
Python for System Administrators
 
嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain
 
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
 
Scaling mysql with python (and Docker).
Scaling mysql with python (and Docker).Scaling mysql with python (and Docker).
Scaling mysql with python (and Docker).
 
NovaProva, a new generation unit test framework for C programs
NovaProva, a new generation unit test framework for C programsNovaProva, a new generation unit test framework for C programs
NovaProva, a new generation unit test framework for C programs
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
 
Java Hates Linux. Deal With It.
Java Hates Linux.  Deal With It.Java Hates Linux.  Deal With It.
Java Hates Linux. Deal With It.
 
POCO C++ Libraries Intro and Overview
POCO C++ Libraries Intro and OverviewPOCO C++ Libraries Intro and Overview
POCO C++ Libraries Intro and Overview
 
Async programming and python
Async programming and pythonAsync programming and python
Async programming and python
 
Fluentd v1 and Roadmap
Fluentd v1 and RoadmapFluentd v1 and Roadmap
Fluentd v1 and Roadmap
 
Kernel bug hunting
Kernel bug huntingKernel bug hunting
Kernel bug hunting
 
Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and Execution
 
Memory Management In Python The Basics
Memory Management In Python The BasicsMemory Management In Python The Basics
Memory Management In Python The Basics
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
 

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
 
Get started with Lua - Hackference 2016
Get started with Lua - Hackference 2016Get started with Lua - Hackference 2016
Get started with Lua - Hackference 2016Etiene 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
 
The basics and design of lua table
The basics and design of lua tableThe basics and design of lua table
The basics and design of lua tableShuai Yuan
 
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 (9)

What's wrong with web
What's wrong with webWhat's wrong with web
What's wrong with web
 
Lua first steps
Lua first stepsLua first steps
Lua first steps
 
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
 
Get started with Lua - Hackference 2016
Get started with Lua - Hackference 2016Get started with Lua - Hackference 2016
Get started with Lua - Hackference 2016
 
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
 
Hands on lua
Hands on luaHands on lua
Hands on lua
 
Lua vs python
Lua vs pythonLua vs python
Lua vs python
 
The basics and design of lua table
The basics and design of lua tableThe basics and design of lua table
The basics and design of lua table
 
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 and its Ecosystem Overview (45

EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4Max Kleiner
 
Linux Kernel Library - Reusing Monolithic Kernel
Linux Kernel Library - Reusing Monolithic KernelLinux Kernel Library - Reusing Monolithic Kernel
Linux Kernel Library - Reusing Monolithic KernelHajime Tazaki
 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudyYusuke Ando
 
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
 
Apache Pulsar Development 101 with Python
Apache Pulsar Development 101 with PythonApache Pulsar Development 101 with Python
Apache Pulsar Development 101 with PythonTimothy Spann
 
Pwrake: Distributed Workflow Engine for e-Science - RubyConfX
Pwrake: Distributed Workflow Engine for e-Science - RubyConfXPwrake: Distributed Workflow Engine for e-Science - RubyConfX
Pwrake: Distributed Workflow Engine for e-Science - RubyConfXMasahiro Tanaka
 
Introduction to Lua Luajit Openresty Luvit
Introduction to Lua Luajit Openresty LuvitIntroduction to Lua Luajit Openresty Luvit
Introduction to Lua Luajit Openresty LuvitLionel Duboeuf
 
LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1Hajime Tazaki
 
BSD Sockets API in Zephyr RTOS - SFO17-108
BSD Sockets API in Zephyr RTOS - SFO17-108BSD Sockets API in Zephyr RTOS - SFO17-108
BSD Sockets API in Zephyr RTOS - SFO17-108Linaro
 
Socket Programming In Python
Socket Programming In PythonSocket Programming In Python
Socket Programming In Pythondidip
 
Rclex: A Library for Robotics meet Elixir
Rclex: A Library for Robotics meet ElixirRclex: A Library for Robotics meet Elixir
Rclex: A Library for Robotics meet ElixirHideki Takase
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microserviceGiulio De Donato
 
Shipping Applications to Production in Containers with Docker
Shipping Applications to Production in Containers with DockerShipping Applications to Production in Containers with Docker
Shipping Applications to Production in Containers with DockerJérôme Petazzoni
 
Jupyter notebooks on steroids
Jupyter notebooks on steroidsJupyter notebooks on steroids
Jupyter notebooks on steroidsJose Enrique Ruiz
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesBUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesLinaro
 
Open Source .NET
Open Source .NETOpen Source .NET
Open Source .NETOnyxfish
 

Similar to Lua and its Ecosystem Overview (45 (20)

EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
 
Linux Kernel Library - Reusing Monolithic Kernel
Linux Kernel Library - Reusing Monolithic KernelLinux Kernel Library - Reusing Monolithic Kernel
Linux Kernel Library - Reusing Monolithic Kernel
 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudy
 
LOD2: State of Play WP6 - LOD2 Stack Architecture
LOD2: State of Play WP6 - LOD2 Stack ArchitectureLOD2: State of Play WP6 - LOD2 Stack Architecture
LOD2: State of Play WP6 - LOD2 Stack Architecture
 
Use of Lua in Lab Devices
Use of Lua in Lab DevicesUse of Lua in Lab Devices
Use of Lua in Lab Devices
 
Shree duth awasthi_cv
Shree duth awasthi_cvShree duth awasthi_cv
Shree duth awasthi_cv
 
Apache Pulsar Development 101 with Python
Apache Pulsar Development 101 with PythonApache Pulsar Development 101 with Python
Apache Pulsar Development 101 with Python
 
Pwrake: Distributed Workflow Engine for e-Science - RubyConfX
Pwrake: Distributed Workflow Engine for e-Science - RubyConfXPwrake: Distributed Workflow Engine for e-Science - RubyConfX
Pwrake: Distributed Workflow Engine for e-Science - RubyConfX
 
Introduction to Lua Luajit Openresty Luvit
Introduction to Lua Luajit Openresty LuvitIntroduction to Lua Luajit Openresty Luvit
Introduction to Lua Luajit Openresty Luvit
 
The Parrot VM
The Parrot VMThe Parrot VM
The Parrot VM
 
LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1
 
BSD Sockets API in Zephyr RTOS - SFO17-108
BSD Sockets API in Zephyr RTOS - SFO17-108BSD Sockets API in Zephyr RTOS - SFO17-108
BSD Sockets API in Zephyr RTOS - SFO17-108
 
Socket Programming In Python
Socket Programming In PythonSocket Programming In Python
Socket Programming In Python
 
Rclex: A Library for Robotics meet Elixir
Rclex: A Library for Robotics meet ElixirRclex: A Library for Robotics meet Elixir
Rclex: A Library for Robotics meet Elixir
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microservice
 
Shipping Applications to Production in Containers with Docker
Shipping Applications to Production in Containers with DockerShipping Applications to Production in Containers with Docker
Shipping Applications to Production in Containers with Docker
 
Jupyter notebooks on steroids
Jupyter notebooks on steroidsJupyter notebooks on steroids
Jupyter notebooks on steroids
 
Ropython-windbg-python-extensions
Ropython-windbg-python-extensionsRopython-windbg-python-extensions
Ropython-windbg-python-extensions
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesBUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
 
Open Source .NET
Open Source .NETOpen Source .NET
Open Source .NET
 

Lua and its Ecosystem Overview (45

  • 1. Lua and its Ecosystem (45’) François Perrad francois.perrad@gadz.org fperrad@OSDC.fr2011
  • 2. Overview  Lua is a powerful, fast, lightweight, embeddable scripting language.  from Brazil (PUC-Rio) since 1993  Open Source, but closed development  A core team (academic)  Roberto Ierusalimschy  Luiz Henrique de Figueiredo  Waldemar Celes  MIT License  A mailing list since 1997  lastest Workshop on September 8–9, 2011 fperrad@OSDC.fr2011
  • 3. History of recent releases fperrad@OSDC.fr2011
  • 4. Lua is small  Reference Manual  < 100 pages  Grammar EBNF  1 page  Code size : Sloccount -> 12.5 KLoC of C  Binary ~150 kB  8 types  nil, boolean, number, string, function, userdata, thread, table  21 keywords  No builtin function,  only standard libraries fperrad@OSDC.fr2011
  • 5. Lua is portable  Only C89  Linux, OSX, Windows  Android, iOS  Corona SDK  eLua runs on the "bare-metal"  LEGO Mindstorm NXT  … fperrad@OSDC.fr2011
  • 6. Alternate Implementations  LuaJIT  Very fast, full compatible  LLVM-Lua  Mochalua  Java JME  Jill  Java JME, JSE fperrad@OSDC.fr2011
  • 7. Lua is powerful  function as first class  closure  exception (as library)  coroutine (as library)  iterator  regex (with its own dialect)  some OO mechanisms (prototype based)  tail call fperrad@OSDC.fr2011
  • 8. Factorial - Loop function factorial (n) local a = 1 for i = 1, n, 1 do a = a * i end return a end print(factorial(7)) --> 5040 fperrad@OSDC.fr2011
  • 9. Factorial – recursive function factorial (n) if n == 0 then return 1 else return n * factorial(n-1) end end print(factorial(7)) --> 5040 fperrad@OSDC.fr2011
  • 10. Factorial - Iter function factorial (n) local function iter (prod, cnt) if cnt > n then return prod else return iter(cnt*prod, cnt+1) end end return iter(1, 1) end print(factorial(7)) --> 5040 fperrad@OSDC.fr2011
  • 11. Fibonacci - iterator local function fibo_iterator () local x, y = 0, 1 return function () local res = x x, y = y, x+y return res end end for v in fibo_iterator() do print(v) if v >= 144 then break end end fperrad@OSDC.fr2011
  • 12. Fibonacci - Coroutine local function fibo_generator () local x, y = 0, 1 while true do coroutine.yield(x) x, y = y, x+y end end local function fibo_iterator () return coroutine.wrap(fibo_generator) end for v in fibo_iterator() do print(v) if v >= 144 then break end end fperrad@OSDC.fr2011
  • 13. Fibonacci – metamethods local fibo = setmetatable({ [0] = 0, [1] = 1, }, { __index = function (t, n) local res = t[n-1] + t[n-2] t[n] = res -- memoize return res end, __call = function (t, n) return t[n] end, }) for i = 0, 12 do print(fibo(i)) end fperrad@OSDC.fr2011
  • 14. Lua is embeddable / extensible  Designed to be integrated with software writen in C  C API  Comprehensible  Well documented  Stack model  All standard libraries are built with  Userdata is a core type and allows metatable/metamethods fperrad@OSDC.fr2011
  • 15. Lua Module Land / Heterogenority  Build system  nothing  Makefile  CMake  Documentation  LuaDoc : à la JavaDoc  LuaPOD : with Perl  QA – Test  assert  lunit : à la xUnit  Lunity  lua-TestMore : à la Perl (Test Anything Protocol)  Packaging / Deployment  LuaDist (CMake)  LuaRocks fperrad@OSDC.fr2011
  • 16. A rockspec sample (plain Lua) package = 'lua-CodeGen' version = '0.2.2-1' source = { url = 'http://cloud.github.com/downloads/fperrad/lua-CodeGen/lua-codegen-0.2.2.tar.gz', md5 = '782a40b6ac55ee3077e10f302e301706', dir = 'lua-CodeGen-0.2.2', } description = { summary = "a template engine", detailed = [[ lua-CodeGen is a "safe" template engine. lua-CodeGen enforces a strict Model-View separation. lua-CodeGen allows to split template in small chunk, and encourages the reuse of them by inheri lua-CodeGen is not dedicated to HTML, it could generate any kind of textual code. ]], homepage = 'http://fperrad.github.com/lua-CodeGen', maintainer = 'Francois Perrad', license = 'MIT/X11' } dependencies = { 'lua >= 5.1', 'lua-testmore >= 0.2.3', } build = { type = 'builtin', modules = { ['CodeGen'] = 'src/CodeGen.lua', ['CodeGen.Graph'] = 'src/CodeGen/Graph.lua', }, copy_directories = { 'doc', 'test' }, } fperrad@OSDC.fr2011
  • 17. Binding modules  LuaSocket : socket, http, smtp  LuaSec : https  LuaPOSIX  LuaExpat : XML  LuaSQL : mysql, postgres, sqlite, …  wxLua : wxWidget  LuaGnome : GTK  LuaZMQ  … fperrad@OSDC.fr2011
  • 18. Other modules / projects  Kepler : web development platform  Orbit : an MVC web framework  WSAPI : à la WSGI, Rack, PSGI/Plack  Sputnik : a wiki engine  Lpeg : Parsing Expression Grammars  LuaJSON  Lua Lanes - multithreading in Lua  OiL : an Object Request Broker (CORBA)  … fperrad@OSDC.fr2011
  • 19. Use case : textadept  Textadept is a fast, minimalist, and ridiculously extensible text editor for Linux, Mac OSX, and Windows  Lead dev : Mitchell  started on 2007, 1.0 on Jan 2009  2 KLoC of C + 6 KLoc of Lua  Textadept 4.0 embeds  Lua 5.1.4  LPeg 0.9  LuaFileSystem 1.4.1  Scintilla 2.28 / GTK+  MIT License fperrad@OSDC.fr2011
  • 20. Use case : wireshark  Wireshark (Ethereal) is the world's foremost network protocol analyzer  > 2 MLoC of C  Lua can be used to write dissectors, post-dissectors and taps.  Lua introduced around 0.99.4  GPL License fperrad@OSDC.fr2011
  • 21. Use case : LuaTeX  LuaTeX is an extended version of pdfTeX using Lua as an embedded scripting language.  started on 2007  source size  300 KLoC of C  200 KLoc of C++  10 KLoC of Lua  GPL License fperrad@OSDC.fr2011
  • 22. Use case : awesome  awesome is an extensible, highly configurable window manager for X.  started on 2007  10 KLoC of C + 7 KLoC of Lua  It's extremely fast, small, dynamic and heavily extensible using the Lua programming language.  GPL License fperrad@OSDC.fr2011
  • 23. Use case : Redis  Redis is an open-source, networked, in- memory, persistent, journaled, key-value data store  Lead dev : antirez  started on 2009  30 KLoC of C  Scripting branch released on May 2011  Server-side scripting with Lua  Easy to embed, and FAST  scripting.c : 500 LoC  will available with Redis 2.6  License : BSD fperrad@OSDC.fr2011
  • 24. Sponsors  Adobe  Photoshop Lightroom  40% is written in Lua  Penlight : A Portable Lua Library  The workshop 2005 held at Adobe’s headquarters in San José, California  SocialMediaPress  CSTUG  Océ  Printer, copier, plotter  The workshop 2006 held at Océ's R&D department in Venlo, The Netherlands fperrad@OSDC.fr2011
  • 25. Philosophy of Lua  Mechanisms instead of policies  Zen of Lua :  Doing more with less. fperrad@OSDC.fr2011
  • 26. Conclusion  An embeddable scripting language that is simple, efficient, portable and lightweight  supports several paradigm of programming :  procedural  Object-Oriented  functional  data-driven fperrad@OSDC.fr2011
  • 27. Bibliography / Webography  www.lua.org  the Lua 5.1 Reference Manual  www.luafaq.org  http://lua-users.org/wiki/  The evolution of Lua  Small is Beautiful: the design of Lua  Lua Short Reference  Programming in Lua  Lua programming Gems  LuaForge (frozen since 2009) fperrad@OSDC.fr2011