Lua: Tiny Embeddable Scripting that Doesn't Suck

Post on 25-Jan-2017

7.525 views 1 download

Transcript of Lua: Tiny Embeddable Scripting that Doesn't Suck

Lua: Tiny Embeddable Scripting that

Doesn’t Suck

Kyle Cordes

Strange Loop 2010

http://www.flickr.com/photos/mikebaird/4060342528/

About Kyle Cordes

• Blah, Blah, Blah

cat ~/.plan

Learn; (Clojure, at the moment)

Teach; (How to SaaS)

Hire; (Grow Oasis Digital)

Market; (same)

Launch Next Big Thing

Abstract“This talk will show how and WHY to

use Lua (as opposed to the zillion other scripting languages) for embedded scripting inside of larger, non-Lua

projects. Lua is safe, fast, simple, easy to learn, and more popular that you might

expect.”

(What you were sold...)

The 20-minute version

“This talk will show how and WHY to use Lua (as opposed to the zillion other

scripting languages) for embedded scripting inside of larger, non-Lua

projects. Lua is safe, fast, simple, easy to learn, and more popular that you might

expect.”

(What you will get.)

http://www.flickr.com/photos/james_michael_hill/88311128/

Use the Interwebs

http://www.lua.org/

Yet Another Scripting LanguageWhy should we care?

Because LuaDoesn’t Suck

6 Reasons

Jail

http://www.flickr.com/photos/kuzeytac/http://www.flickr.com/photos/8422710@N06/

Lua code runs in a Sandboxhttp://www.flickr.com/photos/engelsrud/158040644/

Safe By Default

Default: no I/O, safe but impotent. Lua doesn’t even have “print” built in.

Host application provides whatever limited set of APIs/primitives are warranted.

Contrast this to Java’s complex security model, for example.

Small

http://www.flickr.com/photos/kentigern/221409419/http://www.flickr.com/photos/andrewscott/577706627/

Lua is Small

To embed, hook to a handful of functions.

As small as <100 KB (DLL/LIB)

Easily runs on small devices or in small apps.

Example: Lua on the iPhonehttp://probablyinteractive.com/2009/10/18/Setting-up-iPhone-Wax.html?

Simple

http://www.flickr.com/photos/benmcleod/44336195/http://www.flickr.com/photos/slightlywinded/66875782/

Lua is Simple

• to use - well suited for small software

• to learn - ~20 keywords, ~20 operators

• to teach - plenty of non-developers use it

Flexible

http://www.flickr.com/photos/wiccked/348866434/http://www.flickr.com/photos/wainwright/351684037/

Lua is Flexible

• Dynamically typed

• First-class functions

• Easy interop

• Written in super-clean C, ports to nearly any platform

• Ample libraries off-the-shelf

Fast

http://www.autoblog.com/photos/pagani-zonda-hh-0/ http://www.flickr.com/photos/kentigern/223140455/

LuaJIT is in C++ / Java6 territory.

http://luajit.org/

Interpreted Lua is generally faster than Python, Ruby,

Perl, and PHP.

http://bit.ly/8RLpoG

http://www.flickr.com/photos/us_army_rolling_along/3342500833/http://www.flickr.com/photos/us_army_rolling_along/4509400870/

http://www.flickr.com/photos/carbonnyc/76463757/s

Momentum

• At least one external IDE• Several published books• Large community

Lua in World of Warcraft

Angry Birds

Wikipedia lists

110games with Lua scripting

(many on the PC,many on consoles,

some on handhelds)

Not Just Games

• Adobe Photoshop Lightroom

• Oasis Digital projects

• Many, many more

Lua == 42 ?

http://www.flickr.com/photos/almostinfamous/3531123548/

The right answer for every scripting need?

At my last venture, we chose JavaScript instead:

1. Better Java Integration

2. Everyone knows JavaScript

3. More tooling, easier sell

kylecordes.com

http://www.flickr.com/photos/thetruthabout/