Created
February 24, 2017 03:20
-
-
Save zedshaw/80de87dd4e3b7b0e326b12418448fa71 to your computer and use it in GitHub Desktop.
Quick hack to sort out Lua in Jester with SQL DB in Nim
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
import db_sqlite | |
import jester, asyncdispatch, htmlgen | |
import nimLUA | |
let db = open("test.sqlite3", nil, nil, nil) | |
proc render(page: string, name: string) : string = | |
var L = newNimLua() | |
discard L.pushstring(name) | |
L.setglobal("name") | |
if L.doFile(page) == 0.cint: | |
return L.toString(-1) | |
else: | |
let error = L.toString(-1) | |
L.pop(1) | |
return "Error: " & error | |
routes: | |
get "/": | |
resp render("index.lua", "Nobody") | |
get "/hello/@name?": | |
if @"name" == "": | |
for x in db.fastRows(sql"select * from myTable"): | |
resp render("hello.lua", x[1]) | |
else: | |
resp render("hello.lua", @"name") | |
runForever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment