Upcoming SlideShare
×

Why Lua?

116

Published on

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
116
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
4
0
Likes
0
Embeds 0
No embeds

No notes for slide

Why Lua?

1. 1. Why Lua? A quick intro to Lua for programmers
2. 2. print("hello world") function factorial(number) product = 1 while number > 1 do product = product * number number = number - 1 end return product end -- don't forget to close the block! --[[ strings can be coerced into numbers when needed and vice versa ]]
3. 3. Primitive types ● ● ● ● ● ● ● ● number string nil boolean table function userdata thread
4. 4. Means of abstraction function foo (n) return n+1 end is equivalent to foo = function(n) return n+1 end
5. 5. Means of combination empty = {} -- empty table user = { name="rahmu", organization="LebGeeks" } first_five = {0, 1, 2, 3, 4, 5} mixed_table = {{"hello", "world"}, 5, verbose=true}
6. 6. function insert_elt(elt, set) set[elt] = true end function remove_elt(elt, set) set[elt] = nil end function has_elt(elt, set) return set[elt]
7. 7. ● ● ● head_node = {value= "foo", next=nil} tree_node = {value="bar", left=nil, right=nil} ...
8. 8. Closures function newCounter () local i = 0 return function () -- anonymous function i = i + 1 return i end end c1 = newCounter() print(c1()) --> 1 print(c1()) --> 2 c2 = newCounter() print(c2()) --> 1 print(c1()) --> 3 print(c2()) --> 2
9. 9. Strength ● Ligthweight Python Lua Lines of code ~600k loc ~20k loc Size of the exe 5.5M 220K Compile time ~27 min 5.6 sec
10. 10. ● Blazing fast ● C API ● Portability ● Simplicity
11. 11. Weaknesses ● Weak library ● Very little runtime checks, poor exception handling, ... ● ???
12. 12. Learn Lua ● Programming in Lua - R. Ierusalimschy (http://www.lua.org/pil/) ● Awesome wiki, the briefest introduction to Lua (http://awesome.naquadah.org/wiki/The_briefest_introduction_to_Lua)
1. A particular slide catching your eye?

Clipping is a handy way to collect important slides you want to go back to later.