I am using the ".. code-block:: nim" in my doc comments. When I run "nim doc
file.nim" the html generated does not have the nim code formatted as I expect,
it is just plain text. How do I get formatted code?
Thank you for the responses and code, I'm learning a lot about the macro
system. Nice idea to use a pragma.
Testing the macro I was getting the compiler error:
t.nim(11, 20) Error: invalid indentation
I used treeRepr in the macro to debug the problem. It turned out I was
Using include is an interesting idea, it adds another dimension to consider.
Including allows you to group all module tests together which I want, however
it requires you run in the main module. I want to run in an external module to
more closely match how a user would use the code.
I didn't
I'm trying to write a generic function, here is a simplified version. It
generates the errors shown below. What am I doing wrong?
import strutils
proc test16(): uint16 =
var buffer: array[sizeof(uint16), uint8]
for ix in 0..sizeof(uint16)-1:
buffer[ix] =
Thank you. I did need to indent my code block.
I get a compiler error for the following code. Anyone know what I am doing
wrong?
from tables import OrderedTable, toOrderedTable
proc getMetaInfo(filename: string, fileSize: int64): OrderedTable =
result = {
"filename": filename,
"size": fileSize,
How do I swap the first two bytes of the openArray in the following code?
# t.nim(5, 35) Error: expression has no address
import strutils
import endians
proc num(buffer: openArray[uint8]): uint16 =
swapEndian16(addr(result), addr(buffer))
var buffer =
I upgraded from nim version 0.17 to 0.18 and I'm in the process of updating my
code to remove the deprecated warnings.
What is the replacement for parseopt2?
The following program generates an error. Shouldn't it work?
proc readMe[T](name: string): T =
result = 123'u16
var num = "test".readMe[uint16]()
# var num = readMe[uint16]("test")
echo num
Here are the error messages:
t.nim(5, 17)
The following program generates the errors:
t.nim(15, 17) template/generic instantiation from here
t.nim(5, 28) Error: expression has no address
Why does the expression buffer[0] have no address?
import endians
import strutils
proc
Thank you, that helps. I'm now looking at the json module.
How do you set up a directory structure for a multi-file project with test
files and doc files? How do you name the files and how do you run tests?
I'm trying to follow this page without much luck:
Thanks for all the helpful advice.
I am trying out this structure:
bin
docs
tests
nim.cfg which contains one line: --path:"../project/"
test_project.nim
test_file1.nim
project.nimble
project
project.nim
file.nim
private
Thanks. My problem was using the wrong escape code.
Here are some examples of showing [Suite] in bold blue.
Python: python -c "print '033[1;34m[Suite]033[0m'"
Nim: echo "e[1;34m[Suite]e[00mn"
Bash: printf "e[1;34m[Suite]e[00mn"
Thank you very much.
Is there an easy way to output color text to the terminal in the nimble file?
I tried using standard terminal codes but that didn't work.
I then found and used the Terminal module. That works in a nim file, see the
example below, however you cannot import Terminal in a nimble file (or
Why am I getting a compiler error?
Here is the program:
$ cat test.nim import parseopt2
var p = initOptParser(@["\--left", "\--debug:3", "-l=4", "-r:2"])
for kind, key, val in p.getopt():
echo kind
And here is the error:
$ nim c -r test.nim ... test.nim(4, 24) Error: type mismatch: got
So this is expected nimvm behavior? I thought it would operate like static.
This works as I expect:
static:
echo "compiling"
echo "running"
Run
How do you gracefully stop the compiler? You can specify garbage to stop it,
but is there a better way?
static:
echo "compiling..."
proc display[T](message: T) =
when not (T is string):
compile error: "T is not a string"
echo message
The answer to my question in another thread lead to the answer to this one.
Replace the "compile error" line with:
static:
doAssert(false, "T is not a string")
Run
The the doAssert will run at compile time.
I am trying to debug a python module I wrote in nim using lldb on a Macintosh.
Anyone know how to debug a python module?
The shared library module is compiled like:
nim c -d:buidingLib --debugger:native --verbosity:0 --hints:off
--threads:on \
--tlsEmulation:off --app:lib
The "compiling..." string does not appear when compiling this program:
when nimvm:
echo "compiling..."
else:
echo "running..."
Run
How do you customize the html css output created by the nim rst2html command?
I was able to edit the compiler's config file
(~/.choosenim/toolchains/nim-0.19.0/config/nimdoc.cfg) to customize the css and
I saw the changes in the css output.
However, now I'm trying to do it with my own config
I've used perfect hashing with rust.
[https://github.com/sfackler/rust-phf](https://github.com/sfackler/rust-phf) I
think it is a great idea and it might be implemented in nim with a macro. If
you know the entries at compile time, why not make the map as fast and small as
possible. In the
There's not an exportcpp pragma in nim that I know about. But have you tried
wrapping the nim c code with, extern "C"? Cpp code can compile wrapped c code.
My nim program crashes in release but not in debug mode. Some system code is
overwriting my json structures causing the crash. The problem is hard to narrow
down, it moves around as I add debugging code. I haven't been able to simplify
the error case to something that is easy to share.
The
How do you use the memTracker compiler option to track memory usage?
What I tried was:
* added --memTracker:on to the compile line
* added line to my main module to import nimtracker
When I run my program, the memtracker.db file gets created and sqlite3 can view
it. However the tracker
The nimformat project on github uses nim with nimpy to build a python module
that can be packaged and installed with python's package manager (pip). The
package includes the c source files and pip compiles them to build the python
module on the target machine.
I've been looking for another approach. From what I've read, the python wheel
package can do what I want, but it is still a mystery to me how.
Has anyone done this and know of a project I can learn from? I haven't been
able to find an example in the python or nim public package lists.
I’ve been thinking about this problem for a while too.
I copied Jonesmartinze three options here and numbered them for easier
reference.
1\. create a source distribution of .py and .c files. The end user builds this
so it matches their system architecture/OS.
2\. and/or create platform
I'm trying to get nim code coverage working again in the new nim 1.0 version.
It was working several months ago. Now it's reporting coverage on the c code
instead of the nim lines. The html output shows 100% coverage on the x.nim.c
file when it shouldn't and the standard lib files are not
Here is the code if you want to try it out:
x.nim file:
var x = 0
if x > 1:
echo "foo"
echo "bar"
Run
ct.sh file:
#!/bin/sh
# Remove old coverage information.
rm -rf *.info html ~/.cache/nim
# Compile t.nim
I'm getting warnings about modules imported but not used and I want to fix my
code. The second time I compile the warnings to do show up. How do I get the
warnings to appear again? The second compile is much faster, so I'm thinking I
might have to delete the cache. Is this correct? Where is it?
thank you, that did the trick
Is it possible to pass arguments to nimble tasks? I want to pass the filename
to run one test like this:
nimble test filename
Run
Thank you, that worked. I created a config.nims file in my main folder and
added one line: switch("define", "ssl")
Where do I put the line: switch("define", "ssl")?
I tried a few more things without luck:
* I tried adding a "before build" task:
before build:
switch("define", "ssl")
Run
* I tried adding it by itself in the my project nimble file.
* I tried adding it
How do you change your nim package's tags or description after you've published
it?
My nim package needs the -d:ssl compile switch. How do I add the switch to the
nimble build task used by nimble install? I tried a number of things but none
of them worked for me.
* I tried making a cfg file with the line "-d:ssl" in it.
* I tried adding a switch("d", "ssl") in a nimble
39 matches
Mail list logo