SlideShare a Scribd company logo
Lua 
A powerful, light-weight scripting language
Introduction 
 Lua name 
 Support for 
◦ Object-oriented programming 
◦ Functional programming 
◦ Data-driven programming 
 Embedding program 
 Interpreted Language
Introduction 
 is implemented in pure ANSI C and 
compiles 
 Strongly integrated with C and C++ 
 Cross-platform 
 Good performance 
◦ To claim to be "as fast as Lua" 
 Multi-thread 
◦ Coroutines 
 Easy learning curve. 
 Free
Uses 
 Angry Bird 
 Simcity 4 
 World of Warcraft 
 Adobe Photoshop Lightroom 
 Other sort of applications.
IDE 
 LuaEdit 
◦ Download 
 Eclipse Plug-in 
◦ Lua Development Tools
Hello World! 
 Download Lua 
 Execute Lua 
 Interpreter 
 Print(‘Hello World’);
Values and Type 
 Lua is dynamically typed language. 
 Types 
◦ Nil 
◦ Boolean 
◦ Number 
◦ String 
◦ Function 
◦ Userdata 
◦ Thread 
◦ Table 
 Values 
◦ Initial : nil 
◦ Boolean => nil/false : false, others : true 
◦ Number : double-precision floating-point. 
◦ String : ‘’, “”, [[]], [==[ ]==]
Comment 
 Single comment 
◦ -- 
 Block comment 
◦ --[[ 
◦ ]]--
Variable 
 3 kinds of Scope 
◦ Global 
 _G 
◦ Local 
 local 
◦ Table 
 self 
 Multiple assignment 
◦ a,b = 1,2 
◦ a,b = b,a
The type “Table” 
 Like 
◦ ActionScript Array 
◦ Php Array 
◦ Perl Hash 
◦ Map 
 Indexed Array 
◦ Index is start from 1 
 Associative Array 
◦ Nil and NaN both cannot be as a key 
 Get length : # operator 
 Constructor 
◦ a = {} 
◦ a = { prop1, prop2 } => a[1] = prop1, a[2] = prop2 
◦ a = { prop = “test” } => a[“prop”] = “test” 
◦ a = { [f(x)] = 2 } => a[f(x)] = 2
Funciton 
 Definition 
function func_name ([args]) 
do something 
end 
method: 
function a.b.c:func_name(self, body) body end 
anonymous: 
function() 
do something 
end 
 call function 
• func_name(args); 
• table.func_name(agrs)
Function 
 Call method 
• table:func_name(args) 
 Result return 
◦ Able to return multiple result 
• return a; 
• return a,b; 
• return a or b
Logical Operator 
 Not 
 And 
 Or 
• not(a==1) 
• return a and b 
• return func1() and func2() 
• return a or b 
• return func1() or func2()
Statements 
 if exp then block {elseif exp then 
block} [else block] end 
 while exp do block end 
 repeat block until exp
For statement 
 numeric 
◦ work with number calculation 
• for I = 1, 10 do block end 
• for I = 1, 10, 2 do block end 
• for I = 1, #(table1) do block end 
 generic 
◦ work with iterators, stop when value is nil 
• for namelist in explist do block end 
• for k, v in pairs(table1) do block end 
• for k, v in ipairs(table1) do block end
Metatables and Metamethods 
 Every value has metatable and 
metamethod 
 The key of metatable => event 
 The value of metatable => 
metamethod 
 getmetatable -> get the metatable of 
any value 
 setmetatable -> set the metatable of 
table
Metatables and Metamethods 
 Add 
 Sub 
 Mul 
 Mod 
 Pow 
 Unm 
 Concat 
 Len 
 Eq 
 Lt 
 Le 
 Index 
 Newindex 
 Call
For OOP purpose 
Person={} 
function Person:new(p) 
local obj = p 
if (obj == nil) then 
obj = {name="ChenHao", age=37, handsome=true} 
end 
self.__index = self 
return setmetatable(obj, self) 
end 
function Person:toString() 
return self.name .." : ".. self.age .." : ".. (self.handsome and "handsome" or "ugly") 
end
Modules 
 require(‘hello’); 
◦ package.loaded to record which module is 
loaded 
 dofile(‘hello.lua’); 
 loadfile(‘hello.lua’);
Standard Libraries 
 Basic library 
 Coroutine library 
 Package library 
 String manipulation 
 Table manipulation 
 Mathematical functions 
 Bitwise operations 
 Input and Output 
 Etc.
