I would like to create a binary that is storing some configuration data that will be supplied at compile time and built into the binary that I don't want present in the release versions.
In C I would do this like
#ifdef DEBUG
#define LOOKUP_TABLE "{this:is:test:json}"
#else
#define LOOKUP_TABLE "{this:is:release:json}"
#endif
Below I can get it defined for runtime...but I dont want the debug string in there at all
#debug
when not defined(release):
const LOOKUP_TABLE: string = "{this:is:test:json}"
#release
when defined(release):
const LOOKUP_TABLE: string = "{this:is:release:json}"
CodePudding user response:
const
is a compile time constant, so it will only exist in your program if you directly reference it with runtime code, otherwise Nim will statically evaluate the operations and not include it.
CodePudding user response:
It seems you already know about when
and you are rather looking for a way to not insert the value of the lookup table directly into source code. Maybe you are looking for the staticRead macro?
const LOOKUP_TABLE =
when defined(release):
staticRead("release.json")
else:
staticRead("debug.json")
echo LOOKUP_TABLE