SA-MP Forums Archive
Macro that converts a function name? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Macro that converts a function name? (/showthread.php?tid=663600)



Macro that converts a function name? - PeanutButter - 06.02.2019

Hello, I have a question about macro's.
Is it possible to make a macro that converts a function name to a new name? for example:

Код:
CONVERT_FUNC_NAME(MyFunction)
Which should be rewritten as:

Код:
new_MyFunction
This is what I tried, but that doesn't really work
Quote:

#define CONVERT_FUNC_NAME(%0) new_%0




Re: Macro that converts a function name? - userid - 06.02.2019

I think is not possible, you only could do that with strings


Re: Macro that converts a function name? - Banditul18 - 06.02.2019

Well you can hook existing samp functions with y_hook or ASL hook method


Re: Macro that converts a function name? - TheToretto - 06.02.2019

Yes that's the hooking.

Код:
#if defined _ALS_SomeFunction
  #undef SomeFunction
#else
    #define _ALS_SomeFunction
#endif

#define RenamedFunction SomeFunction



Re: Macro that converts a function name? - Dayrion - 06.02.2019

Quote:
Originally Posted by TheToretto
Посмотреть сообщение
Yes that's the hooking.

Код:
#if defined _ALS_SomeFunction
  #undef SomeFunction
#else
    #define _ALS_SomeFunction
#endif

#define RenamedFunction SomeFunction
That's ALS hooking method. More informations here: https://sampforum.blast.hk/showthread.php?tid=574534
For callbacks, I suggest you to use y_hooks instead of ALS method. It's way more simple.


Re: Macro that converts a function name? - TheToretto - 06.02.2019

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
That's ALS hooking method. More informations here: https://sampforum.blast.hk/showthread.php?tid=574534
For callbacks, I suggest you to use y_hooks instead of ALS method. It's way more simple.
Yes and I am already using y_hooks for callbacks, but I've shown him a function, that's what he requested.


Re: Macro that converts a function name? - PeanutButter - 06.02.2019

Quote:
Originally Posted by ******
Посмотреть сообщение
How doesn't it work? That's exactly how it should be done.

Here's a useless example, but what am I doing wrong?
PHP код:

#define CONVERT_FUNC_NAME(%0) new_%0
new_Myfunction()
{
    print(
"test");
}
public 
OnGameModeInit()
{
    
CONVERT_FUNC_NAME(MyFunction)(); // error 017
    
return 1;

I get the following errors

Код:
error 017: undefined symbol "new_MyFunction"
warning 203: symbol is never used: "new_Myfunction"



Re: Macro that converts a function name? - Pottus - 06.02.2019

Quote:
Originally Posted by TheToretto
Посмотреть сообщение
Yes that's the hooking.

Код:
#if defined _ALS_SomeFunction
  #undef SomeFunction
#else
    #define _ALS_SomeFunction
#endif

#define RenamedFunction SomeFunction

NO!




That's the hooking!


Re: Macro that converts a function name? - Dignity - 06.02.2019

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

NO!




That's the hooking!
I missed your tongue in cheek replies


Re: Macro that converts a function name? - Pottus - 06.02.2019

Quote:
Originally Posted by Dignity
Посмотреть сообщение
I missed your tongue in cheek replies
You can bet she wouldn't miss her tongue in a set of cheeks!


Re: Macro that converts a function name? - TheToretto - 06.02.2019

lmao you're right sry


Re: Macro that converts a function name? - FinStar - 06.02.2019

Quote:
Originally Posted by TheToretto
Посмотреть сообщение
lmao you're right sry



Re: Macro that converts a function name? - Pottus - 06.02.2019

How could anyone not know what hooking is? Ludacris!


Re: Macro that converts a function name? - TheToretto - 06.02.2019

sorry who?