h3rald / min

A small but practical concatenative programming language and shell
https://min-lang.org
MIT License
309 stars 23 forks source link

Loading dynamic libraries created in Nim #8

Closed PMunch closed 6 years ago

PMunch commented 6 years ago

Finally got this working. Min will now look in the dynlib folder and try to load any file in that folder as a library. Each library uses the symbols from the compiled min binary. Therefore it need to know of these symbols when they are defined, which is done by including the dynamic/mindyn.nim file in the library. When the library is compiled with nim c --app:lib --noMain -d:release it will create a small binary (the example file is only 61Kb on my system) which can be put in the dynlib folder. Every library needs a setup proc which returns an object that informs min of the symbol to actually set up the module and which version it is linked against. Note that the version only needs to change when the procedures change signature or location. So it's possible to fix bugs in min and still load the same libraries which will use the new, bugfixed, code. I've added an example in the dynamic folder as well which adds a copy of the + operation called myp. To use it you need to load it by doing 'dyn import.