<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My awesome blog</title>
</head>
<body>
<h1>Recent Posts</h1>
<lua>
local posts = {
{url = "getting-started", title = "Getting started"},
{url = "advanced-usage", title = "Advanced usage"},
{url = "tips-and-tricks", title = "Tips & tricks"}
}
for _, post in posts do
print('<a href="/posts/' .. post.url .. '">'
.. post.title "</a>)
end
</lua>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>User DB list</title>
</head>
<body>
<ul>
<lua>
local sqlite3 = require("lsqlite3")
local db = sqlite3.open("users.db")
for row in db:nrows("SELECT id, name, age FROM users") do
print(string.format("<li>ID: %i <br />Name: %s <br />Age: %i",
row.id, row.name, row.age))
end
</lua>
</ul>
</body>
</html>
<lua>
local json = require("cjson")
local method = sm.request.REQUEST_METHOD
sm.set_mime_type("application/json")
if method == "GET" then
local todos = {
{id = 1, text = "Learn Silvermoon", completed = true},
{id = 2, text = "Build an app", completed = false}
}
return json.encode(todos)
else
sm.set_http_code(400)
return json.encode({
success = false,
message = "Unsupported request type"
})
end
</lua>