Is it possible to use Nimscript as an embedded scripting language instead of for example using Lua? And if possible, can I create bindings for my own functions and restrict which built-in functions can be called from the scripting language?
I want people to be able to safely extend my application using a scripting language and prefer the Nim GC to be reused.
Is it possible to use Nimscript as an embedded scripting language
In theory: Yes, of course. Why shouldn't it?
In practice: Since the compiler and the standard library are rather modular, you can include parts of it in your project. However, there is no API dedicated to what you want to do, so you would need to extend and modify quite a bit of the current code.
I believe that Lua's API for embedding the interpreter would still be superior as it was designed with embedding in mind. Not mentioning the restrictions of Nim's VM (for example, using ref variables is still buggy). Lua's embedding API is also designed for safety as you can tightly control which parts of the standard library will be available. It would be a lot of work to reimplement that for Nim – for example, you would need to split up the system module since it contains a lot of stuff you may not want to make available (like File I/O), while other things are absolutely necessary (basic types and procs, e.g. for strings, arrays and seqs).
Read nimble's source code of how to accomplish this.
Thank you. I had a look at the Nimble code and tried some pretty complex things already. The only thing I could not get to work are macros, but am really happy with what Nimscript can already do.
Some more things I should be aware of? I already know about the FFI limitation.
I added an example of how I embedded Nimscript in my Nim application at:
https://github.com/komerdoor/nim-embedded-nimscript
Still working (between other things) on the automatic binding generator.