[Question] including multiple files with same name
#1

So I have 2 files (say sql.pwn), each one holds different content and placed at a separate folder.
Only the first one is actually included, the second one is completely ignored.

Is it something which is generally not allowed, or something that is restricted to pawn?

Is there a way around that (aside of renaming one of the files) ?

Thanks.
Reply
#2

As long as one of them is not being added into the server it should not effect in anyway. The situation is critical though, why wouldn't you rename the either one?
Reply
#3

Quote:
Originally Posted by Tayab
Посмотреть сообщение
As long as one of them is not being added into the server it should not effect in anyway. The situation is critical though, why wouldn't you rename the either one?
Well, it would be a little bit inconvenient as I would probably need to add a prefix to it, while not adding a prefix to the first one.
But doing that will probably force me to add prefixes for all files based on their category...

If this is the only way out I'm probably gonna end up doing that, however I would like to hear more suggestions before I start renaming all the files.
Reply
#4

Quote:

When the file can be opened successfully, the #include directive
defines a constant with the name “_inc_” plus the base name of
the file (the filename without path and extension) and the value 1.
If the constant already exists, the #include directive skips opening
and including the file, thus preventing a double inclusion. To force
a double include, remove the constant definition with the #undef
directive before the second inclusion of the file.

pawn-lang.pdf, page 119.
Reply
#5

but you'll need to rename prefix - it only works with .p and .inc files.
pawn Код:
#include "/folder/file"         //it also won't work if you'll add extension to filename
#include "/folder2/file"
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
pawn-lang.pdf, page 119.
Thanks, but unfortunately it doesn't work.

I tried different combinations (with the value 1), the directive undefines it with no issues, but it still won't include the file (to confirm I tried to use #error directive inside the second include file).
Reply
#7

Try:

#include <../file>
#undef _inc_
#include <../file>

// NVM didnt read your comment as I wrote this 5 mins ago.

Well I think the easiest way is renaming. There shouldn't be a problem with this right?
It's definitely possible to include both files somehow, but isn't that more complicated and unnecessary?

Also, make sure that both includes don't use the same define preventing it from being double included (apart from the internal one, like most includes have something like "#define ZCMD_INCLUDED")
Reply
#8

Quote:
Originally Posted by NaS
Посмотреть сообщение
Try:

#include <../file>
#undef _inc_
#include <../file>

// NVM didnt read your comment as I wrote this 5 mins ago.

Well I think the easiest way is renaming. There shouldn't be a problem with this right?
It's definitely possible to include both files somehow, but isn't that more complicated and unnecessary?
Maybe complicated, but it is necessary for me, I like things organized.
Renaming would be my last option, I would rather avoid that if I can.
A file with the same name is very likely to appear more than once since it appears in different folders.
Reply
#9

Okay then, I will try around a bit. There must be a way ..
Reply
#10

Quote:
Originally Posted by NaS
Посмотреть сообщение
Try:

#include <../file>
#undef _inc_
#include <../file>

// NVM didnt read your comment as I wrote this 5 mins ago.

Well I think the easiest way is renaming. There shouldn't be a problem with this right?
It's definitely possible to include both files somehow, but isn't that more complicated and unnecessary?

Also, make sure that both includes don't use the same define preventing it from being double included (apart from the internal one, like most includes have something like "#define ZCMD_INCLUDED")
It's not a library I downloaded, its just a part of the gamemode I'm working on.
And since I wrote those files, I can assure you that those kind of definitions are not there.

Quote:
Originally Posted by NaS
Посмотреть сообщение
Okay then, I will try around a bit. There must be a way ..
Well according to the pawn-lang.pdf, which is provided by CompuPhase, it is possible but for some reason it doesn't work.

EDIT: It might be my fault, although I checked if its even defined before undefining it, and to make sure I even used #error directive to check if its defined.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)