web development with lua programming...

52
Web development with Lua Programming Language Introducing Sailor, a web MVC framework in Lua Etiene Dalcol @etiene_d

Upload: others

Post on 19-Feb-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Web development with Lua Programming Language

Introducing Sailor, a web MVC framework in Lua

Etiene Dalcol@etiene_d

Page 2: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Web development with Lua Programming

Language

Introducing Sailor, a web MVC framework in Lua

Etiene Dalcol@etiene_d

Page 3: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

@etiene_d

Page 4: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Sailor!

http://sailorproject.org

Page 5: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Lua Ladies

http://lualadies.org

Page 6: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Google Summer of Code

LabLua

Page 7: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC
Page 8: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Advantages

Page 9: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC
Page 10: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

better reasons

• It looks cool(I heard you could make games with it)

Page 11: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

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)

Page 12: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

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

Page 13: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

??

??

??

Page 14: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Lua on the web

• Early stage

• cgilua ~ 1995

• Kepler Project ~ 2003

Page 15: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

“ 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

Page 16: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC
Page 17: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC
Page 18: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC
Page 19: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC
Page 20: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC
Page 21: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Why?

Page 22: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC
Page 23: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Servers

• Apache: mod_lua

• Nginx: OpenResty

Page 24: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Servers

• Apache: mod_lua

• Nginx: OpenResty

Page 25: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Servers

• Apache: mod_lua

• Nginx: OpenResty

• Xavante

• Others

Page 26: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Frameworks

• Orbit (2007)Least knownNo significant updates since 2010MVC

Page 27: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Frameworks

• Orbit (2007)Least knownNo significant updates since 2010MVC

• Luvit (2011)Most popularIntense developmentnode.js port 2-4x faster

Page 28: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Frameworks

• Lapis (2012)Intense developmentMoonscript and LuaVery well documentedTemplaterOpenResty onlyNot MVC

Page 29: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Frameworks

• Lapis (2012)Intense developmentMoonscript and LuaVery well documentedTemplaterOpenResty onlyNot MVC

• OthersComplicated, abandoned, poorly documented, license

issues or I never heard about it...

Page 30: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Sailor!

Page 31: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Sailor!

Page 32: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Sailor!

Page 33: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Sailor!

0.1(Venus)

0.2(Mars)

Page 34: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

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!

Page 35: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC
Page 36: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

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

Page 37: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

• 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?

Page 38: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Not so great things

• It’s still in early development

• Things are changing fast

• It lacks features

• Documentation

Page 39: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

How to get Sailor!

$ luarocks install sailor$ sailor_create ‘My App’ /var/www$ cd /var/www/my_app$ lua start-server.lua

Page 40: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC
Page 41: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

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-mysql

Page 42: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

/conf /controllers /models /pub /runtime /themes/views

App structure

Page 43: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

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

Page 44: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

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>

Page 45: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Example!

Page 46: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

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)

?>

Page 47: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Example!

Page 48: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

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

Page 49: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

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

Page 50: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

sailorproject.orggithub.com/Etiene/sailor

[email protected]@etiene_d

Page 51: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

Example!

Page 52: Web development with Lua Programming Languagepresentations2015.s3.amazonaws.com/60_presentation.pdf · Web development with Lua Programming Language Introducing Sailor, a web MVC

sailorproject.orggithub.com/Etiene/sailor

[email protected]@etiene_d