nrk (owner)

Revisions

gist: 147605 Download_button fork
public
Description:
A sinatra-like DSL for Lua (actually an hack, but I'm starting to like it)
Public Clone URL: git://gist.github.com/147605.git
Embed All Files: show embed
sinatra_global_scope.lua #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-- defining you application in the global scope
 
require 'sinatra'
 
module('nrk', package.seeall, sinatra.application)
 
get("/", function()
    return "<h1>Welcome to " .. APP_NAME .. "!</h1>"
    --[[
URL: http://127.0.0.1/
OUT: "<h1>Welcome to nrk!</h1>
]]
end)
 
get("/hello/:name", function()
    return "Hi " .. params.name .. ", how are you?"
    --[[
URL: http://127.0.0.1/hello/Daniele%20Alessandri
OUT: "Hi Daniele Alessandri, how are you?"
]]
end)
sinatra_local_scope.lua #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-- defining you application in a dedicated environment without polluting
-- Lua's global scope, you can think of it as a sort of Sinatra::Base.
 
require 'sinatra'
 
myapp = sinatra.application('nrk', function()
    get("/", function()
        return "<h1>Welcome to " .. APP_NAME .. "!</h1>"
        --[[
URL: http://127.0.0.1/
OUT: "<h1>Welcome to nrk!</h1>
]]
    end)
 
    get("/hello/:name", function()
        return "Hi " .. params.name .. ", how are you?"
        --[[
URL: http://127.0.0.1/hello/Daniele%20Alessandri
OUT: "Hi Daniele Alessandri, how are you?"
]]
    end)
end)
 
local function run(wsapi_env) return myapp.run(wsapi_env) end