I have a piece of C code which uses macros in order to rename functions:
#define fmiPaste(a,b) a ## b
#define fmiPasteB(a,b) fmiPaste(a,b)
#define fmiFullName(name) fmiPasteB(MODEL_IDENTIFIER, name)
#define fmiGetModelTypesPlatform fmiFullName(_fmiGetModelTypesPlatform)
How can I do something similar in Nim?
Regards
Templates and identifier construction:
https://nim-lang.org/docs/manual.html#templates-identifier-construction.
Example 1: https://github.com/numforge/laser/blob/c7ddceb0/laser/primitives/reductions.nim#L17-L43 Example 2: https://github.com/mratsim/weave/blob/master/e04_channel_based_work_stealing/profile.nim#L27-L30 and usage: https://github.com/mratsim/weave/blob/master/e04_channel_based_work_stealing/profile.nim#L96-L108
Thinking a bit further, for me it only matters the name exported to C. I was thinking if it would be possible to use instead the exportc pragma (https://nim-lang.org/docs/manual.html#foreign-function-interface-exportc-pragma ).
In particular, how could I replace prefix with the content of a variable?
proc p(s: string) {.exportc: "prefix$1".} =
echo s