Error Handling 
 Throw exception 
◦ The error function 
 Catch exception 
◦ pcall or xpcall
Garbage Collection 
 Auto memory management. 
 2 indexes to determine GC 
◦ The garbage-collector pause 
◦ The garbage-collector step multiplier

More Related Content

PPT
jimmy hacking (at) Microsoft
PDF
Reactive Programming in the Browser feat. Scala.js and PureScript
PDF
Building a Tagless Final DSL for WebGL
PDF
05. haskell streaming io
PPT
Groovy
PPTX
Столпы функционального программирования для адептов ООП, Николай Мозговой
PDF
All Aboard The Scala-to-PureScript Express!
PPT
Overloading
jimmy hacking (at) Microsoft
Reactive Programming in the Browser feat. Scala.js and PureScript
Building a Tagless Final DSL for WebGL
05. haskell streaming io
Groovy
Столпы функционального программирования для адептов ООП, Николай Мозговой
All Aboard The Scala-to-PureScript Express!
Overloading

What's hot (20)

PDF
Introduction to kotlin
PDF
Taking Kotlin to production, Seriously
PPT
Operator overloading
PDF
GR8Conf 2011: GPars
PDF
Kotlin boost yourproductivity
PDF
Intro to Kotlin
PPT
Operator Overloading
PDF
MTL Versus Free
PDF
Orthogonal Functional Architecture
PPT
The Kotlin Programming Language
PPTX
Iron Languages - NYC CodeCamp 2/19/2011
PPTX
Introduction to kotlin + spring boot demo
PDF
Swift and Kotlin Presentation
PDF
Clojure made-simple - John Stevenson
PPTX
Compile time polymorphism
PDF
Pune Clojure Course Outline
PDF
Droidcon Poland - From Kotlin to Machine Code
PDF
Cocoaheads Meetup / Alex Zimin / Swift magic
PDF
Halogen: Past, Present, and Future
PDF
Writing a compiler in go
Introduction to kotlin
Taking Kotlin to production, Seriously
Operator overloading
GR8Conf 2011: GPars
Kotlin boost yourproductivity
Intro to Kotlin
Operator Overloading
MTL Versus Free
Orthogonal Functional Architecture
The Kotlin Programming Language
Iron Languages - NYC CodeCamp 2/19/2011
Introduction to kotlin + spring boot demo
Swift and Kotlin Presentation
Clojure made-simple - John Stevenson
Compile time polymorphism
Pune Clojure Course Outline
Droidcon Poland - From Kotlin to Machine Code
Cocoaheads Meetup / Alex Zimin / Swift magic
Halogen: Past, Present, and Future
Writing a compiler in go
Ad

Similar to Lua Study Share (20)

PPTX
C++ theory
PPT
Groovy presentation
PDF
Scala is java8.next()
PPTX
Functional and code coverage verification using System verilog
PPTX
Java For Automation
PDF
PofEAA and SQLAlchemy
PDF
Swift, functional programming, and the future of Objective-C
PDF
07 control+structures
PPTX
JavaScript (without DOM)
PPTX
Programming in java basics
PDF
JavaScript in 2016
PPTX
JavaScript in 2016 (Codemotion Rome)
PPT
L4 functions
PDF
A Recovering Java Developer Learns to Go
PPTX
Programming picaresque
PPTX
Make BDD great again
PDF
Denis Lebedev, Swift
PPTX
Java gets a closure
PDF
Scala for Java Developers
C++ theory
Groovy presentation
Scala is java8.next()
Functional and code coverage verification using System verilog
Java For Automation
PofEAA and SQLAlchemy
Swift, functional programming, and the future of Objective-C
07 control+structures
JavaScript (without DOM)
Programming in java basics
JavaScript in 2016
JavaScript in 2016 (Codemotion Rome)
L4 functions
A Recovering Java Developer Learns to Go
Programming picaresque
Make BDD great again
Denis Lebedev, Swift
Java gets a closure
Scala for Java Developers
Ad

Recently uploaded (20)

