Your SlideShare is downloading. ×
0
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Script up your application with Lua! -- RyanE -- OpenWest 2014
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Script up your application with Lua! -- RyanE -- OpenWest 2014

4,809

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
4,809
On Slideshare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Script up your application with Lua! OpenWest 2014 Ryan Erickson http://www.untestedhacks.com
  • 2. History of Lua • Lua.org • Created in 1993 at PUC-RIO • Predecessors: DEL and Sol • Lua == Moon, not an acronym. • Focus: – Simplicity for non-programmer audience – Portability – Designed to be easily embedded, extended – Clean ANSI C code – Garbage Collected
  • 3. Why: Size • To embed, hook to a few functions. • Small as < 100kb DLL/LIB • Runs on mobile / embedded devices and platforms
  • 4. Why: Performance • Interpreted Lua is generally faster than Python, Ruby, Perl, and PHP • Not fast enough? LuaJIT! • LuaJIT is in C++ / Java 6 territory. – luajit.org
  • 5. Why: Momentum • Used extensively in games • Adobe Lightroom (60% lua) and Photoshop • First interpreted language allowed on iOS • Angry Birds • World of Warcraft • Wikipedia lists over 100 games using Lua • Nginx / OpenResty • Control4 (us!) • Many, Many more
  • 6. Why: Safety • Lua code runs in a sandbox. • Embedder chooses which modules to expose. • Host application can provide APIs / primitives to Lua engine.
  • 7. Control4’s use case • Existing (C++) Driver architecture • XML Driver ‘document’ + compiled driver • Considered Python, JavaScript, and Lua • Embedded Lua engine into C++ driver • Embedded Lua code into the XML driver – CDATA (non-XML) section read by driver on startup
  • 8. Intro: General • Dynamically typed • Whitespace is not significant. – Spaces, linebreaks, tabs – use what you like • Semicolons not required, discouraged • -- single-line comment • Variables are global by default, ‘local’ keyword
  • 9. Intro: Types • Few types: number, string, boolean, nil, table, function, u serdata • Numbers are double by default • Can represent Floats *and* Integers • No i++, no i+=2. i = i + 1
  • 10. Intro: Types • Strings: – Single-quote / Double-quote / backslash to escape – String concatenation uses .. not + • nil: – Empty value – Evaluates to ‘false’ – Frees item for garbage collection
  • 11. Intro: Tables • Lua Tables – Simultaneous array and hashmap • a = ,“apple”, “banana”, “orange”- • b = {lua = “cool”, java = “sucks”, fred = 3} • c = a • print(c[3], b.fred, b.*“java”+, a.grape) • orange 3 sucks nil
  • 12. Intro: Functions • Functions are first-class objects function add(a, b) print(a + b) end multiply = function(a, b) print(a * b) end plus = add plus(3, 5) -> 8
  • 13. Control Structures if … then … elseif .. else .. End do -- block definition… print(“one”) print(“two”) end for i = 1, 10 do print(i) end for k,v in pairs(,“apple”, “banana”-) do print(k,v) end
  • 14. Control Structures Cont’d i = 0 while i < 10 do print(i) i = i + 1 End repeat i = i - 1 print(i) until i < 0
  • 15. ‘C Programmer’ Hangups • No curly braces… What’s this ‘begin…end’ business? • No +=, ++ • Not Equals is not !=, it’s ~=. • Not is not ~, it’s not! • Arrays start at 1 • #array is not always ‘right’ • Get past the hangups, and Lua is a fantastic little language!
  • 16. C Interface API • Set of functions that allow C to interact with Lua – Functions to read and write Lua global variables – Functions to call Lua functions – Functions to register C functions within Lua • Stack-based parameter passing
  • 17. Demo • C IRC Bot (~100 lines of C code), featureless • Lua 5.1 source, previously compiled • ~50 lines of Lua Integration C code • 9k executable => ~200k with Lua + included libs • Fast turnaround, feature development, etc.
  • 18. Questions? Ryan Erickson ryan@untestedhacks.com • Resources: – http://lua.org – http://lua.org/pil – http://lua-users.org/wiki/LuaShortReference

×