Skip to content

Commit

Permalink
Minor macro and async additions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dom96 committed Jul 13, 2014
1 parent 2b17319 commit 4c94ef9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions jester.nim
Expand Up @@ -308,7 +308,7 @@ proc serve*(settings: PSettings,
jes.matchProc = match
if jes.settings.http:
jes.httpServer = newAsyncHttpServer()
jes.httpServer.serve(jes.settings.port,
asyncCheck jes.httpServer.serve(jes.settings.port,
proc (req: asynchttpserver.TRequest): PFuture[void] =
handleHTTPRequest(jes, req))
echo("Jester is making jokes at http://localhost" & jes.settings.appName &
Expand Down Expand Up @@ -603,6 +603,8 @@ macro routes*(body: stmt): stmt {.immediate.} =
#echo(treeRepr(body))
result = newStmtList()

var outsideStmts = newStmtList()

var matchBody = newNimNode(nnkStmtList)
matchBody.add newCall(bindSym"setDefaultResp")
var caseStmt = newNimNode(nnkCaseStmt)
Expand Down Expand Up @@ -649,7 +651,8 @@ macro routes*(body: stmt): stmt {.immediate.} =
discard
of nnkCommentStmt:
discard
else: assert false
else:
outsideStmts.add(body[i])

var ofBranchGet = newNimNode(nnkOfBranch)
ofBranchGet.add newIdentNode("HttpGet")
Expand All @@ -663,8 +666,11 @@ macro routes*(body: stmt): stmt {.immediate.} =

matchBody.add caseStmt

result = parseStmt("proc match(request: PRequest, response: PResponse): PFuture[bool] {.async.} = discard")
result[0][6] = matchBody
var matchProc = parseStmt("proc match(request: PRequest," &
"response: PResponse): PFuture[bool] {.async.} = discard")
matchProc[0][6] = matchBody
result.add(outsideStmts)
result.add(matchProc)
#echo toStrLit(result)
#echo treeRepr(result)

Expand Down

0 comments on commit 4c94ef9

Please sign in to comment.