Skip to content

Instantly share code, notes, and snippets.

@idevz
Created September 8, 2015 15:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idevz/87b59948ef7bf24ba244 to your computer and use it in GitHub Desktop.
Save idevz/87b59948ef7bf24ba244 to your computer and use it in GitHub Desktop.
A Simple route for vanilla
-- perf
local sgmatch = string.gmatch
-- init Simple and set routes
local Simple = {}
function Simple:new(request)
local instance = {
route_name = 'Simple',
request = request
}
setmetatable(instance, {__index = self})
return instance
end
function Simple:match()
local uri = self.request.uri
local match = {}
local tmp = 1
if uri == '/' then
return 'index', 'index'
end
for v in sgmatch(uri , '/([A-Za-z0-9_]+)') do
match[tmp] = v
tmp = tmp +1
end
if #match == 1 then
return match[1], 'index'
else
return table.concat(match, '.', 1, #match - 1), match[#match]
end
end
return Simple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment