I heard about that Nim strings will become value types.
With latest Nim devel even nimble breaks, so it was clear that current gintro
would not survive :-)
nimblepkg/packageinfo.nim(110, 25) Error: type mismatch: got <JsonNode,
string, nil>
but expected one of:
proc optionalField(obj: JsonNode; name: string; default = ""): string
first type mismatch at position: 3
required type: string
but expression 'nil' is of type: nil
Run
Indeed I had expected that there is no automatic conversion from empty Nim
strings to NULL passed to C libs:
proc clib(s: cstring) =
echo s.isNil
echo s.len
echo cast[int8](s[0])
echo cast[int](s)
proc main =
clib("")
main()
Run
At least GTK generally likes to get NULL pointers, and not cstrings with first
char being value 0x0.
So I think I may apply a proc converting Nim "" to nil when C lib is called.
For the rare case when user really wants to pass an empty cstring to C lib he
may pass "x0" Nim string, maybe after calling setLen(1).