Make my application extendable by "mods"?
Make my application extendable by "mods"?
Examples of what I mean by modding:
- minecraft mods: add some jar file into your mod folder
- skyrim mods: add some .esp file into your mod folder
- luanti: put some folder with .lua files and config into your .minetest/mods folder
Mods are basically "turing-complete" and can add different types of computation to your application, while integrating with the (GUI) system.
How to design a program that allow for modding?
With interpreted programming languages like python or lua, you can load code as strings at runtime โฆ but is it done that way for these languages (that would be really bad for security)?
python
eval("print('mod loading ...')")
So roughly how I imagine modding in python to work, a demo in the python repl โฆ
python
>>> items = {} >>> newmod = """ ... {"name": "holy-mod-sword", "value": 10, "do-damage": lambda x: x.firedamage(1000)} ... """ # loading the mod >>> items["holy-mod-sword"] = eval(newmod) >>> items {'holy-mod-sword': {'name': 'holy-mod-sword', 'value': 10, 'do-damage': <function <lambda> at 0x7f8c710a9d00>}}
is it done that way or similar?
Usually, when games and programs natively support 3rd party mods/plugins its done so through a defined API - a modding API - just a bunch of functions made by the devs that allow you to register new stuff, change/override what already exists, react to events, ... Example https://lua-api.factorio.com/latest/
Lua is often used as the language for the mods because it's really easy to embed into a program (most games are done in compiled languages) and so creates a "sandbox" - you can only really call what the devs make available for the lua scripts.