Lua is mostly often praised for its performance and the ease with which it integrates with C. It has other strengths, however. One that Sputnik exploits most aggressively is Lua's ability to serve at the same time as a programming language and a format for data storage.

When working with other programming languages, one typically separates the logic (written in, say, Java) and the data (stored as, say, XML or database tables). One reason for this is that Java source would not work well as a format for data, while XML doesn't work for expressing the logic. When using Lua, however, one can write the logic in Lua, and store the data in Lua too. Sputnik uses this extensively, storing almost everything it needs to store in Lua itself. All pages are stored as Lua files; for example, this page is internally represented this way(broken link). Many pages also contain Lua code, for instance _navigation. Lua provides an easy way to quickly and securely load such Lua code from inside Lua, making it easy, for example, to parse a string into a "table", check a field in it (or run a function that it defines), and then perhaps, take one of its fields and parse that as Lua code.

More generally, Lua is a very permissive language, even more so than Python. This comes in handy when working with heterogeneous data. Writing a wiki with a framework that uses a relational database underneath, one would have to think ahead of time what fields each "page" should have, and adding fields (or even changing their size) could be quite a hassle. With Sputnik, it's a matter of inserting the new field into the pages of that need it. Checking if a "page" has a particular attribute is as easy as asking for its value. If it's not there, you just get "nil" back.

Full disclosure

What's presented above is, as you might have guessed, an ex post account of why Lua has turned out to be a good language to write a wiki in and why you might want to consider Lua for a future project. It's not, however, the reason why Sputnik was written in Lua in the first place. I (Yuri) wrote the first version of Sputnik mostly in order to learn Lua, though the actual story is a bit stranger, and you should read Background if you want the details.

Powered by Sputnik | XHTML 1.1