real scripting with lua - laser...

23
Real Scripting with Lua Roberto Ierusalimschy

Upload: haanh

Post on 10-Dec-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

23

Lua: cute, efficient, and becoming very

trendy

If programming languages were cars

http://machinegestalt.posterous.com/if­programming­languages­were­cars

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/if­programming­languages­were­religions.html