Slashdot Mirror


NetBSD To Support Kernel Development In Lua Scripting

An anonymous reader writes "NetBSD 7.0 will support the Lua scripting language within its kernel for developing drivers and new sub-systems. A Lua scripting interpreter is being added to the NetBSD kernel along with a kernel API so developers can use this scripting language rather than C for developing new BSD kernel components. Expressed reasons for supporting a scripting language in a kernel were rapid application development, better configuration, and "modifying software written in C is hard for users." In a presentation it was said that Lua in the kernel will let users explore their system in an easy way."

62 of 311 comments (clear)

  1. users? by gTsiros · · Score: 5, Insightful

    "modifying software written in C is hard for users."

    i thought *users* had no business writing device drivers?

    of course if they had said "modifying software written in C is hard for programmers." it would gather a fierce shitstorm.

    --
    Looking for people to chat about multicopters, coding, music. skype: gtsiros
    1. Re:users? by TheRealMindChild · · Score: 4, Interesting

      It seems crazy, but this may not be as braindead as it seems. For instance, a keyboard driver. You just need a read key state->have a look up table to the keycodes function, then pass it on. This is redundant, few lines of code with very little difference between most other drivers. You may not want to write your graphic drivers in it, but not every driver needs bare metal functionality

      --

      "When life gives you lemons, don't make lemonade. Make life take the lemons back!" -- Cave Johnson
    2. Re:users? by KiloByte · · Score: 4, Funny

      So let's invent a sandboxed layer that can interface with the kernel, but can't do damage to it? Also, make the API stable, unlike innards of the kernel. Let's call this novel idea "userspace" or such.

      --
      The creatures outside looked from Alt-Right to Antifa; but already it was impossible to say which was which.
    3. Re:users? by Mindcontrolled · · Score: 4, Insightful

      The moment you even expect that users should, could, would or even remotely in their most maddened fever dreams WOULD WANT to modify the kernel, you lost it.

      --
      Ubi solitudinem faciunt, pacem appellant.
    4. Re:users? by Jane+Q.+Public · · Score: 3, Interesting

      "It seems crazy, but this may not be as braindead as it seems."

      I think that is very much a matter of opinion. And my opinion is: it *IS* just exactly as braindead as it seems.

      Just what we need: "modern" software bloat in the kernel. [sarcasm] Thanks, but no thanks.

      I have right here a program that is more than 45 times the size of the entire hard drive from one of our office computers back in 1994... and that hard drive had a full install of that year's Microsoft Office, plus WordPerfect and Lotus 1-2-3, with lots of room to spare for files.

      Sure... that was '94. But is there REALLY call for programs that large, and by the way slow? And that is by no means the largest application I have on my machine right now. It's on the larger side but I have some many times as big.

    5. Re:users? by MacTO · · Score: 5, Insightful

      Keep in mind that NetBSD users are quite different from Windows/Macintosh/Linux users (at least on average).

      "Hard" may also be a reference to the implementation, rather than the language. Interpreted languages tend to bypass the compile and link part of the development process. This means that interpreted languages are easier to develop with and compiled languages are hard to develop with (at least in some respects). I'd also comment on the arcane nature of C, but I haven't used lua so I don't know if it is any better.

    6. Re:users? by Lodragandraoidh · · Score: 4, Interesting

      Interesting - failure of user space in this way is exactly why we have zero-days.

      I would like to see this happen - but several things make it improbable:

      1. Von Neuman architecture. As long as data and instructions exist in the same space - poorly written apps will allow abuse of it.

      2. Complexity of current software. The more complex the software, the more likely a bug will exist in it that allows #1. Given how programmers stitch together preexisting modules without understanding what is being done on the underlying system - I only expect that to continue expanding.

      It should be instructive that Java was supposed to be that sandboxed layer...and it has so many zero-days it looks like swiss cheese.

      Now - how would we avoid that and make an unhackable userspace?

      --

      Lodragan Draoidh
      The more you explain it, the more I don't understand it. - Mark Twain
    7. Re:users? by Anonymous Coward · · Score: 5, Funny

      I only have 640 KB you insensitive clod!

    8. Re:users? by jbolden · · Score: 4, Interesting

      i thought *users* had no business writing device drivers?

      My non programmer wife wrote a custom device driver in AppleScript, not even knowing what a device driver is. Those sorts of languages can be amazing empowering to end users, and yes there are reasons that end users might want a custom device driver if it is easy enough to accomplish. Though this makes more sense for OSX than NetBSD, I doubt there are many if any non programmers who use NetBSD.

      I had to write a custom device driver for Windows once to get something more like a Unix ethernet driver i.e. bypass some normally quite excellent parts of the Windows networking stack. I was doing software not hardware so I guess I'd consider myself an end user. And that was a pain in the ass.

    9. Re:users? by Natales · · Score: 2

      One possible answer to your point is to use Parallax OS or a similar concept. I find very appealing the self-contained nature of FCAPS to an individual core.

      Interestingly, they leverage Bare Metal OS and the coding is done mostly in Assembly (although C is possible). I think the fattening of all kernels is making these kind of projects look more interesting.

    10. Re:users? by aliquis · · Score: 3, Funny

      The moment you even expect that users should, could, would or even remotely in their most maddened fever dreams WOULD WANT to modify the kernel, you lost it.

      Though it's NetBSD users. Not Apple iPad users.

    11. Re:users? by kriston · · Score: 2

      Lua is all over the Logitech Squeezebox by SlimDevices. It's Tcl for the new generation.

      --

      Kriston

    12. Re:users? by WindBourne · · Score: 3, Interesting

      Exactly. Think about all of the devices out there that are simple ones. I know that my in-laws have BP cuff with USB. I have thought about writting a driver for it, but it just seems like a lot of work for a minimal amount of info. Now, if there is something simple, then this could be useful. In addition, I have been thinking that batteries interface should be standardized. It does not matter wether it is a laptop battery, or a UPS. They accomplish the same thing and the same programs should control them. Simple as that.

      --
      I prefer the "u" in honour as it seems to be missing these days.
    13. Re:users? by jones_supa · · Score: 2

      oh? I also work on my car, home electronics & wiring, carpentry and even plumbing at times. so by your logic I'm an auto manufacturer, fabrication facility, housing contractor.....??

      Yes. In that case you are an amateur auto manufacturer, fabrication facility and housing contractor.

    14. Re:users? by pantherace · · Score: 2

      See?

      It's good for everyone!

    15. Re:users? by Dahamma · · Score: 2

      It is a really simple syntax and reasonably efficient interpreter, and metatables allow a surprising amount of OO design and easy C integration. One complaint is I wish they hadn't made it so minimal as to combine hashes and arrays into one type. I kind of wonder if that's going to be a pain when writing more traditional C-ish driver-type code in this project.

    16. Re:users? by DMiax · · Score: 2

      It won't be hard: tables are implemented with a hash and an array part, so if you only use it as an array they will be efficiently stored. You may find weird to think of 1-based arrays, but it has never been a problem in my experience, since there is no pointer arithmetics to be done in Lua. Plus it's really convenient to develop something in Lua first to get it right, then move the code to C starting from the low level functions once it is stable.

    17. Re:users? by jbolden · · Score: 2

      I don't think that it is really true. I think Lua could evolve to be as strong in applications programming as Python but they choose to fill different niches and so the languages evolved along different paths.

      Lua uses automatic coercion in all instances which makes programs faster to write and harder to maintain.
      Python has a very well defined OO structure.
      Lua doesn't have the huge libraries of functionality Python does
      Lua's lack of high performance arrays
      Lua's lack of unicode is a big problem for applications programming

    18. Re:users? by maxwell+demon · · Score: 2

      Interestingly, the x86 architecture (since the 286) allows to separate code and data on the user level, it's just that operating systems don't make use of that (I don't know whether this is still true for the x86-64 architecture; given that it wasn't used on x86, they might have removed that possibility).

      Of course at the fundamental level, you don't want to do that, because you would take away the possibility to compile programs.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    19. Re:users? by ultranova · · Score: 2

      Just what we need: "modern" software bloat in the kernel. [sarcasm] Thanks, but no thanks.

      A monolithic kernel will inevitably get bloated over time as more features and drivers are added. This is a bad thing because any malfunction in any component has the potential to mess up the entire running kernel. Using a scripting language for less performance-intensive parts is an attempt to mitigate this risk. Whether it's a good idea remains to be seen.

      I have right here a program that is more than 45 times the size of the entire hard drive from one of our office computers back in 1994... and that hard drive had a full install of that year's Microsoft Office, plus WordPerfect and Lotus 1-2-3, with lots of room to spare for files.

      How much disk space does this unnamed program take in proportion to your current disk versus the space taken by any of those programs in the disk you had back then? What does it do?

      Sure... that was '94. But is there REALLY call for programs that large, and by the way slow?

      You seem to believe so, since you have it installed. The rest of us couldn't possibly judge an unspecified program.

      However, I for one remember well the computers and programs of that era. Maybe you should revert back to DOS/Windows 3.1 and associated programs for a week or so? That should refresh your memory on why all the "bloat" was added.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

  2. Performance by Anonymous Coward · · Score: 5, Informative

    Won't that kill performance?

    I mean that's the reason we still write kernels in C. Every cycle counts..

    1. Re: Performance by Anonymous Coward · · Score: 5, Funny

      So we use it for performance. Ok I get it now.

    2. Re:Performance by DarwinSurvivor · · Score: 4, Informative

      Pfff, writing Linux kernels in Javascript is so last century. Nowadays we RUN kernels in Javascript!

    3. Re:Performance by Anonymous Coward · · Score: 2

      Lua is the fastest available scripting language for the task that NetBSD needs it for. It compiles to a byte code, is designed for efficiency and most importantly has excellent hooks for C integration. I have to commend the NetBSD team for their decision - hopefully it will be very successful and lead to a similar implementation in Linux.

    4. Re:Performance by Anonymous Coward · · Score: 3, Informative

      Lua is designed to be a embedded companion language to C. You still use C where it makes sense (i.e. pointer manipulation/performance). You use Lua for expressing higher level logic more easily. Lua is very fast. Writing the same higher level logic in raw C might not be any faster because you have to build up all the infrastructure that Lua has already provided and optimized like associative arrays.

    5. Re: Performance by larry+bagina · · Score: 3, Insightful

      I believe the word you're looking for is "performance".

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    6. Re:Performance by stenvar · · Score: 4, Informative

      Kernel code is like lots of other code: a lot of it is executed rarely and not performance critical. There's setup code, occasional permissions checking, etc.

      In addition, this is not to replace plain C modules (although it may be useful for prototyping), it's for complex and dynamic configurability.

      Right now, there are two ways of handling that. One is to invent complex configuration files and data structures, sometimes even little interpreters. The kernel is full of those. They are error prone, complicated, and require a lot of effort to maintain. The other is to put complex decision making into user-space, but that involves context switches and other overhead. It also means lots of special-purpose and redundant code, and lots of documentation and complexity. The kernel uses both of those strategies extensively, one reason why it's so big.

      Putting Lua+LuaJIT in the kernel is likely faster than either of those approaches, while at the same time also being easier to maintain and document.

    7. Re: Performance by Anonymous Coward · · Score: 3, Interesting

      True. Assembly can be faster than C. In the same way it can be more powerful than C.

      Bottom line is C provides a solution for the complexity of large scale development, without sacrificing the performance, while at the same times still let's the developer be in complete control of his code and data structures.

    8. Re: Performance by Anonymous Coward · · Score: 2, Interesting

      Not really. It's more subtle than that. Straightforward machine code and more explicit code can help performance, or it can hurt. For example, function pointers are slower than inlinable c++ templates or a JIT that can inline across library boundaries or based on observed call frequencies at runtime (all of these at the cost of memory usage). It's not nearly as simple or binary as you're suggesting.

    9. Re: Performance by Anonymous Coward · · Score: 3, Insightful

      Multiple execution units, long pipelines and modern caching makes it hard for assembly to be faster than C. The human brain can not visualize the pipeline like a compiler can.

    10. Re:Performance by 10101001+10101001 · · Score: 4, Insightful

      Kernel code is like lots of other code: a lot of it is executed rarely and not performance critical. There's setup code, occasional permissions checking, etc.

      A lot of it is executed rarely because at least half the code is drivers and one usually doesn't have but one sound card, one (or two) network card, etc vs the hundreds of sound card drivers, hundreds of network card drivers, etc. Further, a major point of the kernel is that it, by design, isn't supposed to be executed a lot because most CPU time should be devoted to user space programs. So, to that end, you could say it's not "performance critical". But, that's more in line with the point that precisely because kernels are generally developed so well, they rarely have "performance critical" code. Once you start throwing scripting into it, I think that goes out the window.

      In addition, this is not to replace plain C modules (although it may be useful for prototyping), it's for complex and dynamic configurability.

      To this, I could see some benefit. But, honestly, I'd feel it safe and saner if it were a language that was reducible to a FSA. The point that "Dangerous code can be disabled at the byte-code level (prevention of endless loop DoS etc)" in the slide really only works in that context, anyways. In any case, Lua is nothing of the sort.

      Right now, there are two ways of handling that. One is to invent complex configuration files and data structures, sometimes even little interpreters. The kernel is full of those. They are error prone, complicated, and require a lot of effort to maintain.

      Which is an argument for making a good, universal FSA language. It won't remove the being error prone or complicated because that's the nature of the beast and papering over it with a Turing complete language is no sort of answer. But having them all share the same language makes sense from a maintenance standpoint. For example, the BPF was repurposed for syscall filtering--a little admission that I'm not sure entirely where BPF stands language wise although I don't think it's turing complete--which could probably be refactored into a more general filtering language which could be refactored into an even more generic FSA language which could likely be used to refactor a lot of other code.

      The other is to put complex decision making into user-space, but that involves context switches and other overhead. It also means lots of special-purpose and redundant code, and lots of documentation and complexity. The kernel uses both of those strategies extensively, one reason why it's so big.

      Generally speaking, context switches aren't a big deal in most OSs/kernels today. Yes, certainly having context switches means an extra overhead and stuffing some code or even all code in the kernel would certainly speed it up. And certainly if a lot more code moved into user space would be measurably slower. But kernel design today seems to try to have a balance between the two, especially with considerations of stability and security. The fact is, lots of code is special-purpose because it's for specific hardware. And code being redundant is more a function of maintaining multiple trees--which admittedly having a single kernel allows a lot of unity--but there's no reason that out-of-kernel-space means out-of-the-kernel-source if the code is still rather kernel specific.

      After all, the whole point is precisely that a lot of potential kernel code is "executed rarely and not performance critical" yet remaining outside kernel memory gives the system greater protection and hence speeds up development and generally makes the code easier to maintain. Documentation is a wholly separate beast, in any case, and that's more a point of maintainers or distributors demanding good documentation before code is accepted.

      Putting Lua+LuaJIT in the kernel is likely faster than either of th

      --
      Eurohacker European paranoia, gun rights, and h
    11. Re: Performance by smittyoneeach · · Score: 2

      *BSD is dying. Perl6 is dying. If they'd just implemented a Perl6 interpreter in the NetBSD kernel, they could have immanentized the eschaton.

      --
      Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
    12. Re: Performance by Kessler · · Score: 2

      Actually, the human brain can do it quite a bit better. This is just a myth people have embraced to justify never using assembly. The only real difficulty for humans is on Intel architectures where you have to deal with the machine conversion of legacy CISC instructions to the actual microinstructions executed by the processor core. On a proper RISC machine, I've yet to see a compiler that can out optimize a human.

      If you want a valid arguments against assembly try portability or programmer productivity.

  3. long overdue by stenvar · · Score: 4, Interesting

    This is a good thing, and it's long overdue. Linux should do the same.

    It's actually pretty easy to get Lua running in the kernel and call kernel APIs; but to make it really useful, it needs additional kernel hooks and callbacks, and that requires cooperation from the core kernel developers.

    1. Re:long overdue by Anonymous Coward · · Score: 3, Interesting

      Exactly.

      With certain algorithms I have LuaJIT code that runs faster than the best C code I can create (I'm speaking with 25+ years of C experience here).

    2. Re:long overdue by Anonymous Coward · · Score: 3, Interesting

      LuaJIT can be seriously fast. But usually when C is slow, it's some compiler flag, or perhaps a bunch of unpredictable branches or random access pattern in the inner loop.

      Pretty often the LuaJIT trace machine code generated is similar to what you'd get from gcc. That's how good it is.

    3. Re:long overdue by stenvar · · Score: 2

      I don't know what you mean by "pretty abysmal, performance wise". Lua is one of the fastest scripting languages around, even without LuaJIT.

    4. Re:long overdue by sourcerror · · Score: 2

      I would be happier if the major window managers supported Lua. I'm not sure I would want to mess with device drivers.

    5. Re:long overdue by stenvar · · Score: 3, Insightful

      It's not mainly for messing with device drivers (although it may be useful for that too).

      It's mainly useful for all the stuff that people right now create /proc devices, ioctls, and user-level kernel-related daemons for. Those mechanisms are both slow and complicated. With Lua in the kernel, a lot of that stuff can be handled much more easily, without the overhead of context switches and with much less code.

      It probably won't replace all the bloated configuration stuff that already exists, but at least when writing new device drivers and new functionality, developers could save a lot of time and effort.

    6. Re:long overdue by AuMatar · · Score: 3, Insightful

      They use Lua for the non-performance effecting parts of games. They'd never consider using it in the graphics code, which is the bottleneck.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    7. Re:long overdue by samkass · · Score: 2

      They use Lua for the non-performance effecting parts of games. They'd never consider using it in the graphics code, which is the bottleneck.

      Does World of Warcraft lay out its entire UI with LUA? Then render the actual 3D graphics with C/C++? Isn't that exactly like what we're talking about here for drivers-- high-level control in LUA and the heavy lifting in C?

      --
      E pluribus unum
  4. Great idea. by Meshugga · · Score: 5, Interesting

    I honestly think that this is a great idea. It's a novel approach to extending a kernel, especially considering NetBSD doesn't have that big of a market share and expressly focusses on supporting as many platforms as possible. Prototyping new features or certain drivers in a portable scripting language may give them a leg up in the functionality aspect of the race.

    Also, LUA is super fast, small, easy to learn, concise and the C API/embedding it is straight forward.

    You may knock it all you want, "because kernel land is C land", but after all bias being said and flamed, this may turn out to be a really fun, interesting and possibly very useful idea.

  5. Re:My P4 by jones_supa · · Score: 2

    That sounds quite cool, but how can you cope with only the terminal?

  6. Re:Fucking LOL. by Anonymous Coward · · Score: 3, Funny

    Linus?

  7. Re:My P4 by MacTO · · Score: 3, Interesting

    It depends upon what he needs the computer for. If it is a server, then there is no need for a GUI. Even with respect to application software, there are a multitude of options out there. Writing can be done in text editors, then processed with TeX or troff (for formatted output to a printer, when necessary). There are a multitude of email clients and several web browsers. I've never really tried it, but you can even do graphical design with languages like PostScript and POV. Media? Again, you have access to many audio players. It's much more gimmicky in nature, but you can even play videos on text consoles.

  8. This is cool already, but with RUMP, OMG by Anonymous Coward · · Score: 2, Insightful

    This is awesome. What is old is new again. Lisp machines were some of the most beloved equipment for os and ai hackers because of the ability to get to the underbelly easily. This is no different. Making the operating system more approachable makes doing operating systems research easier. This is a great idea.

    Besides, it's a natural extension of the RUMP kernel paradigm. If you can run a netbsd kernel, as part of a userspace process on linux, then it only makes sense to be able to talk to these 'kernels' under the hood easily. THIS IS WAY FRIGGING COOL.

  9. Re:My P4 by MacTO · · Score: 2

    And, of course, very few development tools actually depend upon a GUI.

  10. Tags by Areyoukiddingme · · Score: 5, Funny

    Surely this article deserves the whatcouldpossiblygowrong tag more than any other this year. And possibly last year too...

  11. Wikipedia (MediaWiki) is also deploying Lua by yurik · · Score: 2

    MediaWiki developers are almost ready for Lua scripting to be enabled for all Wikipedia and related sites, and It has already been deployed to http://mediawiki.org./ Lua was chosen mostly because of how easy it is to sandbox and limit memory consumption.

    http://www.mediawiki.org/wiki/Lua_scripting/Tutorial -- Introduction

  12. Re:Stupid NOT by Anonymous Coward · · Score: 5, Interesting

    I don't know how much Unix/BSD/Linus code you have read or written, but I have been developing core code, Scheduler, MM and Drivers since 1980 and this is a great idea, long overdue.

    The Abstractions are now well understood and most code dos't need to be quick, but safe, putting PRE in kernels will clean up acres of cockamamie code now written in C, most of which just runs at boot time and is then freed. ... there are exceptions, you cant't have the garbage collector running whenever it likes, eg in the middle of an interrupt routine, but managed memory, not C, C++ scoping is the way to stop slow memory leaks.

    Put simply you are an idiot and dont know what you are talking about.

    MFG, omb

  13. I suggested this years ago for Linux by Theovon · · Score: 2

    With the BSD's, there no such thing as a tainted kernel. But with Linux, non-GPL drivers are actively discouraged. If they were to add scripting to the Linux kernel, it would actually make it easier to write proprietary drivers, so they'd never go for that. Forget the fact that it would make it a hell of a lot easier to sandbox drivers so they don't clobber other kernel memory. Forget the fact that code in a higher-level language is smaller; countless drivers would suffer no appreciable performance hit by being written in an interpreted language (especially Lua), so you'd have one small interpreter and many shrunken drivers, which would make the kernel memory footprint smaller. Forget the fact that mutually exclusive access to shared variables could be made implicit in a majority of cases, eliminating a whole class of bugs in one shot. No. We've got our precious GPL to protect. (Oh, and forget the fact that nVidia basically gets a free pass on this.)

  14. DSL's are already in the BSD kernels by Fyzzler · · Score: 2

    There are multiple non-"C" DSL languages and virtual machines in the BSD kernels already and they have been there for over 20 years.

    Here is a prime example http://en.wikipedia.org/wiki/Berkeley_Packet_Filter

    Lua is a very clean, small, and relatively fast object oriented language. It is probably the best possible choice for a general purpose dynamic language to embed in a kernel.

    --
    I have one question. If the Japanese Ministry of Agriculture is not in charge of Gundam, then who is?
  15. Re:Stupid by dalias · · Score: 4, Interesting

    It is potentially stupid, but the reason is much more subtle than most people realize. For all its limitations and headache, C does have one key feature that makes it suitable for kernel programming where most other languages are not: the concept of well-defined storage durations and reserving storage for an object. I really question whether Lua code running as part of the kernel can be made robust under out-of-memory conditions which a kernel must be able to survive.

  16. Re:Stupid by Anonymous Coward · · Score: 2, Insightful

    No, if you understand how Lua glues C code together, this is brilliant.

  17. Re:Stupid NOT by countach · · Score: 2

    But if it doesn't need to be quick, why is it in the kernel in the first place? I would have thought that if you are tempted to put a scripting language in the kernel, it's a pretty good indication that the division between kernel and non kernel is somehow wrong.

  18. lua vs perl stats by cheekyboy · · Score: 2

    http://benchmarksgame.alioth.debian.org/u32/benchmark.php?test=all&lang=perl&lang2=lua

    In some tests, one is faster than the other, but by no more than 4x to 1/9th each way.

    At least they didnt choose ruby.

    --
    Liberty freedom are no1, not dicks in suits.
  19. Re:Stupid NOT by Atzanteol · · Score: 2

    Won't somebody think of the precious CPU cycles!

    --
    "Ignorance more frequently begets confidence than does knowledge"

    - Charles Darwin
  20. Re:Stupid NOT by cnettel · · Score: 2

    Process A calls kernel. That's okay, kernel-userspace transitions can be reasonably fast. Function called is actually implemented in userspace process B. Whoa, context switch. You can easily have a 100x slowdown in your kernelspace interpreter and still come out ahead compared to incurring that context switch. This all assuming that the driver will not do a lot of complicated processing. Rather, it will probably just need to check some basic data structures to identify whether the operation is currently allowed and maintain some shared state between processes. (Not) surprisingly enough, that's all there is to many drivers. I would even think that some file systems currently implemented in FUSE would be faster using a reasonably well-behaving "safe" kernel language.

  21. Re:Stupid by aaron552 · · Score: 2

    And yet it is so useless without the concept of destructors.

    s/useless/cumbersome

    --
    I had a sig once. It was lost in the great storm of '09.
  22. sandboxed lua by stenvar · · Score: 2

    Lua interpreter instances are small. In a kernel environment, you'd like run lots of tiny Lua interpreters, one for every "task" you want to perform. You can impose limits on memory and CPU usage on each instance. Under an out-of-memory condition, you can also ask each of them to reclaim a maximum amount of memory, via a hook and via the GC interface. And if that fails, you can start killing them off one by one in order of least importance, just like you might with other processes or functions. The fact that Lua has better defined semantics and interfaces for resource management than a chunk of C code means that it's actually easier to deal with out of memory conditions with Lua interpreters than for general C code.

  23. Re:Stupid by K.+S.+Kyosuke · · Score: 2

    What? have you any idea how many interpreters and the like 'glue' C code together, just about all of them and many do it better such as JavaScript.

    Hahaha. Lua was *designed* to do just that. BTW, take a look at how LuaJIT extends what Lua already provides. You can directly manipulate C structures from LuaJIT - define new structure types *at runtime*, malloc them, fill them in, pass them arround, whatever you need to do with them.

    Not to mention that JavaScript or ECMAScript is utilized my millions.

    Lua is a MUCH better language than ECMAScript. Just consider issue number one: variable scoping. Lua: Essentially derived from the Scheme LET for or the functional languages (ML family style LET). Javascript: horrible hack, variable bound anywhere in the function has scope extending to the region before its initialization.

    Lua also doesn't need to have use FP arithmetics, it uses it by default but you can switch to integers. JS requires FP, and at least the Linux kernel doesn't allow FP inside. Or at least it didn't when I checked the last time, whatever the reasons were (faster context switches, perhaps? I really don't remember...) Overall, as far as embedding is concerned, it's definitely much more developer-friendly than any mainstream JS implementation I'm aware of.

    --
    Ezekiel 23:20