The Lua Scripting Language


November 06, 2010 posted by Marc Balmer

About a week ago, I imported the Lua programming language, version 5.1.2, into NetBSD-current as a component of the base system.

Lua is a scripting language with a very small memory footprint that has been designed as an embedded (or hosted) language from the ground up. As such, it's integration into software written in e.g. C or C++ is straightforward. Lua is very fast, it is recognized as one of the fastest scripting languages. The language has a clear and simple syntax with some very powerful concepts; the libraries (called packages) that come with it are themselves reasonable small. Lua compiles programs to a bytecode which is executed by a very small virtual machine. Lua scripts can be precompiled to bytecode for faster load times (but not faster execution). The first versions of Lua date back in 1993, so the language is stable and mature.

Lua is excellent as a scripting language in base, because it is small, fast, and powerful and a user can learn it very quickly. For endusers, having Lua can leverage scripting in NetBSD, e.g. if an interface to e.g. POSIX functionality is used. For developers of software written in C it is a very convenient and efficient means to extend the software by a scripting engine.

Lua allows us to extend exisiting software in interesting ways, DHCP option processing in DHCP clients comes to my mind, or the system installer, sysinst, which can be made a lot more flexible using Lua scripting.

The only change I made to the default Lua distribution is to remove the current working directory ('.') from the module load paths, to avoid potential security problems.

The Lua homepage is at http://www.lua.org/, the reference manual can be found at http://www.lua.org/manual/5.1/. More information about Lua can also be found at http://www.lua.org/about.html.

[12 comments]

 



Comments:

This time I am the first to comment on my own blog entry ;) As you may know, there is also an ongoing project to bring the Lua scripting language to the kernel. Lourival Neto will continue to work on his Google Summer-of-Code project, so stay tuned to more Lua in NetBSD.

Posted by Marc Balmer on November 06, 2010 at 10:36 AM UTC #

Congrats, this is a good opportunity for learn Lua. Regards.

Posted by ficovh on November 06, 2010 at 07:24 PM UTC #

Hi, Why isn't Python considered?. There is a lot of code in python that is readily available and it is relatively simpler to write performance intensive modules in C for python.

Posted by Prudhvi Krishna Surapaneni on November 12, 2010 at 06:45 PM UTC #

I looked at various candidate scripting languages, Python being among them. Keep in mind that the primary goal was to have a scripting language in the classic sense, to be embedded in software written in C to extend and make scriptable this software. Comparing Python and Lua in this regard is left to the reader as an exercise.

Posted by Marc Balmer on November 14, 2010 at 09:59 AM UTC #

It would've been nice though to see a short checklist of languages considered (e.g. perl, tcl, lua, python, ruby, whatnot), weighing their pros and cons (e.g. codebase / libraries / licenses / size / UTF-8 support / crossbuilding etc. etc.) to show how the conclusion was reached to go for lua.

Posted by Martin Weber on November 14, 2010 at 04:27 PM UTC #

There is no such (formal) list, I am sorry.

Posted by Marc Balmer on November 15, 2010 at 09:06 PM UTC #

Hmm, it's never too late. Assuming lua was (is) a sane choice, you'll find no other languages that rank 'better' - and once it comes to others being equally well suited, then (having been) going for lua is a good thing. I know you just went through all the pain but ... if there's another scripting language out there, that actually does *better* than lua, this will come back to haunt and bite you this way or another sooner or later. So rather sooner than later? And finally, if someone (like me) comes around (in the future) who'd preferred another language, having such a list would still be a nice thing. Please don't take this is a "you've done a bad job" - quite the contrary. I'm just asking for a bit of polish, hoping that there's no flaws to be unveiled. (btw, the lack of even paragraphing on comments here sucks)

Posted by Martin S Weber on November 17, 2010 at 05:41 PM UTC #

There was long discussion about this on tech-userlevel (and also on tech-kern): http://thread.gmane.org/gmane.os.netbsd.devel.userlevel/11570 Few things (not all, probably not most important ones), which worked against Perl, Ruby, Python and so on: - footprint - binary size - cross compiling

Posted by blinkkin on November 17, 2010 at 06:04 PM UTC #

Why 5.1.2 and not 5.1.4 with the latest patch? 5.1.4 was released in 2008, why not import the latest?

Posted by James on November 20, 2010 at 02:08 AM UTC #

@James, actually 5.1.4 was imported, not 5.1.2, so the version number was a typo. Sorry about that.

Posted by Marc Balmer on November 20, 2010 at 07:44 AM UTC #

@Prudhvi Lua is quite clearly easier to interface with C -- it is one of its main goals I'd dare to say.

Posted by Vesa on December 09, 2010 at 09:16 AM UTC #

Nice news. Tks.

Posted by Adrew on November 15, 2011 at 07:47 AM UTC #

Post a Comment:
Comments are closed for this entry.