1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
The <code><lua></code> tag allows you to embed Lua code in your templates and wiki documents.
<source lang="lua">
<lua where="wall">
function bottle(x)
if x > 1 then
return x .. " bottles of beer"
elseif x == 1 then
return "One bottle of beer"
else
return "No more bottles of beer"
end
end
function count(x)
output = "<pre>"
for beer = x, 1, -1 do
output = output .. bottle(beer) .. " on the " .. where .. ",\n"
output = output .. bottle(beer) .. ",\n"
output = output .. "Take one down, pass it around,\n"
output = output .. bottle(beer-1) .. " on the " .. where .. ".\n"
output = output .. "\n\n"
end
return output .. "</pre>"
end
</lua>
==99 Bottles of Beer==
{{#luaexpr:count(99)}}
</source>
==In Action==
<lua where="floor">
function bottle(x)
if x > 1 then
return x .. " bottles of beer"
elseif x == 1 then
return "One bottle of beer"
else
return "No more bottles of beer"
end
end
function count(x)
output = "<pre>"
for beer = x, 1, -1 do
output = output .. bottle(beer) .. " on the " .. where .. ",\n"
output = output .. bottle(beer) .. ",\n"
output = output .. "Take one down, pass it around,\n"
output = output .. bottle(beer-1) .. " on the " .. where .. ".\n"
output = output .. "\n\n"
end
return output .. "</pre>"
end
</lua>
==99 Bottles of Beer==
{{#luaexpr:count(99)}}
|