• No results found

Web development with Lua Programming Language

N/A
N/A
Protected

Academic year: 2021

Share "Web development with Lua Programming Language"

Copied!
52
0
0

Loading.... (view fulltext now)

Full text

(1)

Web development with Lua

Programming Language

Introducing Sailor, a web MVC framework in Lua

Etiene Dalcol @etiene_d

(2)

Web development with

Lua Programming

Language

Introducing Sailor, a web MVC framework in Lua

Etiene Dalcol @etiene_d

(3)
(4)

Sailor!

(5)

Lua Ladies

http://lualadies.org

(6)

Google Summer of Code

LabLua

(7)
(8)
(9)
(10)

better reasons

It looks cool

(11)

better reasons

It looks cool

(I heard you could make games with it)

It’s made in my home country

(12)

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)

(13)

?

?

?

?

?

(14)

Lua on the web

Early stage

cgilua ~ 1995

(15)

“ 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

(16)
(17)
(18)
(19)
(20)
(21)
(22)
(23)

Servers

Apache: mod_lua

(24)

Servers

Apache: mod_lua

(25)

Servers

Apache: mod_lua

Nginx: OpenResty

Xavante

(26)

Frameworks

• Orbit (2007)

Least known

No significant updates since 2010 MVC

(27)

Frameworks

• Orbit (2007)

Least known

No significant updates since 2010 MVC

• Luvit (2011)

Most popular

Intense development node.js port 2-4x faster

(28)

Frameworks

• Lapis (2012)

Intense development Moonscript and Lua Very well documented Templater

OpenResty only Not MVC

(29)

Frameworks

• Lapis (2012)

Intense development Moonscript and Lua Very well documented Templater

OpenResty only Not MVC

• Others

Complicated, abandoned, poorly documented, license issues or I never heard about it...

(30)
(31)
(32)
(33)

Sailor!

0.1 (Venus)

0.2 (Mars)

(34)

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)

(35)
(36)

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)

(37)

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

(38)

Not so great things

• It’s still in early development • Things are changing fast

• It lacks features • Documentation

(39)

How to get Sailor!

$ luarocks install sailor

$ sailor_create ‘My App’ /var/www

$ cd /var/www/my_app

(40)
(41)

How to get Sailor!

$ luarocks install sailor

$ sailor_create ‘My App’ /var/www

$ cd /var/www/my_app

$ lua start-server.lua

(42)

/conf

/controllers

/models

/pub

/runtime

/themes

/views

App structure

(43)

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

(44)

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>

(45)
(46)

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

(47)
(48)

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”

} }

(49)

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

(50)

sailorproject.org

github.com/Etiene/sailor

[email protected]

(51)
(52)

sailorproject.org

github.com/Etiene/sailor

[email protected]

References

Related documents

partial: probability (in %) to choose partial retirement, defined as full-time work until earliest possible retirement age, working 60% of pre-retirement hours from earliest to

This system contains the heat pump unit, the equipment to make the source energy available, the back up heater and all auxiliary drives including the auxiliary of the

This system is a concrete blocks poured inside the station, attached to wall eye for a length exceeding the shield length so that, when the last wall is crossed through, the

GENERAL MTS DEGREE REQUIREMENTS Area Number Biblical studies 4 Theological studies 3 Historical studies 2 Public Leadership and Ministry studies 1 Contextual

Netfilter sends the packet to NFLua; then NFLua calls the function checkuseragent, running in the state waf. If a match is found for the packet, Netfilter is instructed to terminate

The Child Learning Center enhances the growth, development and performance of the Austin Peay State University students and other parents by maintaining a campus children’s

To study adverse side effects produced by the administration of Quina on body weight and different body

Effect of packaging material on volatile organic compounds (VOCs) of sliced and MAP packaged typical Italian and Spanish dry- cured hams Latorre M.A., Pinna A., Montanari A.,