
Lua in the NetBSD Kernel [pdf] - profquail
https://fosdem.org/2013/schedule/event/lua_in_the_netbsd_kernel/attachments/slides/278/export/events/attachments/lua_in_the_netbsd_kernel/slides/278/kernel_mode_lua.pdf
======
AlexanderDhoore
I was at this talk @ fosdem. Pretty cool stuff.

He said he considered java (there have been attempts to write drivers in java)
and python. Python didn't make it because of high ram usage (java wasn't any
better). He didn't look into ruby, but "not for any particular reason".
Probably because embedding ruby is quite hard compared to python or lua.

Very interesting talk!

~~~
pm90
Do you know if that talk was recorded, by any chance? I checked here
<http://video.fosdem.org/2013> but couldn't find it there

~~~
AlexanderDhoore
It wasn't recorded. At least not officially. Fosdem has so many rooms, I think
they just give up at some point. It's a shame though.

Edit: Just checked and there are videos for only one devroom. And there were
around 30...

~~~
threedaymonk
The graph processing room was recorded, as were the lightning talks, but I
don't know if those videos are available yet.

------
cpressey
As someone who once threw together a Lua kernel module for FreeBSD 4 just for
fun, I approve of the idea -- although I don't know how useful it is.

Being able to rapidly prototype kernelspace things is probably the main
advantage. I'd think twice about actually running garbage-collected code in
the kernel in production. And the slide that touts that it's easy for users to
modify -- yes, well -- you could easily argue that it shouldn't be easy for
users to modify what's in the kernel :)

~~~
AlexanderDhoore
Indeed, prototyping functionality is the main point here. The whole system
isn't even part of the default install and can be turned on/off.

Easier is always good. It's still far from easy though.

~~~
Nelson69
I've seen this on an embedded product that has been sold for years.

The license is liberal, it's remarkably easy to work with Lua, is can
basically call any of your C functions. Great for debugging stuff,
prototyping, certain kinds of monkey patches. Great for doing unit test like
experiments too; you can have some Lua put the system in to a particular state
and then do your experiment.

~~~
AlexanderDhoore
How would you compare it with python for things like unit testing c code? Here
lua is chosen because of it's small footprint, but for testing that doesn't
really matter.

~~~
reddit_clone
Lua is multi-threading friendly. It is allowed and easy to run multiple VMs in
different threads in the same process.

------
vor_
Lua sometimes drives me nuts, but it's such a humble little language that you
can't hate it for too long. There are alternatives I would have preferred,
like the Lua-inspired Squirrel (<http://http://squirrel-lang.org> ), but Lua
is the most well-known and is written in plain C, which is likely appealing to
a BSD project. I'm interested to see if this gains any popularity and if the
other BSDs show interest.

~~~
StavrosK
How does it drive you nuts?

~~~
rwmj
Arrays based on 1. The odd and slightly under-documented stack that you have
to use when interfacing it with C. Global variable scope by default. Tables
(.. are both good and bad). Not standard named operators like '=~' and ':'.

Having said that, it's not a bad language. It has an excellent community, who
really went to great lengths to help me writing the Lua libguestfs bindings.

<http://libguestfs.org/guestfs-lua.3.html>

~~~
snogglethorpe
The 1-based arrays are theoretically annoying (I'm a C guy), but in practice I
find they simply aren't an issue, I guess due to the differences in typical
programs for each language. "~=" is unusual (I too wish it used "!=") but
other than that, Lua's pretty much like everybody else (":" doesn't really
count because it's an operation that doesn't exist in most languages).

"Global by default" can be annoying, but at least it's better than "local by
default" like python etc. [As a programmer, who'd rather find bugs easily than
save some typing, I think better than either would be "nothing by default, you
gotta declare your variables", but that might not be popular for "dash off a
quick script" usage; maybe make it configurable based on the load context or
something?]

But this:

> _The odd and slightly under-documented stack that you have to use when
> interfacing it with C_

... seems almost bizarre. Lua's C interface is probably the most elegant and
usable I've ever seen. A stack is the _classic_ abstraction to use for this
application, Lua's implementation is well-designed, and Lua's API
documentation is both comprehensive and very well written.

------
klrr
How does this really work, is it possible to write such stuff as drivers with
a garbage collected language?

~~~
pjmlp
Yes.

There are operating systems written in system programming languages with GC.
Check Native Oberon and A2 for desktop operating systems used at Zurich's
university.

Smalltalk was originally developed as OS. Only the so called primitives were
done in Assembly, with the remaining parts in Smalltalk itself.

Sun played around with Java in Solaris for device drivers and Squawk is a VM
that runs directly on hardware with device drivers written in Java, as an
example.

~~~
rwmj
Also OpenMirage, written in OCaml straight to the "hardware" (where "hardware"
is a Xen virtual machine). <http://openmirage.org/>

------
wildchild
Could anyone explain, why Lua is so special?

~~~
eric_bullington
It's very small, fast, and uses little memory. It's easy to learn and easy to
interop with C. It's got two great implementations, with one (LuaJIT) probably
holding the top spot among all dynamic, garbage-collected language currently
in existence, measured by performance (although the creator -- `mikep` on HN
-- is very careful to avoid making this sort of claim).

It's also got one of the coolest GUI toolkits around in IUP. If you've ever
wondered by a cross-platform GUI toolkit that uses native widgets has to be so
huge and complex, IUP's what you're looking for. Unfortunately, IUP doesn't
yet have a native OSX driver, but you can use motif graphics driver to build a
program that will run on OSX. Like Lua, IUP's in portable C, so a number of
other languages have built bindings, notably go and perl. Like Lua, IUP has a
very liberal license license (MIT), so you can use it for commercial projects
without worrying about dynamic or static linking.

~~~
arundelo
Correction: LuaJIT's creator Mike Pall is
<http://news.ycombinator.com/user?id=mikemike> .

~~~
eric_bullington
Thanks for the correction. I should have verified the HN username for Mike;
not sure where I pulled `mikep` out of since I always enjoy reading his
comments here and elsewhere. It's too late for me to correct it in my original
comment, so thanks again.

------
fafner
Similar to this SnabbSwitch is a virtual Ethernet switch for Linux written
mostly in Lua (using LuaJIT).

<https://github.com/SnabbCo/snabbswitch/wiki>

------
lemcoe9
Oh my god, I may have fallen in love with that PowerPoint theme...

~~~
profquail
I think it's one of the standard themes for Beamer (LaTeX package for creating
presentations):

<http://www.hartwork.org/beamer-theme-matrix/>

------
markwong
will the backward compatibility of Lua be a matter?

