Skip to content

Instantly share code, notes, and snippets.

local iter, dir = lfs.dir('.')
local file = dir:next()
while file and file ~= 'foo' do
print(file)
file = dir:next()
end
dir:close()
template = "$do_cards[[$rank of $suit, ]]"
view = {
{ rank = "Ace", suit = "Spades" },
{ rank = "10", suit = "Hearts" },
}
result = cosmo.fill(template, {
do_cards = function()
for i,v in ipairs(view) do
cosmo.yield(v)
end
template = "Today is $date_string{ today }"
result = cosmo.fill(template, {
today = os.time(),
date_string = function (args)
return os.date("%B %d, %Y", args[1])
end
})
print(result) -- Today is October 23, 2009
template = "$cards[[$if{show}[[$rank of $suit, ]]]]"
view = {
{ rank = "Ace", suit = "Spades", show = true },
{ rank = "5", suit = "Clubs" },
{ rank = "10", suit = "Hearts", show = true },
}
result = cosmo.fill(template, { cards = view })
print(result) -- Ace of Spades, 10 of Hearts,
require 'luarocks.require'
require 'cosmo'
require 'mustache'
-- This needs the Cosmo in source control to work (because of the nested long strings and
-- cosmo.last - install with luarocks install cosmo --from=http://luarocks.org/repositories/rocks-cvs
do
local template = "$cards[[$if{show}[[$rank of $suit$if{not _last}[[, ]]]]]]"
local view = {
template = "$cards[[$rank of $suit, ]]"
view = {
{ rank = "Ace", suit = "Spades" },
{ rank = "10", suit = "Hearts" },
}
result = cosmo.fill(template, { cards = view })
print(result) -- Ace of Spades, 10 of Hearts,
location ~ ^(.+\.lua)(.*)$ {
root html;
fastcgi_pass 127.0.0.1:9100;
fastcgi_index index.lua;
fastcgi_split_path_info ^(.+\.lua)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
$ spawn-fcgi -a 127.0.0.1 -p 9100 -F 4 -- ~/lualr2/bin/wsapi.fcgi
require "sputnik.wsapi_app"
require "orbit"
require "wsapi.util"
local filter = orbit.new()
local sputnik = sputnik.wsapi_app.new{
VERSIUM_PARAMS = { '/Users/mascarenhas/sputnik/wiki-data/' },
BASE_URL = '/sputnik.ws',
PASSWORD_SALT = '6QQQuj9A2aUqwKq5YQsCCG8hEZZX1Lf2praCyM1I',
#!/usr/bin/env lua
-- Does a "luarocks make" with symlinks from your source tree instead of copying
-- Run with "lua luarocks_ln.lua make <rockspec>" at the root of the source tree
local command_line = require("luarocks.command_line")
local fs = require("luarocks.fs")
require "lfs"