Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Lua is a joy to work with, one of my favorite (scripting) languages.

Having tables as the primary underlying data structure gives it a very LISP-y feel despite having an ALGOL syntax, providing a nice middle ground between the two styles.



Lua really is a joy, and after 40 years of software development is still one of the top ways, in my personal list, to get serious software built.

I've done quite a few projects where I built a library of C modules to do the heavy lifting for some particular purpose (data in/out mostly), glommed these functions into the LuaVM, then built the application logic, very rapidly and smoothly, in Lua - outcompeting others working in my group with their big fancy stacks of stuff, time and time again.

I think its really important for any developer, whether they are encased in the glories of the browser or otherwise, to understand how to add the Lua VM - to anything - and then use that as a means of productive application development.

Its very rewarding once you get the VM glomming happening and can start accessing everything you need from within your own scriptable execution environment. More programmers should learn this technique, imho - it moves us from being effected clients of someone elses' ball of string and wax, to actually causative developers building architecture that really, really works.

Whether you like Lua or not, building-in a VM for your higher-level application logic is just good architecture.


I discovered this technique only a few months ago, and couldn't agree more. I also cannot believe I've missed out on it for so long, having been a software engineer professionally for 13 years now, with 10 years of computer science specific education before that. How is this not taught in every computer science curriculum?


I think it once was taught, but was considered passé in various places during the "Java" revolution, and in general I think there is a degradation of capabilities in most comp-sci programs, a consequence of interference by market players who invest in the schools in order to keep their technologies relevant.

If anyone reading this wants to see what the fuss is, you can get started very easily with antirez' (Redis fame) simple toy project, LOAD81 - which is a great example of just how powerful things can get when you bring Lua into your life. (http://github.com/antirez/load81.git) - note that this is a great project to learn this technique, but if you do anything interesting in the load81 context - please push it back to LOAD81. :)


There's also the book "Creating Solid APIs with Lua" by Tyler Neylon [1,2] which seems to be quite specifically addressing this idea of embedding lua in something so as to implement highly-movable application logic in lua rather than the something you started out with.

[1] https://www.oreilly.com/library/view/creating-solid-apis/978...

[2] https://github.com/tylerneylon/APIsWithLua


Thanks a lot! Never heard of this book. Will read it and mention it in the article if I enjoy it. :)


Great references, thanks for that! I'll add that book to my library and give it to folks when I recommend they learn the VM+execution environment technique.


It's a shame that Java (and JavaScript) replaced the "Lua with C/C++/whatever" approach. JavaScript is incredibly hard to write in a "correct" way. It has way too many quirks and an incredibly complex tooling system (npm, etc.).

Lua is pretty much a "minimal" language which gets things done. It's not perfect, but it certainly doesn't suffer from the bloat which many other languages have.


I agree with you completely, Javascript has been a step backwards from what could have been, had we been teaching teenagers to glom the VM onto C/C++ layers. This is just a much better approach than 'npm all the things' .. although Lua isn't without its warts: LuaJIT, LuaRocks, 5.1, 5.2, 5.3 ..


Yeah, we're also employing that same architecture to great effect. A really nice side-effect is that you can reconfigure your app easily without recompiling. It really speeds up iteration times.

We can also have a small core team writing C/C++, and then let a wider team loose to build applications with Lua.


"I think its really important for any developer, whether they are encased in the glories of the browser or otherwise, to understand how to add the Lua VM - to anything - and then use that as a means of productive application development."

I completely agree! I feel that I should add thoughts about this into the article.

A lot of people (justifiably) complain that C and C++ are not memory-safe and that it's hard to write readable and safe code in it. Lua allows you to hide the scary parts of C and C++ and write simpler and safer code by default.


Definitely. And I think one of the reasons this approach is so powerful as well as being safer - when done properly - is that it follows the philosophy embodied in the OSI model. By glomming the VM onto a hierarchy of abstraction, one is fulfilling the OSI intention of clean separation of concerns.

This isn't so easy to do in the Javascript jungle, alas.

Happy to read your article, we are very much aligned. I hope your work brings more programmers to the world of Lua ..


I imagine this speeds up development velocity and is easy to adapt to a changing environment.

I think Python is an example of the same pattern, you write your glue code in Python and the high performance code is in C called by C FFI from Python.

I just wonder how we can write code with development velocity of Python or Lua but actually evaluate extremely fast.


Write the code in pure Lua, ship only the LuaJIT'ed bytecode...

Okay, not workable for every Lua project, but for most it'll be fine.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: