Web development with Lua and Sailor @ GeeCon 2015
-
Upload
etiene-dalcol -
Category
Software
-
view
318 -
download
4
Transcript of Web development with Lua and Sailor @ GeeCon 2015
![Page 1: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/1.jpg)
Web development with Lua Programming Language
Introducing Sailor, a web MVC framework in Lua
Etiene Dalcol @etiene_d
![Page 2: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/2.jpg)
@etiene_d
![Page 3: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/3.jpg)
Sailor!
http://sailorproject.org
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 4: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/4.jpg)
Lua Ladies
http://lualadies.org
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 5: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/5.jpg)
Google Summer of Code
LabLua
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 6: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/6.jpg)
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 7: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/7.jpg)
Advantages
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 8: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/8.jpg)
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 9: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/9.jpg)
better reasons • It looks cool (I heard you could make games with it)
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 10: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/10.jpg)
better reasons • It looks cool (I heard you could make games with it)
• It’s made in my home country(In my university to be more precise)
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 11: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/11.jpg)
better reasons • It looks cool (I heard you could make games with it)
• It’s made in my home country(In my university to be more precise)
• It’s easy to learn
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 12: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/12.jpg)
??
? ?
??
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 13: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/13.jpg)
Lua on the web
• Early stage
• cgilua ~ 1995
• Kepler Project ~ 2003
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 14: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/14.jpg)
“ I have myself developed Web sites with pure C++, Java, C#, PHP, and Python. The easiest way to go was definitely Python. If the libraries existed, Lua would be not quite as easy to use as Python, but probably quite a bit more efficient; I think it would become my first choice... if the libraries existed.” Michael Gogins
“ Recently there was some discussion about mod_lua on the Apache developers mailing list. I mentioned there that I feel Lua could replace PHP as the number one web scripting language if mod_lua were stable (i.e. not still in beta) and it were implemented well (not making some of PHP's mistakes such as putting everything in the global scope with no consistent naming or parameter schemes). I've wanted to use Lua for all the things I currently use PHP for ever since I discovered it.” Rena
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 15: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/15.jpg)
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 16: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/16.jpg)
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 17: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/17.jpg)
Web development with Lua @etiene_d
![Page 18: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/18.jpg)
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 19: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/19.jpg)
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 20: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/20.jpg)
Why?
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 21: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/21.jpg)
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 22: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/22.jpg)
Servers
• Apache: mod_lua
• Nginx: OpenResty
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 23: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/23.jpg)
Servers
Web development with Lua @ GeeCON 2015 @etiene_d
• Apache: mod_lua
• Nginx: OpenResty
![Page 24: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/24.jpg)
Servers
• Apache: mod_lua
• Nginx: OpenResty
• Xavante
• Others
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 25: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/25.jpg)
Frameworks
• Orbit (2007)Least knownNo significant updates since 2010MVC
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 26: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/26.jpg)
Frameworks
• Orbit (2007)Least knownNo significant updates since 2010MVC
• Luvit (2011)Most popularIntense developmentnode.js port 2-4x faster
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 27: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/27.jpg)
Frameworks• Lapis (2012)
Intense developmentMoonscript and LuaVery well documentedTemplaterOpenResty onlyNot MVC
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 28: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/28.jpg)
Frameworks• Lapis (2012)
Intense developmentMoonscript and LuaVery well documentedTemplaterOpenResty onlyNot MVC
• OthersComplicated, abandoned, poorly documented, license issues or I never heard about it...
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 29: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/29.jpg)
Sailor!
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 30: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/30.jpg)
Sailor!
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 31: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/31.jpg)
Sailor!
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 32: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/32.jpg)
Sailor!
0.1 (Venus)
0.2 (Mars)
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 33: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/33.jpg)
What exactly is Sailor?
• It’s an MVC web framework• Completely written in Lua• Compatible with Apache (mod_lua), Nginx (OpenResty),
Mongoose, Xavante and Lwan• Compatible with Linux, Windows and Mac• Compatible with different databases• MIT License• Pre alpha v0.2 (Mars)• 0.3 (Jupiter) will be released TODAY!
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 34: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/34.jpg)
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 35: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/35.jpg)
What (else) is cool about Sailor?• Routing and friendly URLs• Session, cookies, include, redirect…• Lua Pages parsing• Mail sending• Simple Object Relational-Mapping• Validation (valua)• Basic login and authentication modules• Form generation• Themes (Bootstrap integration out of the box)• App generator (Linux and Mac only)• Model and CRUD generator
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 36: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/36.jpg)
• Routing and friendly URLs• Session, cookies, include, redirect…• Lua Pages parsing• Mail sending• Simple Object Relational-Mapping• Validation (valua)• Basic login and authentication modules• Form generation• Themes (Bootstrap integration out of the box)• App generator (Linux and Mac only)• Model and CRUD generator
• Lua at client
What (else) is cool about Sailor?
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 37: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/37.jpg)
Not so great things
• It’s still in early development
• Things are changing fast
• It lacks features
• Documentation
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 38: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/38.jpg)
How to get Sailor!
$ luarocks install sailor $ sailor_create ‘My App’ /var/www $ cd /var/www/my_app $ lua start-server.lua
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 39: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/39.jpg)
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 40: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/40.jpg)
How to get Sailor!
$ luarocks install sailor $ sailor_create ‘My App’ /var/www $ cd /var/www/my_app $ lua start-server.lua
$ luarocks install luasql-mysqlOptional
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 41: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/41.jpg)
/conf /controllers /models /pub /runtime /themes/views
App structure
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 42: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/42.jpg)
Example!-- /controllers/site.lua
local site = {}
function site.index(page)
local msg = “Hello World”
page:render(‘index’, { msg = msg } )
end
function site.notindex(page)
page:write(“I’m different!”)
end
return site
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 43: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/43.jpg)
Example!<!-- /views/site/index.lp -->
<p>
A message from the server:
<?lua page:print(msg) ?>
<br/>
The message again:
<%= msg %> <!-- same thing as above —>
</p>
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 44: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/44.jpg)
Example!
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 45: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/45.jpg)
Example!<?lua@server -- Code here runs on the server ?>
<?lua -- Same as above ?>
<?lua@client -- Runs at the client ?>
<?lua@both -- Runs at the server and the client ?>
<?lua@both
another_msg = “Another message”
?>
<?lua page:print(another_msg) ?>
<?lua@client
js.window.alert(another_msg)
?>
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 46: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/46.jpg)
Example!
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 47: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/47.jpg)
Example!local user = {} local v = require “valua” -- validation module user.attributes = { { id = “safe” }, { name = v:new().not_empty() } } user.db = { key = ‘id’, table = ‘users’ } user.relations = { posts = { -- u.posts relation = “HAS_MANY”, model = “post”, attribute = “author_id” } } return user
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 48: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/48.jpg)
Example!-- /controllers/site.lua local site = {} function site.index(page) local User = sailor.model(‘user’) local u = User:new() u.name = ‘Arnold’ local msg if u:save() then msg = ‘Success’ else msg = table.unpack(u.errors) end local users = User:find_all() page:render(‘index’, { msg = msg, users = users } ) end return site
Web development with Lua @ GeeCON 2015 @etiene_d
![Page 50: Web development with Lua and Sailor @ GeeCon 2015](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b8bb34bb61ebef688b4644/html5/thumbnails/50.jpg)
Example!
Web development with Lua @ GeeCON 2015 @etiene_d