Is there any way to implement dynamically-loadable code modules in Swift? Ideally, I'd be able to implement a protocol or subclass, and have that implementation loaded dynamically by the running host program.
Even more ideally, I'd be able to do that on both macOS and Linux.
I actually double this question as I'm working on a game, and would love to use some form of scripts for skills/items logic, so that I could update them on the fly without rebooting the server
If Swift code is compiled to a loadable format, dlopen will work with that format and Foundation's NSClassFromString(_:) will let you access top-level classes inside it. The easiest way for that to match up with what's in your host program is for both the main app and the plugin to compile against a common framework that contains the base class or protocol; then you can cast the result of NSClassFromString to that type.