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

#define string in string


Post New Thread Reply   
 
Thread Tools Display Modes
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 01-30-2010 , 17:13   Re: #define string in string
Reply With Quote #21

Quote:
error 079: inconsistent return types (array & non-array)
__________________
Greyscale is offline
API
Veteran Member
Join Date: May 2006
Old 01-30-2010 , 18:42   Re: #define string in string
Reply With Quote #22

You are not supposed to return a string to a function. Quite simply put, a String is an array of characters, so the reason it is working is probably the following psuedo-code:
Code:
ALLOC "hey" to STRING_POINTER
String:get_string=SomeFunction();
get_string SET TO STRING_POINTER
This might explain why there are "wierd" letters returned as well. Plus, you can not guarentee the life of the string, so eventually the data will be garbage.
__________________
API is offline
Send a message via AIM to API
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 01-30-2010 , 19:06   Re: #define string in string
Reply With Quote #23

http://forums.alliedmods.net/showthr...736#post831736

I'm assuming sourcemod doesn't allow it in this situation, but do you have any idea how we can put string define values in string define values? Look at the OP
__________________
Greyscale is offline
API
Veteran Member
Join Date: May 2006
Old 02-01-2010 , 12:04   Re: #define string in string
Reply With Quote #24

#define A "hey"
#define B "you"
#define AB A ... B

Quote:
The macro substition processor now recognizes the "#" character for "stringizing" a parameter. For example, if you have the definition
#define log(%1) #%1
Then the expression log(test) will result in "test".
Note that concatenation of literal strings requires an ellipsis in Pawn (which is different than C/C++). So to combine the parameter with literal strings, use a syntax like:
#define log(%1) "logging: " ... #%1 ... "\n"
__________________
API is offline
Send a message via AIM to API
DieTeetasse
Senior Member
Join Date: Jul 2009
Old 02-01-2010 , 15:08   Re: #define string in string
Reply With Quote #25

... is not working :/

PHP Code:
#define A "hey"
#define B "you"
#define AB A ... B

public OnPluginStart()
{
    
PrintToChatAll("%s"AB);

Quote:
//// abc.sp
// abc.sp(7) : error 001: expected token: ",", but found "..."
// abc.sp(7) : error 029: invalid expression, assumed zero
// abc.sp(7) : warning 215: expression has no effect
// abc.sp(7) : error 001: expected token: ";", but found ")"
// abc.sp(7) : fatal error 127: too many error messages on one line
This will work, but it doesn't solve the original problem:
PHP Code:
#define A "hey"
#define B "you"
#define AB A,B

public OnPluginStart()
{
    
PrintToChatAll("%s %s"ABAB);

__________________

Last edited by DieTeetasse; 02-01-2010 at 15:13.
DieTeetasse is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 02-01-2010 , 18:00   Re: #define string in string
Reply With Quote #26

Quote:
Originally Posted by Greyscale View Post
Code:
#define PROJECT_AUTHOR      "Greyscale"
#define PROJECT_COPYRIGHT "Copyright (C) 2010  PROJECT_AUTHOR"
I simply suggest that you separate author and copyright into two strings, and format the final string when using these defines.

Separate data in defines and join them on runtime based on what info you need.
__________________
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
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 02-01-2010 , 19:23   Re: #define string in string
Reply With Quote #27

Actually I think this will do it:

Quote:
The macro substition processor now recognizes the "#" character for "stringizing" a parameter. For example, if you have the definition
#define log(%1) #%1
Thanks pimp!
__________________
Greyscale is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 02-02-2010 , 01:03   Re: #define string in string
Reply With Quote #28

Quote:
Originally Posted by Frus View Post
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.
For that to work, you will need to omit the quotes around Greyscale.

so:
Code:
#define PROJECT_AUTHOR      Greyscale
#define PROJECT_COPYRIGHT_FORMAT(%1) "Copyright (C) 2010  %1"
#define PROJECT_COPYRIGHT  PROJECT_COPYRIGHT_FORMAT(PROJECT_AUTHOR)
naris is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 02-02-2010 , 01:20   Re: #define string in string
Reply With Quote #29

Quote:
Originally Posted by DieTeetasse View Post
... is not working :/
Apparently, the SourceMod pawn compiler must not of merged that bit of code form the original CompuPhase Pawn project
That doesn't bode well for the stringizing operator either
naris is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 02-03-2010 , 18:52   Re: #define string in string
Reply With Quote #30

Aha, I'll test this out.
__________________
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 04:36.


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