As my weekend's fun project I added an experimental new configuration system to the compiler. Unfortunately I had no time to document it, PRs welcome. So this is how it works:

Instead of foo.nim.cfg you can use foo.nims to provide a configuration file that uses Nim's VM. Within foo.nims the full power of Nim is available and system.nim provides additional tools for you like cd, mvFile and even task. Example:

# don't really execute 'gcc -v'
mode = ScriptMode.Whatif

exec "gcc -v"

--forceBuild

task listDirs, "lists every subdirectory":
  for x in listDirs("."):
    echo "DIR ", x

task default, "default target":
  # 'nim default foo.nim' is an alias for 'nim c foo.nim'
  setCommand "c"

I'm quite proud of how few lines it took to get there, so study this piece of art

The extension to system.nim is here:

https://github.com/nim-lang/Nim/blob/devel/lib/system/nimscript.nim

The support in the compiler is here:

https://github.com/nim-lang/Nim/blob/devel/compiler/scriptconfig.nim

An example here:

https://github.com/nim-lang/Nim/blob/devel/tests/newconfig/tfoo.nims https://github.com/nim-lang/Nim/blob/devel/tests/newconfig/tfoo.nim

NimScript has been inspired by nake, but doesn't compile your build script, instead it runs it via Nim's virtual machine. It's my hope that we can deprecate the old configuration system soon.

Cheers!

PS: I'm not sure what this means for the Nimble - Nim interaction.

2015-08-16 12:19:25
rku
Hmm interesting. Does it mean we can possibly have actual nim scripting? As in compiler evaluating a nim script? Possibly hooking scripted functions to compiled code? Something like that would be greatly appreciated by game developers. 2015-08-16 14:24:04
This is possible since quite some time. The API still needs cleanups but it's usable. https://github.com/nim-lang/Nim/blob/devel/compiler/scriptconfig.nim shows how to use Nim as a scripting language within your Nim application.
2015-08-16 16:10:40
Wow thats so cool @Araq! I vote for more weekends to you! 2015-08-16 16:18:22
On a practical note, I'd suggest a different extension instead of .nims. I'm not particularly picky about which one, but it should be easy to tell apart from .nim and easy to pick out of a directory listings.
2015-08-16 23:24:45
At some point would it be possible for you to go into detail and explain how this works and how people can take advantage of it? 2015-08-17 06:48:30

I tried this:

import os
echo paramStr(1)
But i get the following:
winlean.nim(468, 3) Error: cannot 'importc' variable at compile time

Which is a bad thing, because then it hardly can be used as a windows scripting language. Otherwise, i'd say this is a big achievement. It could kick python as a scripting lang.

Maybe .ns as an alternative ext?

2015-08-17 08:23:38
That's strange, it should fail with an ambiguity error. It's system.paramStr for NimScript.
2015-08-17 08:39:56

On a practical note, I'd suggest a different extension instead of .nims. I'm not particularly picky about which one, but it should be easy to tell apart from .nim and easy to pick out of a directory listings.

Meh, alright, will call it .nimscript then.

2015-08-17 08:49:02

It seems interesting, but I am not sure how to actually run it. I tried to download the example, and in fact when I compile tfoo with nim c tfoo I see that tfoo.nims is being processed - in fact [NimScript] exec: gcc -v is printed, and if I remove the speculative mode, gcc -v is run.

I am not sure, though, how to execute the tasks defined below

2015-08-17 08:52:43
<<<••1234567••>>>