SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Script up your application
with Lua!
OpenWest 2014
Ryan Erickson
http://www.untestedhacks.com
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
Why: Size
• To embed, hook to a few functions.
• Small as < 100kb DLL/LIB
• Runs on mobile / embedded devices and
platforms
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
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
Why: Safety
• Lua code runs in a sandbox.
• Embedder chooses which modules to expose.
• Host application can provide APIs / primitives
to Lua engine.
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
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
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
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
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
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
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
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
‘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!
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
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.
Questions?
Ryan Erickson
ryan@untestedhacks.com
• Resources:
– http://lua.org
– http://lua.org/pil
– http://lua-users.org/wiki/LuaShortReference

Weitere ähnliche Inhalte

Andere mochten auch

Nginx+lua在阿里巴巴的使用
Nginx+lua在阿里巴巴的使用Nginx+lua在阿里巴巴的使用
Nginx+lua在阿里巴巴的使用OpenRestyCon
 
淺入淺出 GDB
淺入淺出 GDB淺入淺出 GDB
淺入淺出 GDBJim Chang
 
Gdb tutorial-handout
Gdb tutorial-handoutGdb tutorial-handout
Gdb tutorial-handoutSuraj Kumar
 
Perl在nginx里的应用
Perl在nginx里的应用Perl在nginx里的应用
Perl在nginx里的应用琛琳 饶
 
基于OpenResty的百万级长连接推送
基于OpenResty的百万级长连接推送基于OpenResty的百万级长连接推送
基于OpenResty的百万级长连接推送OpenRestyCon
 
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
 
高性能Web服务器Nginx及相关新技术的应用实践
高性能Web服务器Nginx及相关新技术的应用实践高性能Web服务器Nginx及相关新技术的应用实践
高性能Web服务器Nginx及相关新技术的应用实践rewinx
 
Using ngx_lua / lua-nginx-module in pixiv
Using ngx_lua / lua-nginx-module in pixivUsing ngx_lua / lua-nginx-module in pixiv
Using ngx_lua / lua-nginx-module in pixivShunsuke Michii
 
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明National Cheng Kung University
 
Load balancing in the SRE way
Load balancing in the SRE wayLoad balancing in the SRE way
Load balancing in the SRE wayShawn Zhu
 
Microservices & API Gateways
Microservices & API Gateways Microservices & API Gateways
Microservices & API Gateways Kong Inc.
 
C/C++调试、跟踪及性能分析工具综述
C/C++调试、跟踪及性能分析工具综述C/C++调试、跟踪及性能分析工具综述
C/C++调试、跟踪及性能分析工具综述Xiaozhe Wang
 
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsTIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsXiaozhe Wang
 

Andere mochten auch (16)

Nginx+lua在阿里巴巴的使用
Nginx+lua在阿里巴巴的使用Nginx+lua在阿里巴巴的使用
Nginx+lua在阿里巴巴的使用
 
淺入淺出 GDB
淺入淺出 GDB淺入淺出 GDB
淺入淺出 GDB
 
Gdb tutorial-handout
Gdb tutorial-handoutGdb tutorial-handout
Gdb tutorial-handout
 
Learn C Programming Language by Using GDB
Learn C Programming Language by Using GDBLearn C Programming Language by Using GDB
Learn C Programming Language by Using GDB
 
Perl在nginx里的应用
Perl在nginx里的应用Perl在nginx里的应用
Perl在nginx里的应用
 
基于OpenResty的百万级长连接推送
基于OpenResty的百万级长连接推送基于OpenResty的百万级长连接推送
基于OpenResty的百万级长连接推送
 
Nginx-lua
Nginx-luaNginx-lua
Nginx-lua
 
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
 
高性能Web服务器Nginx及相关新技术的应用实践
高性能Web服务器Nginx及相关新技术的应用实践高性能Web服务器Nginx及相关新技术的应用实践
高性能Web服务器Nginx及相关新技术的应用实践
 
Using ngx_lua / lua-nginx-module in pixiv
Using ngx_lua / lua-nginx-module in pixivUsing ngx_lua / lua-nginx-module in pixiv
Using ngx_lua / lua-nginx-module in pixiv
 
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
 
Load balancing in the SRE way
Load balancing in the SRE wayLoad balancing in the SRE way
Load balancing in the SRE way
 
Microservices & API Gateways
Microservices & API Gateways Microservices & API Gateways
Microservices & API Gateways
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
 
C/C++调试、跟踪及性能分析工具综述
C/C++调试、跟踪及性能分析工具综述C/C++调试、跟踪及性能分析工具综述
C/C++调试、跟踪及性能分析工具综述
 
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsTIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
 

