Minority Opinions

Not everyone can be mainstream, after all.

One More Language

leave a comment »

I’ve been learning Lua for a side project.  I had alternatives in C++ or Ruby, but the one involved setting up a finicky environment and the other I found vaguely distasteful last time I tried it.  So far, given Lua’s basic premise, I’ve not been displeased with the language.

Lua is designed for embedding into C/C++ programs, to allow scripting them at run time.  In that respect, it’s a lot like JavaScript; both have limited syntax, few native variable types, and very small standard libraries.  On the other hand, both are frequently granted access to powerful functions by the programs that use them, and both use their chosen types effectively.

I started my journey from a Python perspective, but quickly found a similarity to PHP:  Both use (abuse?) mappings as their primary sequence type.  In PHP’s case, that translates into all sorts of quirky behavior within its standard library.  Lua sidesteps that by omitting most such functions; some of the remaining few treat the table as a 1-based sequence, simply ignoring any keys that don’t fit that model.

Yes, 1-based; surprising for programmers, but (supposedly) easier for the new scripter, their target market.  Granted, the tables can have any indices you choose, so you can make them 0-based, but you sacrifice certain conveniences like the #varname syntax for the length of sequence.  (When I first saw it, I had expected it to be the number of keys in the table.  No dice.)  Then it comes up again in the string functions.  Even while trying to use 1-based tables like a polite user, I find myself adjusting for fence posts more than once every fifty lines, gaining a new appreciation for 0-based sequences and ranges that end before the stop number.

Everything beyond that is window dressing for the most part.  Sometimes I try to use an extra “do” at the beginning of a function block; I keep trying to use “done” instead of “end” to close a for block; I find myself implementing functions that I might have expected in a more expansive standard library; incrementing a variable is harder than it should be.  I’ve even managed to avoid getting too annoyed at the treatment of zero, the empty string, and the empty table as true values, partly because falsehood is so mixed up with variable existence.

Maybe that last bit could even help me get over my aversion to Ruby.


Written by eswald

30 Apr 2013 at 10:05 pm

Posted in Technology

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s