Closed drriguz closed 1 year ago
As explained in the manual, arguments to meta-macros (like #include
) aren't necessarily evaluated, so in your example, your last line initially expands to #include dir/file
instead of #include chapters/ch01.txt
.
The Examples section of the manual explains how to get around this using #defeval
and some helper macros. See in particular the examples involving the macro APPLY
. Here's how you might adapt it to your particular use case:
#define IDENTITY(x) x
#define BUILDIMPORTSTRING(dir,file) \#include dir/file
#define IMPORT(dir,file) IDENTITY(#defeval RUNIMPORTSTRING BUILDIMPORTSTRING(dir,file)
RUNIMPORTSTRING)
IMPORT(chapters,ch01.txt)
Does this solve your problem?
Yes, it works! Thanks for your help!
It's a little bit hard to get startted, thought it's actually already explained in detail in the manual. A toturial should be helpful for beginners like me :p
OK, glad I could help! I agree that a tutorial would be nice. I don't have the time to produce one now but perhaps someone else might step up and volunteer. :)
Hi, I'd like to define a macro to include files dynamically, here's a minimal example:
File structure:
main.txt
Then I run
gpp main.txt
,#include chapters/ch01.txt
works as expected, However, the last line,IMPORT(chapters, ch01.txt)
won't work, and says thaterror: Requested include file not found
.It's this a bug or it's something that not supported?
Thanks, Riguz