5 ms·
Would someone explain the function of scripting languages. Why use a scripting language spun off from another language than use the original host language. What
by indigo0086 2y ago
Would someone explain the function of scripting languages. Why use a scripting language spun off from another language than use the original host language. What does lua offer as a scripting language when offering it as a scripting language?
- bobajeff 2y agoIdeally all languages would be quick to program in but the reality is that some languages have really long compile times and are unsuitable for quick prototyping, experimenting, creating proof of concepts, or small programs. That's where scripting languages come in handy.
- imtringued 2y agoNothing prevents anyone from building an ABI compatible interpreter where only parts of the program are compiled.
- deleted 2y ago[deleted]
- idle_zealot 2y agoI think the bigger problem is a language design one. Scripting languages are often easier to use than more performant ones because they make a lot of choices for the developer (automatic allocation and garbage collection, doesn't expose reference versus value, no pointers, everything is a table/object/whatever). A runtime can try to make inferences about how language features are being used in order to speed up execution or reduce memory use, but usually even then things end up being less efficient than if the programmer had to actually make choices about memory allocation, if/when to free things, etc.
- bobajeff 2y agoNothing save for time, skill and enough financial support. Sure. While we're at it why not make a Web Browser too? Technically, nothing stops us.
- hasanhaja 2y agoThey offer a higher level abstraction that might make interacting with the underlying APIs a little more egonomic. For example, Python being used a scripting language for AI and other data science things. The performant APIs that the Python wrappers call are powerful but it might be a little cumbersome to use. A library I used a lot in university was the OpenCV through the native C++ APIs, the Java API and the Python API; the Python version felt a lot easier to work with.
- fwip 2y agoOther people have given good examples about scripting languages in general. But one thing that Lua in particular excels at, is being embedded in other programs. For example, it's a common language for video games to use, both for internal scripting and external modding. For internal use, you give the game designers a higher-level and easier-to-use language with quick feedback (no recompiling your game just to change some logic). For modders, it lets you sandbox their contributions to a specific API, but let them implement arbitrary logic inside of it. This lets users install mods from untrusted sources with confidence that it's not going to crash their computer, delete their data or install a keylogger.
- akkartik 2y agoThey enforce invariants automatically for you that you might have to manually deal with in the host language. Examples: * You'd have to remember to free heap allocations in C. Lua does it for you. * You might want to always access a particular object's field through a function rather than directly. If you programmed in C it's your responsibility to not mess this up, you won't get any warnings or errors if you forget. A scripting language could automatically call the function when you try to access the field. * You might want to ensure that any switch case over a enum always considers all possible values of the enum. C wouldn't help you here, but Fennel's infrastructure for pattern matching would.