|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
Running Nim programs as scripts with shebangHere I want to show you the nimbang project. Installation: $ nimble install nimbang Then, you can write and execute Nim programs similarly to Python. Example: #!/usr/bin/env nimbang echo "hello nim" Make it executable and launch it: $ chmod u+x prg.nim $ ./prg.nim # nim c --colors:on --nimcache:/home/jabba/.cache/nimbang/nimcache-0E9E0F169BBD965E # --out:"/home/jabba/.cache/nimbang/nimcache-0E9E0F169BBD965E/.prg" "/tmp/send/prg.nim" hello nim $ ./prg.nim hello nim When you launch it for the first time, it's compiled, the EXE is cached in your HOME directory, and the EXE is executed. When you launch it for the second time, the cached EXE is found and just executed. It's also intelligent. If you modify the source code, then the program will be re-compiled. And the good news is that it's much faster than " $ time ./prg.nim # nim c --colors:on --nimcache:/home/jabba/.cache/nimbang/nimcache-0E9E0F169BBD965E # --out:"/home/jabba/.cache/nimbang/nimcache-0E9E0F169BBD965E/.prg" "/tmp/send/prg.nim" hello nim (252 msec) $ time ./prg.nim hello nim (4.59 msec) By default, it makes a debug build. If you want to have a release build, add a special line under the shebang: #!/usr/bin/env nimbang #nimbang-args c -d:release echo "hello nim" For more info, see the README of the project: https://github.com/jabbalaci/nimbang Template fileI suggest using the following template: #!/usr/bin/env nimbang #off:nimbang-args c -d:release echo "hello nim" Notice that the second line has " Disclaimer
|
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |