Replies: 2 comments 7 replies
-
I have worked extensively with both Lua and Python as embedded languages (both developing scripts and adding script support to C++ engines). There isn't, in my opinion a single reason to use Lua over Python. Python's syntax is world-class, its API is infinitely ahead of Lua and its popularity is unparalleled as the second most-wanted language only behind Java Script https://survey.stackoverflow.co/2023/#section-admired-and-desired-programming-scripting-and-markup-languages Even the common myth that Lua is faster, often brought-up as Lua's one saving-grace in the exact debate of Lua versus Python is also a blatant lie as both have equivalent performance: https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/python3-lua.html
Python has an industry-standard security-auditing system that is an integral part of the core API, much like Java's security-managers https://peps.python.org/pep-0578/
Considering the data for Project M is almost 30 mega-bytes, I can's see Python's size, which is a small fraction of that, being a real issue (Debian's Obviously when discussing disk-space, memory and network band-width in 2024, anything below giga-bytes is irrelevant, let alone individual mega-bytes. If Project M was first-and-foremost created for embedded devices, then maybe I'd agree but not only that's not the case as far as I'm aware of but even then I'd still suggest something like Micro Python (200k of code and 10k of memory foot-print) over Lua. Hopefully I have made it clear that using Lua over Python would be a significant detriment to this project, with no tangible benefit. |
Beta Was this translation helpful? Give feedback.
-
With scripting support, it would be interesting to allow visualizations to setup ahead of time, such as with a (Relatively) longer operations shouldn't be encouraged during visualization execution as even a less-of-a-second delay is noticeable when watching high-frame-rate play-back. However, no one would mind a 2 or 3 second delay as visualizations are first loaded as a whole, between opening and the start of rendering the first visualization. This would open a large possibility-space for (relatively) processing-intensive visualizations, while ensuring smooth play-back isn't affected. To avoid stalling and inadvertent abuse of this feature, I would place a hard limit of 1 second per visualization load runtime and if it exceeds that, the visualization is silently discarded so as not to impact user-experience, until the next time Projuct M is run. This ensures that artists will want to stay well-below that hard-limit and the load time of an entire visualization library wouldn't be too high over-all. Of course, a simple user-setting could also be provided for users who want a snappier start-up time or who have weaker processing units. If this feature is anticipated to be very popular, it could be better to play it safe and only allow a half or a tenth of a second as a load hard-limit. Otherwise we could end-up with a worst-case scenario where it takes a minute to open 100 visualizations before the first starts rendering. Still, I would suggest a 1-second limit initially with visualizations being load in parallel (and not sequentially) to reduce overall loading time. |
Beta Was this translation helpful? Give feedback.
-
Milkdrop (and AVS) used their very own, simple scripting language to enable preset authors to control many parts of the visuals. While this works quite well, the expression language doesn't support a lot of features like functions and user-defined data structures. There's also no way of controlling the whole rendering process within these expressions - they're solely responsible to control some variables for the predefined effects.
The new visualizer should ideally provide a more flexible way for authors to control the rendering process. While there will be some contraints, the preset should be able to control the following aspects:
There should be different entry points into the scripts, both one-off calls (e.g. when loading the preset) and also events the preset can react on. The main function would be the per-frame render/update function which does the majority of the work to setup the renderer for a single frame.
Language
There are many scripting languages available which can be embedded. The most popular ones are:
Lua
A lightweight, relatively simple and widely adopted scripting language used in possibly thousands of software projects, many of those being games.
Lua has a very basic type systems, e.g. it has no strongly-typed variables. Lua also doesn't support complex data structures, only simple variables containing a single value or tables, which are basically hash tables with key/value pairs.
Functions can be freely defined and used within a Lua scope, and the application can also provide functions which are routed back into the C/C++/Rust/etc. code of the underlying application to let the user control things and request data for example.
Lua has an optional standard library of functions which can easily be disabled for safety purposes, e.g. the
os
library which would allow users to execute arbitrary code.Python
A widely used language, which can be used as a scripting interpreter within other applications or as a standalone language to write any kind of application in. It ships with a (bytecode) compiler to improve loading times and perform some optimizations.
Python is is more like a full programming language, which also supports modules, some object-oriented features and more. This also means that a Python interpreter is relatively large in comparison to Lua, and also needs a number of basic modules to be loaded and available to properly work.
Since Python is relatively big and rich in features, it's relatively hard to disable certain parts to make it safe to use with untrusted code. There might be some sandboxing feature available though.
Conclusion
IMO, Lua would be the best option here as it provides enough flexibility, is safe, fast and really small (<200 KB) and embeds very easily. There's also a huge userbase knowing how to write code in that language as well, as most games with modding support use Lua for that purpose. LuaJit could also be used to further improve runtime performance if needed.
While Python will surely offer more features, it'll increase the library size by several megabytes, isn't easy to secure and prevent malicious code from being executed.
Other scripting hosts are also available, e.g. NodeJS (which has basically the same issues as Python).
If anyone else has suggestions for a language more similar to Lua, please post them!
Beta Was this translation helpful? Give feedback.
All reactions