DaveB
Posts: 29
Joined: Wed Sep 14, 2011 8:40 pm

Re: Lua on the Raspberry Pi

Wed Sep 14, 2011 10:03 pm

Hello, first time poster here, I've just registered but I've been watching this project for a while now.

I've just read Eban's interview on Slashdot and I was puzzled about one of his responses where he said that a developer is currently working porting Lua to the Raspi.

What exactly is being ported here? Lua (http://www.lua.org) is written in plain ANSI C, so it just needs to be compiled for ARM. Are we talking about add-on libraries that are being ported?

If you need better performance, there is an ARM port of the LuaJIT (http://www.luajit.org) compiler. This is in beta at the moment, but I've used it on an ARM based Pandora (http://www.openpandora.org) and found it to be quite stable.

I'm quite interested in developing some sort of Lua based games programming toolkit for the Raspi. Would anyone be interested in that sort of thing? This is something that I've done before for x86 Linux machines (http://www.jameter.org) and I'm currently working on a ground up rewrite based on LuaJIT for the Pandora. This is now at quite an advanced stage and I don't think it would take much work to adapt it for the Raspi.

Edit: Edited to fix URLs.

User avatar
liz
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 5202
Joined: Thu Jul 28, 2011 7:22 pm
Contact: Website

Re: Lua on the Raspberry Pi

Wed Sep 14, 2011 10:18 pm

Yes - it's the add-on libraries which are being ported. We want a version of Lua that does something a bit more interesting than just print "Hello World" on the device.

Thanks for the pointer to the port of the LuaJIT. We probably won't be including beta software on the device, but we'll keep an eye on its progress. And absolutely, yes, please look at writing a toolkit - it's exactly the sort of thing we'd love to see from the community.
Director of Communications, Raspberry Pi

finnw
Posts: 24
Joined: Wed May 16, 2012 7:05 pm

Re: Lua on the Raspberry Pi

Sun May 20, 2012 1:26 am

You can certainly use LuaJIT (2.0.0b10) on the Pi - I'm experimenting with it right now.

So far I've managed to use the FFI to:
- Call functions in the BLAS library (the version included in NumPy) to multiply matrices
- Call EGL/GLES functions (so far: created a surface and filled it with a single color; Next I will try to write a Lua version of the rotating cube from the hello_triangle demo.)

XIX
Posts: 7
Joined: Wed Jun 06, 2012 9:14 pm

Re: Lua on the Raspberry Pi

Sat Jun 30, 2012 10:58 am

I've got my batch of lua libs building and running with the raspi as a target recently so figure it might be of interest here.

Run the code below on a raspi prompt (works before or after startx) to download and run a little lua gles demo. See if you can guess which old machine I used to know inside out.

Code: Select all


wget https://bitbucket.org/xixs/bin/raw/tip/exe/lua.raspi
wget https://bitbucket.org/xixs/lua/raw/tip/apps/demo/helloball.lua

chmod +x lua.raspi
./lua.raspi helloball.lua

helloball.lua can of course be edited and played with and the lua gles code is an obvious mapping to standard gl code.

All the C code can be found on my bitbucket and it compiles into the lua.raspi file, a fat binary with libs included. it also builds for many other platforms.

https://bitbucket.org/xixs/lua

I suspect you will need the debian wheezy beta for this to run.

Cheers,

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

Re: Lua on the Raspberry Pi

Sat Jun 30, 2012 4:09 pm

Awesome stuff, nice to see a fellow Lua fan :)

User avatar
ukscone
Forum Moderator
Forum Moderator
Posts: 4198
Joined: Fri Jul 29, 2011 2:51 pm
Contact: Website

Re: Lua on the Raspberry Pi

Sat Jun 30, 2012 4:21 pm

nice. thanks for doing this

mlepage
Posts: 95
Joined: Tue Jun 12, 2012 1:58 am

Re: Lua on the Raspberry Pi

Sun Jul 01, 2012 6:39 am

Lua 5.1.5 is already on the beta Debian Wheezy image (June 18).

XIX
Posts: 7
Joined: Wed Jun 06, 2012 9:14 pm

Re: Lua on the Raspberry Pi

Sun Jul 01, 2012 10:26 am

mlepage wrote:Lua 5.1.5 is already on the beta Debian Wheezy image (June 18).
This isn't a build of lua, its a bundle of lua libs,some of which are written by me.

Essentially I've added raspi to the list of platforms I'm building a low level lua game framework for, hence the focus on opengl. Right now I figure the gles2 binding demonstrated in the example code might be of interest and something anyone can play around with just by messing about with a single file.

Think of this like https://love2d.org/ except in 3d. A broken unfinished version of love2d sure, but it is getting there slowly :)

LuaPie
Posts: 11
Joined: Tue Jul 10, 2012 12:52 pm

Re: Lua on the Raspberry Pi

Tue Jul 10, 2012 1:58 pm

Have you people ever heard of the Lua Player?

If not then I think it's the kind of thing that your Lua dreams are made of!

Take a look at these links for some of the games you can make for the Lua Player.
http://soucali.com/pspnews/modules/news ... torynum=20
http://www.frank-buss.de/luaplayer/gallery/index.html

ren41
Posts: 99
Joined: Sat May 26, 2012 8:00 pm

Re: Lua on the Raspberry Pi

Wed Jul 11, 2012 12:28 pm

Great demo, XIX. It works fine on the Squeeze distro, too.

ren

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

Re: Lua on the Raspberry Pi

Mon Sep 17, 2012 12:53 pm

Great demo, XIX, helloball.lua work fine on Raspbian armhf as well when using the latest GameCake lua binary!
http://gamecake.4lfa.com/welcome
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

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

Re: Lua on the Raspberry Pi

Sat Sep 29, 2012 9:44 am

Lua is not a development language per-se (like Perl, Python, C++), it is embedded. That is to say that it is there to add scripting ability to another application. Of course the "application" can be a minimal bit of C that just allows it to do basic console and file io (as we see in the lua ELF).

See the lua website and wikipedia for the number of applications that have lua in the back.

Take "nmap" (the network analysis tool). The core functionality (packet grabbing etc) is written in C/C++. Then the lua library is linked in and an API to the packet is exposed to lua. Then the business logic is expressed in lua and the scripts bound in the back.

Adobe Lightroom uses a lot of lua. It even uses it in its "savegame" files. For each platform the respective programming teams can make it fit nicely on each platform, but the business logic is all lua. Similarly, because the API is the same across all platforms, the "plugins" will work anywhere irrespective of chip.

Similarly with a games program. The core video is written in C/C++ and then the API is given to lua. In this case you would expect to find methods for setting up the dungeon and for the appearance and behaviour of characters. For each new beastie you only have to write it in lua and not tangle with C.

That having been said, some lua apps can get quite large. There is a documentation tool to extend doxygen to let it read lua (lua2dox).

zoyo
Posts: 5
Joined: Tue Jul 24, 2012 9:15 pm

Re: Lua on the Raspberry Pi

Sat Sep 29, 2012 5:50 pm

darkstar wrote:Lua is not a development language per-se (like Perl, Python, C++), it is embedded. That is to say that it is there to add scripting ability to another application. Of course the "application" can be a minimal bit of C that just allows it to do basic console and file io (as we see in the lua ELF).
....
See the lua website and wikipedia for the number of applications that have lua in the back.
.
Sorry, but this is rubbish. Though the intention behind Lua really was to embed it, but you can write full-blown standalone programs in Lua. That said, for file or console I/O you do not need other applications.

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

Re: Lua on the Raspberry Pi

Sun Sep 30, 2012 6:13 am

zoyo wrote:
darkstar wrote:Lua is not a development language per-se (like Perl, Python, C++), it is embedded. That is to say that it is there to add scripting ability to another application. Of course the "application" can be a minimal bit of C that just allows it to do basic console and file io (as we see in the lua ELF).
....
See the lua website and wikipedia for the number of applications that have lua in the back.
.
Sorry, but this is rubbish. Though the intention behind Lua really was to embed it, but you can write full-blown standalone programs in Lua. That said, for file or console I/O you do not need other applications.
Sorry, that part of the original post wasn't so well written but, yes, some apps can be mostly lua.

You still need a lua VM at runtime and some supporting app, even if this is the lua ELF that came with your distro.

The basic lua interpreter is quite useful. You get your language features and console/file IO, and from this you can build some quite nice apps. If you need a bigger API you can load external C/C++ modules.

One of these is a sqlite binding, so you can do some nifty dataprocessing.

One binding that would be good is to handle GPIO (and other hardware wiggling) for the RPi.

With these bindings we can write some cool apps: GPIO to talk to the hardware, sqlite to log it and Apache/PHP(or whatever) to display it. Alternatively display via some GUI lib to the local monitor. Even cooler would be with a touchscreen to complete the loop.

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

Re: Lua on the Raspberry Pi

Fri Oct 05, 2012 6:31 am

The embeddedness of lua and its VM is one of its attractive features.

Because lua lives within a host application its communication, via the exposed API, is under the control of the original programmer, so it is sortof sandboxed. If the C/C++ programmer wishes to restrict the lua code's scope then he can.

But more positively it allows the C/C++ programmer to add lots of features.

Writing a GPIO module would be quite trivial. I would do it myself but I don't have any hardware on which to test it.

The virtual machine of lua is fairly efficient. I have had apps written in Perl that were quite sluggish, rewrite them in lua and they are quick.

Return to “Other programming languages”