Programming in Lua
- 10 November, 2011 04:38
- Comments
I haven't talked about programming languages for a while so here goes: We start this week with the free, open source (MIT License) Lua language.
First released in 1993, Lua (which means "moon" in Portuguese) was designed as an embeddable, interpreted scripting language. It's small, fast, and very elegant, and so flexible that it has found its way into a whole galaxy of commercial applications.
For example, the user interface of Adobe's Photoshop Lightroom is written in Lua (I raved about this app when it was first released in 2006), as is Logitech's Squeezebox music player and Damn Small Linux. According to Wikipedia, DSL uses "Lua to provide desktop-friendly interfaces for command-line utilities without sacrificing lots of disk space." (I reviewed DSL in 2005.)
I must digress for a moment and note that it appears from the Wikipedia article on DSL, as well as a number of blog comments, that Damn Small Linux may be faltering. Wikipedia says: "Due to infighting among the project's originators and main developers, DSL development seems to be at a standstill, and the future of the project is uncertain, much to the dismay of many of the users." Dismay indeed, and given that the DSL site seems dead (activity appears to have more or less stopped in 2008 after the 4.4 release of the OS) it may be DSL RIP, QED.
Anyway, Lua is easy to learn and you can download it in many implementations from the Lua Web site.
The classic first program in Lua is pretty unremarkable:
print("hello")
This prints "hello" (natch). A slightly more interesting Lua program is a factorial calculator:
function fact (n)
if n == 0 then
return 1
else
return n * fact(n-1)
end
end
print("enter a number:")
a = io.read("*number") -- read a number
print(fact(a))
... but only slightly.
That code is from "Programming in Lua by Roberto Ierusalimschy, which was written for Lua 5.0. Now Lua is at version 5.1, that work is a little out of date but still useful as a starting point.
Lua is a fascinating language with lots of examples (check out the Luaforge site) and you can try an interactive online version.
If you want more current documentation there are a number of commercial books to choose from or you can just put on your big boy programming pants and dive into the official Lua reference manual.
Now, should you be an iPad owner you might like to try Codea for iPad, a programming tool publishing by the curiously named Two Lives Left, that embeds a Lua interpreter into an iOS app designed for the iPad.
This is a really good looking app with elegant graphics and a well-designed user interface.
From the startup screen you can either load an existing project or create a new one. A Codea project consists of a tabbed window with the classes that make up an application on separate tabs and, at execution time, a two column layout with a program parameters panel, a text output panel, and execution controls (back, play, pause, and reset) on the left and the program graphical display pane on the right.
What's really cool in the Codea programming environment is how well it is integrated with the iPad. If you want to change a number, poke it with your finger then either release and edit with the keyboard or hold and drag up or down to increase or decrease the value. To change a color, poke the value with your finger and up pops a color picker. You can also select sprites in much the same way. Full Lua documentation is also built-in.
The demo programs are fairly impressive. There's a simulation of a sheet of cloth that swings fairly naturally when you move the iPad (the Codea system can access data from the accelerometers and detect multiple simultaneous screen touches), some multi-touch demos, a couple of visually quite complex games, and a drum machine.
What's missing? The ability to import or export code either locally or to and from an external resource, access to networking functions, you can't hide the left hand control panels so the application can run full screen, and any kind of code protection so you could actually produce a real app for use in your enterprise. The author, Simeon Nasilowski, tells me he has plans for all sorts of enhancements which may well include all I've asked for, but for now, he's not committing to a schedule.
Simeon tells me that that about 10,000 copies have been sold for the princely sum of $7.99 each since Codea's release Oct. 26, which is pretty impressive. Codea gets a rating of 4 out of 5.
Finally this week, I want to recommend a book called "Acts of the Apostles" by a friend of mine, John F.X. Sundman. This is not a religious text as you might first assume, but rather a science fiction novel in what I think of as the "old school, hard Sci-Fi" style.
I mention this book here in Gearhead because it is exactly what you, my geeky readers, will like. Sundman is very much one of us with a passion for technology and the ability to actually make it not only interesting but also central to a human story.
"Acts" starts with an engineer struggling to debug a timing problem on a custom chip called the "Kali." This scene is promptly followed by a murder and the story rapidly unfolds to include a collection of Silicon Valley characters, Scud missiles, Gulf War Syndrome, a manipulative billionaire genius, nanomachines, neurobiology, genetic programming, and much deviousness, intrigue, and skullduggery. As a writer on Slashdot commented: "It's what Tom Clancy would write if he were smart."
It's been a while since I've read a story that was quite so geekily entertaining. Highly recommended.
Gibbs finds little time to read in Ventura, Calif. Your unfinished book list to gearhead@gibbs.com.
Read more about software in Network World's Software section.
Join the CIO Australia group on LinkedIn. The group is open to CIOs, IT Directors, COOs, CTOs and senior IT managers.
- Bookmark this page
- Share this article
- Got more on this story? Email CIO
- Follow CIO on twitter
- Open Source Subnet: An independent Open Source community
- Open Source Initiative OSI - The MIT License (MIT):Licensing : Open Source Initiative
- The Programming Language Lua
- Applications Research Center - Network World
- Use Photoshop Lightroom 3 software to edit, manage & share photos
- Workflow and Lightroom
- Linux gets small and smaller
- Damn Small Linux - Wikipedia, the free encyclopedia
- Lua: download
- Programming in Lua : 1.1
- LuaForge
- Lua: demo
- Lua: documentation
- Lua 5.1 Reference Manual - contents
- Codea – iPad
- Two Lives Left
- Amazon.com: Acts of the Apostles (Mind over Matter) eBook: John F.X. Sundman: Kindle Store
- Wetmachine » My Thoughts Exactly
- Software Research Center - Network World
-
Pfizer's Future Depends on IT Transformation
-
Pfizer's Future Depends on IT Transformation
-
Pfizer's Future Depends on IT Transformation
-
Apple aims iPads at High Schools
-
Face Time - Interview with John Brennan and Robert DiStefano
-
Enterprise Buyers Guide for Cloud Storage
Customer interest in public cloud storage is increasing, driven by the promise of affordable, elastic storage for archiving, backup/recovery, and disaster purposes. To understand the types of offerings available and to assist buyers with purchasing decisions Computerworld has prepared a public cloud storage buyers guide. -
Enhancing Decision-Making, Cost-Efficiency, and Profitability With Predictive Analytics
Today’s managers must always look at the past, present, and future. They need reports on past performance to improve operational efficiency. Business intelligence (BI) platforms such as Information Builders WebFOCUS, are providing a unified decision-support environment where managers can retrieve and analyze data about past, present, and future activities. In this paper, we will discuss the incorporation of predictive modeling capabilities into the WebFOCUS BI platform, and highlight how this advanced functionality can dramatically improve decision-making, thus reducing risk and costs while increasing revenue and profits. -
Unified Monitoring™ A Business Perspective
The enterprise computing landscape has changed dramatically. Virtualisation, outsourcing, SaaS, and cloud computing are creating fundamental changes, and ushering in an era in which enterprises distribute increasingly critical IT assets and applications across multiple service providers.This paper explores today’s computing trends and their monitoring implications in detail. In addition, it reveals how a new monitoring paradigm architecture, that uniquely addresses the monitoring realities of today’s and tomorrow’s enterprises—whether they rely on internal platforms, external service providers, or a combination of both.
-
Java Concepts 6E for Java 5, 6 and 7
-
Wiley Pathways
-
Professional C++
-
Tcp/IP for Dummies®, 6th Edition
-
Software Engineering Risk Management
-
Beginning Mac OS X Tiger Dashboard Widget Development
-
Scanners for Dummies, 2nd Edition
-
Data Warehousing for Dummies®, 2nd Edition
-
Excel 2000 for Windows for Dummies Quick Reference








Comments
Post new comment