I’ve upgraded my moveable type installation to version 3.2. I hope this solves the spam comment problem I was having with moveable type 3.0.1.
In the next few months, I’ll be introducing you to the programming language “lua”.
Lua can be downloaded from http://lua.org. Here is the direct link : http://luaforge.net/frs/download.php/1106/lua5_1b1_Darwin83.tar.gz for Mac OS X.
Lots of people comment how they “used to program” or would “like to program” and yet none of these people ever do. What a shame. Lua is a simple programming language, so why not get started with a little teaser to make you see how easy it is to play.
function shuffle()
local suits={"spades", "clubs", "diamonds", "hearts"}
local cards={"ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}
deck = {}
local index = 1
for suitIndex, suit in ipairs( suits ) do
for cardIndex, card in ipairs( cards ) do
deck[ index ] = { suit = suit, card = card, value = { cardIndex } }
if cardIndex == 1 then
-- in blackjack, the ace is worth either 1 or 11
table.insert( deck[ index ].value, 11 )
end
index = index + 1
end
end
for i = 1, 52 do
local randomIndex = math.random( 52 )
deck[ randomIndex], deck[ i ] = deck[ i ], deck[ randomIndex ]
end
curCard = 1
end
function draw()
print( string.format("%s of %s", deck[ curCard ].card, deck[ curCard ].suit))
curCard = curCard + 1
end
And here is example output:
< shuffle() < draw() 4 of clubs < draw() 6 of clubs
Ok. Who am I kidding. You guys don’t want to learn lua. But if you do, here are some good questions: what is a function and how do you call one? What does call a function mean? What does it mean when the word “local” appears before a variable name? Are the words “for”, “function”, “end”, “do” and “if” special in some way? What is math.random? What is the significance of the curly braces “{” and “}”? Brackets “[” and “]” and parenthesis “(” and “)”?
I await with baited breath to see if anyone really asks me any programming questions.