5 ms·
What are some projects that people are using that use Lua? Why use it over something like python for scripting?
by j_m_b 6y ago
What are some projects that people are using that use Lua? Why use it over something like python for scripting?
- stevedonovan 6y agoProbably because Lua is meant to be embedded in an application and provides a small, highly optimized VM. On my system Lua is smaller than PCRE.
- stevekemp 6y agoI wrote a console-based email-client, using Lua for all configuration and scripting needs. Using Lua is generally done because it is easy to embed inside a host-application. While it is possible to embed Python, Perl, or other languages, they're relatively heavyweight and not so commonly used in that case. In my own application I always felt annoyed that mutt didn't have "real" scripting. Just an ad-hoc configuration that made lots of things possible, but neglected some basics (such as loops and similar). Configuring a mail-client in Lua was a nice exercise, but eventually I moved on to pay for gsuite rather than self-hosting a mailserver of my own so it became a "done" project. Definitely a useful learning experience though, experimenting with user-interface, embedded scripting, and going through lots of learning relating to MIME-handling & etc.
- fit2rule 6y agoYour project sounds cool - is it possible to process email with Lua scripts, so that I could use a mailbox as a business process queue that is also user-friendly, while having a suite of Lua apps processing the mailboxes? If so, care to share details of your project if its open/available?
- stevekemp 6y agoIt wouldn't be impossible to iterate over a series of mails, and get the message-bodies, but it would be a bit fiddly and annoying as the program was more designed as an email-client. https://github.com/lumail/lumail/ https://github.com/lumail/lumail/ https://lumail.org/ https://lumail.org/ Honestly I'd probably write something in perl/go/similar to just walk over a remote IMAP mailbox: * Search for messages that are unread, or which don't have a given tag. * Process each one. * Mark as read, or add a tag. (I actually did something like that recently for processing DMARC reports.)
- fit2rule 6y agoNeat project - thanks for sharing. I really like the idea of having a Lua-backed email app which can be used to do mail processing ..
- masklinn 6y agoLua is way more common for game scripting than Python. One of the few major games which used Python I can think of was Civ IV, and Civ V switched to Lua. Lua is smaller, easier to embed interface / interact with (e.g. it's way less ceremony to expose a native function to Lua than to Python), and tends to be faster, especially when jumping back and forth between the engine and the scripting. Embedding / scripting (within a larger program) is the original use-case of Lua, not so Python. I believe it's also much easier to secure / sandbox (remove bits you don't want script writers to have access to) as well, the stdlib is smaller and I think it has less interactions between modules. Python embedding / scripting tends to be more common for software where the securing / restriction aspect is smaller but flexibility & larger embeds are necessary e.g. 3D, CAD and other "production pipeline" software tends to be scripted with Python.
- pansa2 6y ago> I believe [Lua is] also much easier to secure / sandbox [than Python] Yes. C code that embeds the Lua VM has total control over which functions are exposed to the Lua code. It's possible to create a VM that, for example, has no access to the filesystem. AFAIK it's not possible to do that if you embed Python. Dangerous functions like `open` are always available and sandboxing facilities have to try and prevent untrusted code from getting a reference to them. Unfortunately, there are numerous ways to work around these restrictions and obtain access to dangerous functions, e.g. via `__builtins__`. Another reason running untrusted Lua code is considered fairly safe is that the VM is well-engineered and has a history of very few bugs [0]. However, the latest 5.4.0 release seems to have more bugs than older releases. It might still possible for untrusted Lua code to use 100% CPU and hang a program, or to read data from the embedding process using a Spectre-style attack (although even that's unlikely because the Lua VM is an interpreter rather than a JIT compiler). However, it's quite possible to secure an embedded Lua VM to prevent it from doing things like accessing arbitrary files. [0] https://www.lua.org/bugs.html https://www.lua.org/bugs.html
- formerly_proven 6y agoSandboxing Python used to be and still is hairy and very hard (it requires intricate knowledge of CPython, because you are going to inspect the AST for unwanted things and do some other relatively low-level stuff) and Python is also a pretty big dependency (~5-10 MB). I think many recent-ish additions to Python may make sandboxing easier (e.g. audit hooks, subinterpreters), but it's still hard and messy.
- chgibb 6y agoWe're using Lua as a base for bringing Flutter into other languages https://github.com/chgibb/hydro-sdk https://github.com/chgibb/hydro-sdk
- gumby 6y agothe easiest way to put it is that you embed Lua into your app (say scripts that are loaded at startup or even as a command line) while it’s more natural to embed your external functionality into Python (e.e. numpy). It’s simpler to connect lua to your c/c++ datastructures than it is to connect Python, and it’s more complicated to write little things in Python. Sometimes it’s easier to grab a pencil and scribble a little note on a piece of paper. Sometimes it’s a lot more useful to type a note into your phone or computer than to deal with paper.
- pkphilip 6y agoI have embedded lua in Spring Boot webapps where I required an external rules files which could be easy to read for business folks. Example: Specialised handling for different customer types and you don't want to manage all the rules in the RDBMS but would rather run a separate script for each customer type and have this script in a plain text format and version managed using Git.
- harryvederci 6y agoSounds very interesting! Any chance this is open source? If not, can you give a bit of additional information on how you did this (including project structure, some insight in the lua code, etc)?
- pkphilip 6y agoUnfortunately, no. This was done for a client and is proprietary.
- jmiskovic 6y agoI've made a suite of digital musical instruments for Android phones in Lua. Now I'm using same language to build some VR prototypes. Here are some benefits of Lua over Python. It's really powerful language (anonymous functions, closures, tail-call optimization, full lexical scoping, coroutines...) that supports many paradigms, and yet it is tiny and elegant. There are few surprises and everything is explicit. Runtime is easily embeddable, which means it will be more readily available on exotic platforms. The interpreter is much faster than Python. C code is effortless to call into with FFI and resulting code looks just like normal Lua. Not everything is roses. I prefer readability and less verbosity of Python. The 1-indexing needs some getting used to. Batteries are not included (to be more portable), so there are dozens of implementations of basic things like serialization, OO classes and table copying. Most online material (wiki) was written very long ago and it's full of language proposals that never succeeded. Some valuable resources can be found in documentation of hosting frameworks (Defold, Solar2D, Roblox, ComputerCraft, WoW).
- formerly_proven 6y agoLua is a tiny, relatively simple language with a simple data model built on a small runtime that's very fast for an interpreter and easy to embed into C/C++ applications (once you dealt with the stack, mentally or otherwise). Startup time is ~nil. Python is a large, complex language with an exceedingly complicated data model built on a runtime where the core interpreter is about ~4 MB, which is also a pretty slow interpreter (mostly due to the exceedingly complicated data model). Python is certainly not hard to embed on an API level, but somewhat annoying to package up for a build. Python is very hard to sandbox, whereas Lua is basically sandboxed by default. Startup time is on the order of ~100-200 ms.
- spc476 6y agoI use it at work to process SIP messages on behalf of a cellular carrier. The actual parser is written using LPEG, a parser expression grammar for Lua. Because Lua is meant to be embedded, it only has the functionality required to do the job and no more.
- anonymoushn 6y agoIf I use Python instead of Lua for monte carlo tree search, my machine will page out, and even before it pages out, my training pipeline will be running dozens of times slower than it was with Lua. If I use Python instead of Lua to make a game, I will not be able to update my game state and render all my images at 60hz. If I use Python instead of Lua to write programs that do many tasks at the same time, I will have to write "await" a thousand times instead of 0 times.