Created
July 15, 2009 09:21
-
-
Save nrk/147605 to your computer and use it in GitHub Desktop.
A sinatra-like DSL for Lua (actually an hack, but I'm starting to like it)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment