lua language?


12 posts
by darkstar » 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: 29
Joined: Wed Dec 28, 2011 4:20 pm
by Mjiig » 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

Angus
Posts: 21
Joined: Mon Dec 05, 2011 8:44 pm
by asb » 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.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 800
Joined: Fri Sep 16, 2011 7:16 pm
by darkstar » 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: 29
Joined: Wed Dec 28, 2011 4:20 pm
by lyzby » 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")
>Ctrl+C
Posts: 24
Joined: Sun Nov 20, 2011 3:34 am
by antiloquax » 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.
mark
Posts: 406
Joined: Sun Nov 20, 2011 11:37 am
by ukscone » Fri Jun 15, 2012 2:42 pm
there is another good one called egsl
http://www.egsl.retrogamecoding.org/

it requires freepascal to build and i haven't got around to setting that yet but no reason it shouldn't work.
User avatar
Forum Moderator
Forum Moderator
Posts: 2893
Joined: Fri Jul 29, 2011 2:51 pm
by dmattp » 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: 2
Joined: Sun Jul 01, 2012 1:25 am
by BlackJack » 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: 288
Joined: Sat Aug 04, 2012 8:28 am
by 6677 » 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: 382
Joined: Wed Mar 14, 2012 9:23 pm
by Heater » Sun Sep 16, 2012 12:32 am
Darkstar,

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.
Posts: 1326
Joined: Tue Jul 17, 2012 3:02 pm
by xranby » 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

http://gamecake.4lfa.com/welcome

You can use "GameCake" to run the helloball.lua demo on Raspbian!
viewtopic.php?p=112301#p112301
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby
User avatar
Posts: 401
Joined: Sat Mar 03, 2012 10:02 pm