Ähnlich wie Script up your application with Lua! -- RyanE -- OpenWest 2014

JS introduction
JS introductionJS introduction
JS introductionYi Tseng
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersDiego Freniche Brito
 
Benefits/tutorial of Lua in games
Benefits/tutorial of Lua in gamesBenefits/tutorial of Lua in games
Benefits/tutorial of Lua in gamesaction.vn
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 
Lua London Meetup 2013
Lua London Meetup 2013Lua London Meetup 2013
Lua London Meetup 2013Cloudflare
 
High Performance Drupal
High Performance DrupalHigh Performance Drupal
High Performance DrupalJeff Geerling
 
Leonid Vasilyev "Building, deploying and running production code at Dropbox"
Leonid Vasilyev  "Building, deploying and running production code at Dropbox"Leonid Vasilyev  "Building, deploying and running production code at Dropbox"
Leonid Vasilyev "Building, deploying and running production code at Dropbox"IT Event
 
Working Effectively with Routine Tasks
Working Effectively with Routine TasksWorking Effectively with Routine Tasks
Working Effectively with Routine TasksIvan Katunou
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Henry S
 
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
 
Эффективная работа с рутинными задачами
Эффективная работа с рутинными задачамиЭффективная работа с рутинными задачами
Эффективная работа с рутинными задачамиCOMAQA.BY
 
Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IDUSPviz
 
Python and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementPython and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementLaurent Leturgez
 
Rapid Application Development using Ruby on Rails
Rapid Application Development using Ruby on RailsRapid Application Development using Ruby on Rails
Rapid Application Development using Ruby on RailsSimobo
 
HTTP cache: keeping it fresh
HTTP cache: keeping it freshHTTP cache: keeping it fresh
HTTP cache: keeping it freshDavid de Boer
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinayViplav Jain
 
Speed up large-scale ML/DL offline inference job with Alluxio
Speed up large-scale ML/DL offline inference job with AlluxioSpeed up large-scale ML/DL offline inference job with Alluxio
Speed up large-scale ML/DL offline inference job with AlluxioAlluxio, Inc.
 

Ähnlich wie Script up your application with Lua! -- RyanE -- OpenWest 2014 (20)

2015 555 kharchenko_ppt
2015 555 kharchenko_ppt2015 555 kharchenko_ppt
2015 555 kharchenko_ppt
 
JS introduction
JS introductionJS introduction
JS introduction
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented Programmers
 
Benefits/tutorial of Lua in games
Benefits/tutorial of Lua in gamesBenefits/tutorial of Lua in games
Benefits/tutorial of Lua in games
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
Lua London Meetup 2013
Lua London Meetup 2013Lua London Meetup 2013
Lua London Meetup 2013
 
High Performance Drupal
High Performance DrupalHigh Performance Drupal
High Performance Drupal
 
How do event loops work in Python?
How do event loops work in Python?How do event loops work in Python?
How do event loops work in Python?
 
Leonid Vasilyev "Building, deploying and running production code at Dropbox"
Leonid Vasilyev  "Building, deploying and running production code at Dropbox"Leonid Vasilyev  "Building, deploying and running production code at Dropbox"
Leonid Vasilyev "Building, deploying and running production code at Dropbox"
 
Working Effectively with Routine Tasks
Working Effectively with Routine TasksWorking Effectively with Routine Tasks
Working Effectively with Routine Tasks
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
 
Use of Lua in Lab Devices
Use of Lua in Lab DevicesUse of Lua in Lab Devices
Use of Lua in Lab Devices
 
Эффективная работа с рутинными задачами
Эффективная работа с рутинными задачамиЭффективная работа с рутинными задачами
Эффективная работа с рутинными задачами
 
C++ overview
C++ overviewC++ overview
C++ overview
 
Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part I
 
Python and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementPython and Oracle : allies for best of data management
Python and Oracle : allies for best of data management
 
Rapid Application Development using Ruby on Rails
Rapid Application Development using Ruby on RailsRapid Application Development using Ruby on Rails
Rapid Application Development using Ruby on Rails
 
HTTP cache: keeping it fresh
HTTP cache: keeping it freshHTTP cache: keeping it fresh
HTTP cache: keeping it fresh
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
 
Speed up large-scale ML/DL offline inference job with Alluxio
Speed up large-scale ML/DL offline inference job with AlluxioSpeed up large-scale ML/DL offline inference job with Alluxio
Speed up large-scale ML/DL offline inference job with Alluxio
 

Kürzlich hochgeladen

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 

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

  • 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