News for hackers. Stuff that matters.
Re:Porting Python to GRUB: “Networking without an operating ... by sandGorgon on Wednesday July 13, 2016 @02:41AM (#12084299)
why would they not use lua ? which is pretty popular (and pretty much designed) as embedded scripting languages. Not to mention much more lightweight than python.. and has a much smaller footprint.

Nginx is a pretty good example of this.

Re:Porting Python to GRUB: “Networking without an operating ... by JoshTriplett on Wednesday July 13, 2016 @03:03AM (#12084377)
> why would they not use lua ?

The target audience for this is BIOS developers and firmware engineers. Several existing development tools in that area already support Python, including Simics and the Intel ITP, so the target audience is used to it.

Lua also has several other impedance mismatches with the target audience, such as 1-based array indexing (remember, the target audience writes assembly and C).

While people often describe Lua as "easy to embed", personally, I don't find Lua's stack-based C API easy at all; in particular, the references to stack-based indexes that change when you push or pop the stack feels like working with stack-based parameters in assembly without a base pointer, where the offset of a given location can change at any time. I much prefer the Python C API.

Finally, Lua would require additional libraries to provide a useful environment, precisely because it can assume so little about its environment. For instance, we'd need to bundle one of the Lua socket libraries in addition to Lua itself, as well as an HTTP library. Python's "batteries included" standard library works nicely here.

Re:Porting Python to GRUB: “Networking without an operating ... by sandGorgon on Wednesday July 13, 2016 @03:14AM (#12084425)
thank you for that. That explains a lot ! But Lua is already in Grub right ? wouldnt it have been more effective to just extend that anyway ?
Re:Porting Python to GRUB: “Networking without an operating ... by JoshTriplett on Wednesday July 13, 2016 @03:57AM (#12084600)
Lua isn't part of upstream GRUB; it lives in a separate module, "grub-extras". As far as I can tell, it also wouldn't be easy to extend that with additional functionality or modules without forking it, due to the way GRUB builds out-of-tree modules.

Note that this port of Python is almost as old as grub's Lua; we've been working on BITS since ~2009, and it has had Python support since May 2011.

For reference, the Python port consists of less than 1000 lines of code, most of which provides compatibility implementations of standard C and POSIX functions that Python expects. (Plus another couple thousand lines implementing additional C Python modules like "_smp", "_acpi", and "_efi", but those are getting smaller as we move more code into Python using ctypes.)

Re:Porting Python to GRUB: “Networking without an operating ... by mwcampbell on Wednesday July 13, 2016 @04:04PM (#12089201)
> I much prefer the Python C API.

Your other reasons for going with Python make sense, but this one surprises me. Isn't the Python C API's reference counting tedious? I've written bindings to C libraries for both Python and Lua. With Python, I always use something higher level than the Python C API, like Cython or ctypes. With Lua, I've cranked out lots of bindings using the Lua C Api directly.

Re:Porting Python to GRUB: “Networking without an operating ... by JoshTriplett on Wednesday July 13, 2016 @04:16PM (#12089308)
The reference counting is annoying, yes; however, it's the cost of allowing C to hold references to Python objects.

I find a single call to PyArgs_ParseTuple at the top of a Python C entry point much nicer than referencing various values off the Lua stack as they move around.

That said, we're in the process of rewriting as many of those functions as possible from C into Python itself, using ctypes.

Re:Porting Python to GRUB: “Networking without an operating ... by __b__ on Wednesday July 13, 2016 @09:38AM (#12086011)
"... the target audience writes assembly and C)."

In C, I make frequent use of "switch" statements.

Does CPython have a switch statment?

Re:Porting Python to GRUB: “Networking without an operating ... by dalke on Wednesday July 13, 2016 @10:13AM (#12086261)
The context is that Lua has "several other impedance mismatches" beyond Python, not that Python-the-language is like C.

Note that Lua also does not have a switch statement: http://lua-users.org/wiki/SwitchStatement .

Re:Porting Python to GRUB: “Networking without an operating ... by __b__ on Wednesday July 13, 2016 @10:47AM (#12086525)
I made no mention of Lua. The context is C and assembly programmers as an audience.

But let's consider Lua. Most of the Lua pogrammers I know also know C. How do they handle the so-called "impedence mismatches"? (Should this be plural? What else besides 1-based arrays?)

As far as I know Lua's target audience is, at least in part, C programmers. That's why it's made to be easy to embed in a C program.

Re:Porting Python to GRUB: “Networking without an operating ... by dalke on Wednesday July 13, 2016 @11:51AM (#12087145)
JoshTriplett's comment was a response to "why would they not use lua?" The points were all made relative to "C and assembly programmers" using Python vs. the same using Lua.

You can't simply pull a few words out of the comment and assume it means there is no mismatch what C programmers expect and what Python offers. It doesn't mean that and wasn't meant to mean that.

You wrote "Lua's target audience is, at least in part, C programmers". That is also true of CPython. Bear in mind that these facts aren't that relevant. This code is not mean for the wider class of "C programmers". The relevant bit is "the target audience writes assembly and C". This is far different than "the target audience is assembly and C programmers", which appears to be what you think it says.

Instead, the target audience is the narrower class of people writing EFI binaries and working with the EFI protocol. As JoshTriplett further clarified, the "existing development tools in that area already support Python", but apparently not in Lua.

Re:Porting Python to GRUB: “Networking without an operating ... by __b__ on Wednesday July 13, 2016 @12:11PM (#12087329)
To sum up, the target audience was EFI developers who would prefer to write Python than write assembly, C or Lua.

No problem. I get it.

Re:Porting Python to GRUB: “Networking without an operating ... by metalliqaz on Wednesday July 13, 2016 @11:58AM (#12087208)
Found the Lua developer!
Re:Porting Python to GRUB: “Networking without an operating ... by SixSigma on Wednesday July 13, 2016 @03:23AM (#12084468)
Why would they not use C?

Or forth, or any number of alternatives.

You would get the same question with the names shuffled around whichever one you chose.

Re:Porting Python to GRUB: “Networking without an operating ... by coredog64 on Wednesday July 13, 2016 @08:46AM (#12085700)
If you want forth in your BIOS, buy a Sun workstation.

/snark:off

Re:Porting Python to GRUB: “Networking without an operating ... by detaro on Wednesday July 13, 2016 @03:05AM (#12084386)
Speculation: At least for the given Intel use case, lightweight doesn't sound to important: they can use the entire machine. And given the fairly specialist application, porting a language experts and users are familiar with (or maybe was used in existing tooling) might be better.
Re:Porting Python to GRUB: “Networking without an operating ... by chungy on Wednesday July 13, 2016 @02:47AM (#12084316)
GRUB already has Lua, so I imagine the answer is "because we can"
Re:Porting Python to GRUB: “Networking without an operating ... by sandGorgon on Wednesday July 13, 2016 @03:16AM (#12084431)
interesting. I never knew that... i wonder if any additional socket library dependencies were problematic in the lua world.
Re:Porting Python to GRUB: “Networking without an operating ... by Bromskloss on Wednesday July 13, 2016 @02:54AM (#12084342)
What is it that makes the language suitable for being embedded? Actually, what does it mean to be embedded?
Re:Porting Python to GRUB: “Networking without an operating ... by imtringued on Wednesday July 13, 2016 @03:54AM (#12084582)
You can launch a lua vm with an empty environment table (in other words no standard library). This means only the functions you manually put into the environment table can be used which makes sandboxing extremely easy. I must admit I've only used luaj where interop to java boils down to something like http://stackoverflow.com/a/19629914 and you can optionally use reflection for even easier intertop if I recall correctly.
Re:Porting Python to GRUB: “Networking without an operating ... by walkingolof on Wednesday July 13, 2016 @08:27AM (#12085580)
Lua as mentioned before is very suited to run in an embedded environment because of it small size (both when executing and the actual source code size) and its modules, which makes it trivial to remove everything except the core language (IO support etc).

I'm running Lua on a DLX like processor implemented on a fpga, in this context Lua performs the same role as Basic did on many home computers in the 80's, a small IPL is setting up the machine and loading Lua on boot.

Re:Porting Python to GRUB: “Networking without an operating ... by agumonkey on Wednesday July 13, 2016 @03:00AM (#12084367)
Lua is extremely small, simpler, and has a jitted version. It's been used extensively as a scripting language in video games so has more mileage in constrained environment. Never used it really, just stating what other people say.

And luajit author, Mike Pall, is extremely skilled.