Raised This Month: $51 Target: $400
 12% 

#define string in string


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 01-28-2010 , 20:36   #define string in string
Reply With Quote #1

Code:
#define PROJECT_AUTHOR      "Greyscale"
#define PROJECT_COPYRIGHT "Copyright (C) 2010  PROJECT_AUTHOR"

Possible? I know in c++ you would use + to concatenate, but not in pawn.

And the above doesn't work. It prints PROJECT_AUTHOR (literally), as I expected.
__________________
Greyscale is offline
Kevin_b_er
SourceMod Donor
Join Date: Feb 2009
Old 01-28-2010 , 23:11   Re: #define string in string
Reply With Quote #2

In C,
#define "String1""String2"
works.

Don't know if it will in sourcepawn.

However, for everyone who's reading this, the method strictly would only work when creating a literal. It will not concatenate at runtime.
Kevin_b_er is offline
Frus
Senior Member
Join Date: Aug 2009
Old 01-28-2010 , 23:44   Re: #define string in string
Reply With Quote #3

Code:
#define PROJECT_AUTHOR      "Greyscale"
#define PROJECT_COPYRIGHT_FORMAT(%1) "Copyright (C) 2010  %1"
#define PROJECT_COPYRIGHT PROJECT_COPYRIGHT_FORMAT(PROJECT_AUTHOR)
I think that would work.

Otherwise you may be forced to stick a strcat() or Format() in your code to format the author string into the copyright string.

Last edited by Frus; 01-28-2010 at 23:49.
Frus is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 01-29-2010 , 00:42   Re: #define string in string
Reply With Quote #4

Frus: I tried that, didn't work :/

I have no idea why, hopefully I did something wrong. I'll try again.

Kevin: Doesn't work in SourcePawn.


EDIT: Didn't work, Frus.
__________________

Last edited by Greyscale; 01-29-2010 at 00:45.
Greyscale is offline
Frus
Senior Member
Join Date: Aug 2009
Old 01-29-2010 , 01:09   Re: #define string in string
Reply With Quote #5

Since I assume by you saying it twice you tried both methods, I don't see why

Code:
#define PROJECT_AUTHOR      "Greyscale"
#define PROJECT_COPYRIGHT "Copyright (C) 2010"
decl String:copyrightNotice[128];
Format("%s  %s", copyrightNotice, sizeof(copyrightNotice), PROJECT_COPYRIGHT, PROJECT_AUTHOR);
wouldn't work.

main is down so I'm going off the syntax by memory, forgive me if the params are in the wrong order.
Frus is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 01-29-2010 , 02:06   Re: #define string in string
Reply With Quote #6

Well, yes I'm sure that method works. If that's the only way that really blows.

I was hoping the compiler would be able to compile it into the code as opposed to making a global string constant to do it.
__________________
Greyscale is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 01-29-2010 , 08:58   Re: #define string in string
Reply With Quote #7

In C++ you can only use + to concatentate String objects because there is an operator overload for it. You can't do "foo" + "bar".

Our version of the Pawn compiler does not have either a "stringize" operator or a literal string concatenate operator (# and ##, respectively, in the C preprocessor).
Fyren is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 01-29-2010 , 16:41   Re: #define string in string
Reply With Quote #8

Can't we overload the + operator for strings ourself then?

Like it's done with floats.
Code:
stock Float:operator+(Float:oper1, oper2)
{
    return FloatAdd(oper1, float(oper2));			/* "+" is commutative */
}
Maybe it isn't that easy to do with arrays.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-29-2010 , 17:37   Re: #define string in string
Reply With Quote #9

Quote:
Originally Posted by Greyscale View Post
Code:
#define PROJECT_AUTHOR      "Greyscale"
#define PROJECT_COPYRIGHT "Copyright (C) 2010  PROJECT_AUTHOR"
Possible? I know in c++ you would use + to concatenate, but not in pawn.

And the above doesn't work. It prints PROJECT_AUTHOR (literally), as I expected.
I already filed a bug report 1 year ago, when the old bug system was still on, nothing happened since then.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 01-29-2010 , 18:11   Re: #define string in string
Reply With Quote #10

Quote:
Originally Posted by rhelgeby View Post
Can't we overload the + operator for strings ourself then?

Like it's done with floats.
Code:
stock Float:operator+(Float:oper1, oper2)
{
    return FloatAdd(oper1, float(oper2));			/* "+" is commutative */
}
Maybe it isn't that easy to do with arrays.
I had no idea overloading was possible in Pawn.

But the problem is it takes the return value. Pawn can't return strings.

berni: Did you end up using Format() to work around this?
__________________
Greyscale is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:12.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode