Closed ioquatix closed 9 years ago
Just wondering, is it possible to run a nim script using a hash bang line, e.g.
Yes: http://hookrace.net/blog/what-makes-nim-practical/#use-as-a-scripting-language
Can you accept the script from stdin somehow for running unsaved files?
I made a PR for this just yesterday: https://github.com/Araq/Nim/pull/2202
Is nimscript
bundled by default?
No.
What is the preferred implementation in script-runner?
1/ Bundle nimscript
and use it.
2/ Execute something similar to what nimscript
does.
The option of having nimscript
included in nim
makes life a lot easier since it can run the script outside the script-runner environment.
I guess just running this would work: nim --verbosity:0 -r c $FILE
@def- I guess the big issue with that is people would have to type that into every script.. either that or it gets hard coded into script-runner in which case it might become a compatibility issue in the future if the flags change.
If no file is specified can you default to stdin
? This is how almost every other script interpreter works.
Stdin support has been merged.
@Araq looking to implement this now, can you please confirm how to run this at the top of a script file, e.g.
#!/usr/bin/env nim --verbosity:0 -r c
I can't find a correct shebang line to make it work. I think it's a problem with the argument parsing and/or how the arguments are passed to the invoked compiler.
Okay, well, essentially, what we want is something that can run on the hash bang line, it looks like nimscript
might have cracked that nut, but perhaps it's good if this functionality is available directly from nim - once you let me know I will integrate support into script-runner.
@ioquatix That won't work: on most systems (including Linux), /usr/bin/env
will not pass any command line arguments to the program. In your example, /usr/bin/env
will be looking for an executable named nim --verbosity:0 -r -c
.
The passing works just fine on arch. I get
Error: invalid command: '--verbosity:0 -r c'
When enclosing the arguments via "
, I get
Error: arguments can only be given if the '--run' option is selected
@kirbyfan64 I have never seen the behaviour your proposing. In fact, I can write an entire program after /usr/bin/env with arguments if I like:
From the env
man page:
SYNOPSIS
env [-i] [name=value ...] [utility [argument ...]]
The only limitation is programs with =
in their name as this looks like an environment option.
@ioquatix What version of UNIX are you using? On Linux:
ryan@DevPC-LX:~/langtest$ ./x.rb
/usr/bin/env: ruby -e "puts ARGV.inspect" --: No such file or directory
ryan@DevPC-LX:~/langtest$
I'm on Mac OS X which is BSD derived.
On linux:
% /usr/bin/env ruby -e "puts ARGV.inspect" -- Apples Oranges Bananas
["Apples", "Oranges", "Bananas"]
Is it different when you run it in a file?
Weird, when it's in a file, it doesn't work correctly, on both Mac and Linux.
Interesting, as soon as you have quotes, it fails.
Perhaps bundling nimscript
makes sense given the complexity of using env with arguments.
Just touching base, any progress here?
I would recommend to use https://github.com/flaviut/nimrun
Okay right, so basically this isn't something we really need to add explicit support to script-runner then. Anyone can just add this to their path and use it. Thanks.
Hi,
I've had this issue come in: https://github.com/ioquatix/script-runner/issues/20#issuecomment-75649211
Just wondering, is it possible to run a nim script using a hash bang line, e.g.
Can you accept the script from
stdin
somehow for running unsaved files?Sorry for the bother and thanks for your advice, assistance.