Play With Lua!

Archive for July, 2011

No update this week

without comments

I am spending the time making a presentation on ZeroMQ for the Lone Star Ruby Conference.

Written by randrews

July 31st, 2011 at 1:24 pm

Posted in Uncategorized

A short trick: transparent containers

without comments

I thought of this today, and I thought it might make an interesting short post. One of the small annoyances of Lua is that it doesn’t have a lot of convenient support for arrays. You can implement arrays with tables, of course, but they’re still tables: they don’t have default metatables (so you can’t do things like join), they don’t pretty-print (so it’s a hassle to see what you have), and there’s still only one iterator (using ipairs with a for loop). You can do it but it’s not exactly convenient. So I started thinking about how exactly I’d add all that stuff.
Read the rest of this entry »

Written by randrews

July 24th, 2011 at 12:35 am

Posted in Uncategorized

Lua modules, explained simply

without comments

I’m not an expert on Lua. I’ve been using it for less than a year; most of the time before that I wrote Ruby, JavaScript, Scheme, etc. It’s not a terribly large language. I usually tell people that if they know JavaScript they can learn Lua in a weekend, and that’s true as far as the syntax goes. But, there are several Lua idioms that are either complicated or just not explained well, and one of those is modules. You can get a long way coding in Lua without ever using a module, but eventually you’ll want to know how they work.

I’m going to explain what modules are for, how to use them, and most importantly why they work that way, and I’m going to do that by implementing Lua’s module system myself. Let’s begin:
Read the rest of this entry »

Written by randrews

July 15th, 2011 at 1:53 pm

Posted in Uncategorized

Storing bitmaps in quadtrees

without comments

This is an adaptation of a chapter from The New Turing Omnibus, a great little tour of a few dozen areas of CS. This is about a way to compress a bitmap, to store it without storing each individual pixel.

The technique is called a quadtree. We’re going to split a bitmap up into four equally-sized chunks, then compress and store those. The savings comes from the fact that we aren’t going to store equivalent chunks twice.
Read the rest of this entry »

Written by randrews

July 10th, 2011 at 3:13 am

Posted in Uncategorized

A simple puzzle game (part 3)

without comments

When we left off last week, we had part of a game. It would display a board, and we could rotate it left or right. It would even animate, which was cool, but already our code was starting to get complex, so we were probably going about things the wrong way.

The issue is that we need to start an animation, then return from the function so that Löve can actually show the animation. But, the animation isn’t the entire turn; we have more game logic that needs to run after it finishes.

Currently, the only way to find out when something finishes is by checking for it in love.update, right? So we can make this game by making something like this:
Read the rest of this entry »

Written by randrews

July 2nd, 2011 at 10:24 pm

Posted in Uncategorized