PPTX
Transform Your Business with a Software ERP System
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
top salesforce developer skills in 2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
medical staffing services at VALiNTRY
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
System and Network Administration Chapter 2
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Transform Your Business with a Software ERP System
Wondershare Filmora 15 Crack With Activation Key [2025
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Reimagine Home Health with the Power of Agentic AI​
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
top salesforce developer skills in 2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Operating system designcfffgfgggggggvggggggggg
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
medical staffing services at VALiNTRY
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
System and Network Administration Chapter 2
Softaken Excel to vCard Converter Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Odoo Companies in India – Driving Business Transformation.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Odoo POS Development Services by CandidRoot Solutions
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx

Lua Study Share

  • 1. Lua A powerful, light-weight scripting language
  • 2. Introduction  Lua name  Support for ◦ Object-oriented programming ◦ Functional programming ◦ Data-driven programming  Embedding program  Interpreted Language
  • 3. Introduction  is implemented in pure ANSI C and compiles  Strongly integrated with C and C++  Cross-platform  Good performance ◦ To claim to be "as fast as Lua"  Multi-thread ◦ Coroutines  Easy learning curve.  Free
  • 4. Uses  Angry Bird  Simcity 4  World of Warcraft  Adobe Photoshop Lightroom  Other sort of applications.
  • 5. IDE  LuaEdit ◦ Download  Eclipse Plug-in ◦ Lua Development Tools
  • 6. Hello World!  Download Lua  Execute Lua  Interpreter  Print(‘Hello World’);
  • 7. Values and Type  Lua is dynamically typed language.  Types ◦ Nil ◦ Boolean ◦ Number ◦ String ◦ Function ◦ Userdata ◦ Thread ◦ Table  Values ◦ Initial : nil ◦ Boolean => nil/false : false, others : true ◦ Number : double-precision floating-point. ◦ String : ‘’, “”, [[]], [==[ ]==]
  • 8. Comment  Single comment ◦ --  Block comment ◦ --[[ ◦ ]]--
  • 9. Variable  3 kinds of Scope ◦ Global  _G ◦ Local  local ◦ Table  self  Multiple assignment ◦ a,b = 1,2 ◦ a,b = b,a
  • 10. The type “Table”  Like ◦ ActionScript Array ◦ Php Array ◦ Perl Hash ◦ Map  Indexed Array ◦ Index is start from 1  Associative Array ◦ Nil and NaN both cannot be as a key  Get length : # operator  Constructor ◦ a = {} ◦ a = { prop1, prop2 } => a[1] = prop1, a[2] = prop2 ◦ a = { prop = “test” } => a[“prop”] = “test” ◦ a = { [f(x)] = 2 } => a[f(x)] = 2
  • 11. Funciton  Definition function func_name ([args]) do something end method: function a.b.c:func_name(self, body) body end anonymous: function() do something end  call function • func_name(args); • table.func_name(agrs)
  • 12. Function  Call method • table:func_name(args)  Result return ◦ Able to return multiple result • return a; • return a,b; • return a or b
  • 13. Logical Operator  Not  And  Or • not(a==1) • return a and b • return func1() and func2() • return a or b • return func1() or func2()
  • 14. Statements  if exp then block {elseif exp then block} [else block] end  while exp do block end  repeat block until exp
  • 15. For statement  numeric ◦ work with number calculation • for I = 1, 10 do block end • for I = 1, 10, 2 do block end • for I = 1, #(table1) do block end  generic ◦ work with iterators, stop when value is nil • for namelist in explist do block end • for k, v in pairs(table1) do block end • for k, v in ipairs(table1) do block end
  • 16. Metatables and Metamethods  Every value has metatable and metamethod  The key of metatable => event  The value of metatable => metamethod  getmetatable -> get the metatable of any value  setmetatable -> set the metatable of table
  • 17. Metatables and Metamethods  Add  Sub  Mul  Mod  Pow  Unm  Concat  Len  Eq  Lt  Le  Index  Newindex  Call
  • 18. For OOP purpose Person={} function Person:new(p) local obj = p if (obj == nil) then obj = {name="ChenHao", age=37, handsome=true} end self.__index = self return setmetatable(obj, self) end function Person:toString() return self.name .." : ".. self.age .." : ".. (self.handsome and "handsome" or "ugly") end
  • 19. Modules  require(‘hello’); ◦ package.loaded to record which module is loaded  dofile(‘hello.lua’);  loadfile(‘hello.lua’);
  • 20. Standard Libraries  Basic library  Coroutine library  Package library  String manipulation  Table manipulation  Mathematical functions  Bitwise operations  Input and Output  Etc.
  • 21. Error Handling  Throw exception ◦ The error function  Catch exception ◦ pcall or xpcall
  • 22. Garbage Collection  Auto memory management.  2 indexes to determine GC ◦ The garbage-collector pause ◦ The garbage-collector step multiplier