Real Scripting with Lua - LASER...
Transcript of Real Scripting with Lua - LASER...
![Page 1: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/1.jpg)
Real Scripting with Lua
Roberto Ierusalimschy
![Page 2: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/2.jpg)
2
Uses of Lua
● Widely used in some niches● not a “web language”
● Embedded systems● Scripting for applications● Games
![Page 3: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/3.jpg)
3
Embedded systemsTVs (Samsung), routers (Cisco), keyboards (Logitech), printers (Olivetti, Océ),set-top boxes (Ginga, Verizon), M2M devices (Sierra Wireless, Koneki), calculators (TI-Nspire), mobiles (Huawei), …
Scripting for applicationsWireshark, Snort, Nmap, VLC Media Player, lighttpd, LuaTeX, Flame, …
![Page 4: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/4.jpg)
4
Slashdot: News for nerds, Feb 1, 2012:
“Wikipedia Chooses Lua As Its New template language”
![Page 5: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/5.jpg)
5
Adobe Lightroommore than one milion lines of Lua code
![Page 6: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/6.jpg)
6
1
![Page 7: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/7.jpg)
7
![Page 8: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/8.jpg)
8
What About Lua?
● Yet another scripting language● Goals
● Emphasis on scripting● Portable● Small● Simple● Efficient
![Page 9: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/9.jpg)
9
Scripting
● Scripting language x dynamic language● scripting emphasizes inter-language communication
● Program written in two languages● a scripting language and a system language
● System language implements the hard parts of the application● algorithms, data structures● little change
● Scripting glues together the hard parts● flexible, easy to change
![Page 10: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/10.jpg)
10
Scripting in Grim Fandango[The engine] doesn't know anything about adventure
games, or talking, or puzzles, or anything else that makes Grim Fandango the game it is. It just knows how to render a set from data that it's loaded and draw characters in that set.[…]
The real heroes in the development of Grim Fandango were the scripters. They wrote everything from how to respond to the controls to dialogs to camera scripts to door scripts to the in-game menus and options screens. […]
A TREMENDOUS amount of this game is written in Lua. The engine, including the Lua interpreter, is really just a small part of the finished product.
Bret Mogilefsky
![Page 11: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/11.jpg)
11
Lua and Scripting
● Lua is implemented as a library● Lua has been designed for scripting● Good for embedding and extending● Embedded in C/C++, Java, Fortan, C#, Perl,
Ruby, Python, etc.
![Page 12: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/12.jpg)
12
Portablility
● Runs virtually everywhere● Symbian, Nintendo DS, PSP, PS3, Android, iOS,
IBM z/OS, etc.● Written in ANSI C
● Kernel is a free-standing application● Can run inside the OS kernel● Can run over the “bare metal”
![Page 13: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/13.jpg)
13
Size
![Page 14: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/14.jpg)
14
Simplicity
Reference manual with 100 pages
(spine)
Documents the language, the C API, and the standard libraries
![Page 15: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/15.jpg)
15
Efficiency
● Several benchmarks show Lua among the fastest languages in the realm of interpreted languages with dynamic typing
● Mix of simplicity and some new techniques● LuaJIT
![Page 16: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/16.jpg)
16
Aren't these goals about the implementation, not about the language?
![Page 17: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/17.jpg)
17
Aren't these goals about the implementation, not about the language?
No.
![Page 18: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/18.jpg)
18
Aren't these goals about the implementation, not about the language?
No.
(Maybe, but big impact on language design.)
![Page 19: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/19.jpg)
19
● Emphasis on scripting● few syntactical constructions● function-style
● Portable● few standard libraries● even fewer primitive operations
● Small, Simple● minimalistic design
● Efficient
Impact on Design
![Page 20: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/20.jpg)
20
Lectures
● Introduction about Lua, scripting● Tables● Modules and Objects● Coroutines● API Lua-C
![Page 21: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/21.jpg)
21
www.lua.org
![Page 22: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/22.jpg)
22
Books
![Page 23: Real Scripting with Lua - LASER Foundationlaser.inf.ethz.ch/2012/slides/Ierusalimschy/intro-0.pdf · 2 Uses of Lua Widely used in some niches not a “web language” Embedded systems](https://reader031.fdocuments.in/reader031/viewer/2022022110/5c0e497b09d3f258548cc96f/html5/thumbnails/23.jpg)
23
Lua: cute, efficient, and becoming very
trendy
If programming languages were cars
http://machinegestalt.posterous.com/ifprogramminglanguageswerecars
If programming languages were religions
Lua would be Wicca - A pantheistic language that can easily be adapted for different cultures and locations. Its code is very liberal, and allows for the use of techniques that might be described as magical by those used to more traditional languages. It has a strong connection to the moon.
http://blog.aegisub.org/2008/12/ifprogramminglanguageswerereligions.html