Posts: 29
Joined: Wed Dec 28, 2011 4:20 pm

Re: lua language?

Mon Apr 23, 2012 2:33 pm

I haven't seen lua mentioned anywhere for the RPi.

I have used it and it's a nice lightweight interpretted embedded language. It is lighter and more stable than say Python.

It is intended as a scripting language. Used by, amongst other apps, luatex and Adobe Lightroom.

For us it would allow us to write controller apps for GPIO testing.

Posts: 21
Joined: Mon Dec 05, 2011 8:44 pm

Re: lua language?

Mon Apr 23, 2012 7:44 pm

This is quite interesting. Lua never occurred to me as a potential language to use, but now that I think about it more, using Lua over (or as well as) Python seems a really good idea. There are a few things about it I don't like (1 based arrays, might make more sense to the lay person but counting from 0 is so pervasive in programming that you might as well get used to it from the off) but for the most part I think it makes a good balance between the intuitiveness of python and the lean design of C or something. Since Lua was actually designed as a language for people who don't program this has some real potential...

Even if Lua isn't used as a primary language to teach on the Pi it should be part of the default install I think.

Definitely food for thought


Forum Moderator
Forum Moderator
Posts: 853
Joined: Fri Sep 16, 2011 7:16 pm

Re: lua language?

Mon Apr 23, 2012 8:36 pm

I'm a major Lua fan myself. I've been (happily!) sucked in to so many other things since getting a Pi I haven't pushed Lua as much as I might have hoped LuaJIT 2.0 runs great on the Pi, and of course so does Lua. I personally think LuaJIT 2's FFI is *incredibly* compelling on a device like the Pi.

Posts: 29
Joined: Wed Dec 28, 2011 4:20 pm

Re: lua language?

Tue Apr 24, 2012 6:30 am

Glad you guys like the idea.

What I had in mind as an educational/debug app was some kind of wrapper for the gpio and enable interactive mode. This can be done either as a C/C++ gpio module loaded into the stock lua app or compiled/linked into out own minimal C/C++ app.

Let us suppose we had a Gertboard (or whatever) with some LEDs, motor etc plugged in. Via the gpio module we could write say:

leds = gpio.whatever_setup(…)

leds[1] = 1

leds[2] = 0

so flashing the lights on/off  under keyboard control.

We could even write:

leds = our_gpio.whatever(...)

leds.a = 1

leds.b = 1

leds.c = 0

leds.a = 0

This gives us a helloworld-ish interactive experience such as we got with BASIC where, with appropriate daughterboards, I could have done on an Apple II.

As programming skills get more advanced they can write/store their own scripts.

One of the nice features of lua is that because it is embedded the host app writer can offer as much or as little of his own API to lua. Also he can link in other extra modules, and it supports dynamic external modules.

A slightly more advanced app could include some GUI (qt bindings(?)) so not only can we talk to our daughter boards we can write pretty interfaces. The educational/practical value being that we can see all the way from the metal to the GUI.

On the point of the language features: surreptitious nil values are really irritating. You slightly mis-spell a variable name, it doesn"t complain but quietly just gives nil. In a long call stack this is a pain to debug.

The nice feature is the ubiquity of tables. It allows the implementation of object orientation(ish).

Posts: 24
Joined: Sun Nov 20, 2011 3:34 am

Re: lua language?

Sun May 20, 2012 2:55 am

With debian, I did "apt-get install lua", and it installed version 5.0. 5.2 is now available. It just takes a few more commands to install that. From your home (or desired directory):

wget http://www.lua.org/ftp/lua-5.2.0.tar.gz [download source]
tar xzvf lua-5.2.0.tar.gz [unpack]
cd lua-5.2.0 [switch to new directory]
sudo apt-get install libreadline5-dev [install a required library]
sudo make linux install [build & install lua]

then just Run lua
pi: lua
>print("Hello, World")

Posts: 406
Joined: Sun Nov 20, 2011 11:37 am

Re: lua language?

Fri Jun 15, 2012 2:35 pm

I haven't had a chance to have a play with this yet, but I have heard good things about Love. This is a framework to help you to make games using Lua.

I have a feeling that Lua may be quite popular with young people - it's widely used as a scripting tool in MMORPGs such as World of Warcraft, Roblox, etc.

User avatar
Forum Moderator
Forum Moderator
Posts: 4562
Joined: Fri Jul 29, 2011 2:51 pm

Re: lua language?

Fri Jun 15, 2012 2:42 pm

there is another good one called egsl

it requires freepascal to build and i haven't got around to setting that yet but no reason it shouldn't work.

Posts: 2
Joined: Sun Jul 01, 2012 1:25 am

Re: lua language?

Sat Sep 15, 2012 1:35 am

Lua and the RasPi get along great. What I love about Lua is the ease of integrating with 3rd party libraries. Here's a little demo of a Lua application driving the OpenVG graphics: https://www.youtube.com/watch?feature=p ... uc1A1B-H4U

Posts: 288
Joined: Sat Aug 04, 2012 8:28 am

Re: lua language?

Sat Sep 15, 2012 6:41 am

@darkstar: What do you mean by more stable than Python?

The API with indexing or naming the GPIO pins would be possible in Python too.

Code: Select all

while not self.asleep():
    sheep += 1

Posts: 386
Joined: Wed Mar 14, 2012 9:23 pm

Re: lua language?

Sat Sep 15, 2012 8:43 pm

BlackJack wrote:@darkstar: What do you mean by more stable than Python?
My only interpretation would be that lua uses less of the pi's few resources.

Posts: 19722
Joined: Tue Jul 17, 2012 3:02 pm

Re: lua language?

Sun Sep 16, 2012 12:32 am

It is lighter and more stable than say Python.
I'm curious. In what way is Python not stable? It has worked in flawlessly in production code for a long time now.

I have to say though, that Lua is a wonderful thing. It can be used on systems much smaller than the Pi and much smaller than where you will ever see Python.
Slava Ukrayini.

User avatar
Posts: 539
Joined: Sat Mar 03, 2012 10:02 pm

Re: lua language?

Mon Sep 17, 2012 12:49 pm

I highly recommend GameCake it is a Lua port with integrated OpenGL ES 2.0 and Joystick support that work nicely on the Raspberry PI


You can use "GameCake" to run the helloball.lua demo on Raspbian!
http://www.raspberrypi.org/phpBB3/viewt ... 01#p112301
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!

Return to “Other programming languages”