Hi,
First of all this topic is not about how to do this or that specifically, but more of an open reflexion on what Nim offers and allows.
I am by no mean a Nim expert, having only played with it on a little project, but I was amazed by all the awesome features it takes here and there, mainly the hygienic macros and the functional flavor of the language. It occured to me that it's the language I would want to use as a complement to C++ in games programming - and not in place of it. I think it would be ideal because of one very strong feature : the ability to create DSLs inside Nim. This makes it perfect to develop configuration formats (that already exist iirc), and more importantly, scripting DSLs for game and level design. That's what Nim has.
What Nim lacks, or is difficult to obtain at least, is some kind of JIT (the VM is really limited) or very fast feedback loop. By this I mean : the ability to load the scripts at start-up, requiring no compilation of the project (ie. C++ code); and ideally, to edit the Nim code at runtime (and see the effects live). Maybe compiling the scripts as a dll before starting could do the trick, but it can still be fairly long depending on the size and number of scripts, and it would not allow to edit them at runtime. Another solution would be to run the Nim compiler when a script is edited, and JIT the emitted C/LLVM IR code with LLVM (not so well-versed into this, so correct me if need be). Don't know about the feasability of this.
Note that this is useful when developing, a shipped game would compile the Nim code once to squeeze the maximum performance out of it.
What do you think ? Is there a way to replace usual scripting languages (Python, Lua ...) with Nim ?
I've been thinking about the same thing for the same reason (I'm a game developer too). Right now, for the VM to call into compiled code, you have to manually write a stub. I was looking into what would be involved in having the compiler automatically generate the necessary wrappers so that the VM can call any function that was compiled into the binary.
If it could do that, would that satisfy your needs?
Have a look at nimble packages nrpl and tnim.
Maybe this is something you could build upon.
I see Nim as potentially a single language replacement for C/C++ and Python. It's not quite there yet, but once the bugs to be fixed for 1.0 are fixed (closures, concepts, destructors/finalizers, static[T]) I'd consider it 'good enough'. I like the language design a lot.
Game development is an important domain, but not the only one. Nim's competitors include C++, Python, Rust, D, and Julia. Of all of these, I like Nim most of all, but the competition is tough.In particular, I like Julia a lot, as a MATLAB/Octave user.
Nim will be successful, of that I'm sure.
@jyelon Nice to see I'm not the only one to think about that. As for your proposition, I don't know since I followed the nimscript/VM stuff very vaguely. Please enlighten me!
@jlp765 That may basically work, but I'm affraid relying on external compilers is not really a satisfactory solution. I was hoping it could be possible to embed the Nim compiler, have it compile scripts in-memory and then JIT them with Clang/LLVM.
Nim as a replacement for C++, not gonna happen any time soon if you ask me. At least (in games development) not for medium to large scale projects, where C++ is the lingua franca. But that doesn't mean we can't use it, and I hope we will.