Skip to content

Instantly share code, notes, and snippets.

@nrk
Created July 15, 2009 09:21
Show Gist options
  • Select an option

  • Save nrk/147605 to your computer and use it in GitHub Desktop.

Select an option

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