And I'll tell you why!
Super easy to embed
I literally just dropped all of Lua 5.2's source code into an Xcode project, and it compiled. Instantly. Without warnings. It didn't need a fancy perl script or anything to pre-process the code. It just worked.
And hooking up my own C functions to Lua's is amazingly simple. When I
need to give Lua a number, I use
lua_pushnumber(L, n) and when I
want to get it back, I run
int n = lua_tonumber(index). That's
it. There are no fancy implicit conversion rules. You put C data types
in, you get C data types out. You can even give it C functions, no
problem! Lua doesn't care, Lua's easy.
Lua's C API is really simple. You only need to learn about 10 or 20 C functions, and suddenly you can hook your C project up to Lua, and let your users script away!
Extremely simple language
Lua's got all the simplicity I used to like about Ruby, before I continued learning Ruby. It's got all the sanity I used to love about Python before I continued to learn Python. And it has far fewer quirks than either language. That's just a by-product of how simple it is.
The other day I tried using Ruby without using classes. Big mistake. I ended up using classes, not because I wanted to, but because it was the path of least resistence to getting my Ruby project working. Lua doesn't have this problem. Sure, Lua makes it possible to build your own insane and horrible object system. Or you can just use the types it gives you and live an easy life. Maybe even retire early.
Very acceptable syntax
I used to worry about syntax. At one point I refused to like any
language that didn't have s-expressions. These days I care way more
about what the language lets me do, not how it looks. Fortunately Lua
isn't actually half bad to look at. It's got its little quirks, but
what language doesn't? Yeah, you have to use
local everywhere, but I
just pretend it's "let" or "var" and move on.
Metaprogramming for when you need it
Years ago I learned (the hard way!) that metaprogramming should be
used sparingly. Lua offers a bare-minimum set of metaprogramming
functionality, and makes it easy to tap into. You can use
efficiently set "methods" on an object. (You could just add the
methods onto each object, but this way is probably faster.) And when
you're wrapping a C datatype in a
userdata object, it's nice to be
able to override
__eq to make
a == b work as expected.
Easy to use functional programming
Thanks to Lua having first-class functions, I wrote my own
filter functions! And they were only about 5 lines long, too. It's
really nice to be able to do
local visiblewindows = filter(windows, window.isvisible).
Fast and efficient
This is one of my favorite parts! If you're not familiar with Wirth's law, it bears repeating: "software is getting slower more rapidly than hardware becomes faster". Lua is a great weapon for your arsenal in this epic never-ending battle for performance.
Lua's C API uses a stack-based approach. This is great for the authors of Lua, since it lets them avoid writing an exponential number of functions. And honestly, sometimes it's just nice to not have to name variables. But the API can be admittedly difficult to use in large quantities. The solution is to write a very (very!) minimalist private C layer, and write your public-facing API in Lua itself, which calls into the private API written in C.
My name is Steven Degutis, and I've been writing software professionally for almost a decade. During that time, I've written many apps and websites, quite a few techical articles, and kept up-to-date with the rapidly evolving software industry.
If you have software needs for web, mobile, or desktop, and are looking for a seasoned software professional, please reach out to me at email@example.com to set up a phone call.
- Self-employed – present
- Clean Coders – 5 years
- 8th Light – 2 years
- Big Nerd Ranch – 1 year
- Self-employed - 1 year
- Web: full-stack
- iOS (UIKit)
- macOS (Cocoa)
- REST APIs
- AWS / EC2 / ELB
- HTML5 / CSS
Over the past decade, I've written a total of 169 technical articles on various programming languages, frameworks, best practices, and my own projects, as I kept up-to-date and active in the software industry.
Subscribe via RSS / Atom.
- 2017 — "Clean code" isn't actually clean
- 2017 — Passion in your field is overrated
- 2017 — What I learned in 5 days of writing an experimental website
- 2014 — Age of the Polyglot
- 2013 — How to Program
- 2013 — Ignore the Naysayers
- 2013 — Writing Clearly
- 2012 — Reinvent the wheel
- 2010 — Good usability
- 2009 — Twitter is the wrong tool
- 2009 — We're all pretty bad at driving
- 2008 — Why I Code
|March||Notes on Haskell Extensions|
|February||Second thoughts on front-end tools|
|February||First thoughts on front-end tools|
|February||Some thoughts on GUIs|
|February||First thoughts on OCaml|
|February||First thoughts on Haskell|
Here are some of the projects I'm most proud of. They were created using a variety of technologies, running on several different platforms and OSes. They're all finished products, and many of them are open source.
I made Docks in 2009 for users who wanted to swap out icons in their Dock with a single click. Its unique functionality and design aesthetic attracted the attention of Apple, Engadget, MacWorld, and led to an acquisition of my start-up by Big Nerd Ranch.
This toy was made in a weekend to entertain my 1 year old daughter. It lets you create bubbles with your fingers, which then simulate physics by bumping into each other and falling.
When I couldn't find an app in the App Store that let me make very simple lists extremely quickly, I made one myself. I use it almost every day to organize and track my activities.
I created this app to increase my productivity by letting me move windows around in macOS using keyboard shortcuts. It grew into a community-driven highly extensible app, using Lua for its plugin system.
Implementing this elite social network gave me experience integrating both Apple Pay and credit card payments (via Stripe.com) seamlessly into web apps, for a frictionless and pain-free payment experience.
This isn't just any chatroom. In this web app, you can see what everyone is typing while they type it. I made this in order to scratch my itch for making real-time apps and games, and learned how to use WebSockets in the process.
This was written in 2009, before the time of Slack, when IRC was the main way for programmers to get short-term assistance from each other. Its purpose was to be a beautiful app with an emphasis on simplicity and usability over technical power.
This is an app I actually use every single day. It lets you move windows with global keyboard shortcuts. Since it uses Vim-like key bindings, it should feel pretty natural to any programmer. There's no configuration needed; it Just Works™.
As an evolution of Phoenix, Hydra was my first attempt at embedding a full Lua virtual machine into an Objective-C app, to make a lightweight and efficient window manager that focused on speed, low memory usage, low CPU usage, and overall being gentle on laptop batteries.
These may be tiny, but they're interesting technical feats.
|Lua4Swift||Swift framework for embedding Lua with a native Swift API.|
|choose||Command line fuzzy-matching tool for macOS that uses a GUI|
|music||Command line music daemon for macOS that only speaks JSON|
|hecto||Command line text editor with an embedded Lua plugin system|
|ZephSharp||Window manager for Windows using Clojure for scripting|
|management||Minimalist EC2 configuration & deployment tool in Ruby.|
|go.assert||Assertion helper package for writing tests in Go.|
|go.shattr||Go library for printing shell-attributed strings to stdout.|
|OCDSpec2||Objective-C based testing framework with Xcode integration.|