Raised This Month: $ Target: $400
 0% 

[not important] dyn natives: how to get native name from itself? no hardcoding


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Owyn
Veteran Member
Join Date: Nov 2007
Old 01-02-2012 , 07:26   [not important] dyn natives: how to get native name from itself? no hardcoding
Reply With Quote #1

Hello,

Can I get native name from itself? not making a different function for each

I have:
PHP Code:
register_native("myfunc","func");
register_native("myfunc2","func");
register_native("myfunc3","func"); 
PHP Code:
public func(iPluginiParams)
{
    new 
MyNativeName[64] = ?

    
log_to_file("MyLog.log""Native with name %s was used"MyNativeName);
    return 
0;

So it would write that it was either myfunc or myfunc2 or myfunc3, is it possible?
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.

Last edited by Owyn; 01-02-2012 at 10:07.
Owyn is offline
Send a message via ICQ to Owyn
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-02-2012 , 13:31   Re: dyn natives: how to get native name from itself? no hardcoding
Reply With Quote #2

Any reason you want to do that ???
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 01-02-2012 , 13:43   Re: dyn natives: how to get native name from itself? no hardcoding
Reply With Quote #3

Yes, - logging ^_^
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.
Owyn is offline
Send a message via ICQ to Owyn
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-02-2012 , 13:46   Re: dyn natives: how to get native name from itself? no hardcoding
Reply With Quote #4

Why using the same callback for different natives ? I don't see situation where you could do that.
__________________

Last edited by Arkshine; 01-02-2012 at 13:48.
Arkshine is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 01-02-2012 , 13:55   Re: dyn natives: how to get native name from itself? no hardcoding
Reply With Quote #5

Because they are all for the same purpose - being a dummy native and alerting when it is used. I need their names just for deeper level of logging, you may be right and I don't really need it, but it would be desirable.

As I see now the only way is storing last called native name in amx mod x and retrieving it in my callback, am I right? Or just making tons of simular callbacks with hardcoded names inside, yes.
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.

Last edited by Owyn; 01-02-2012 at 13:59.
Owyn is offline
Send a message via ICQ to Owyn
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 01-02-2012 , 15:27   Re: dyn natives: how to get native name from itself? no hardcoding
Reply With Quote #6

Quote:
Originally Posted by Owyn View Post
Because they are all for the same purpose - being a dummy native and alerting when it is used. I need their names just for deeper level of logging, you may be right and I don't really need it, but it would be desirable.

As I see now the only way is storing last called native name in amx mod x and retrieving it in my callback, am I right? Or just making tons of simular callbacks with hardcoded names inside, yes.
Or you could just have the native pass a string parameter with the native name.

For example, you register the native, and then when calling the native you do something like this:
PHP Code:
public test()
{
     
func1"func1" );

and in the native callback:

PHP Code:
public funciPluginiParams )
{
     new 
szName64 ];
     
get_string1szNamecharsmaxszName ) );

     
client_print0print_chat"Native %s was used."szName );

__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Owyn
Veteran Member
Join Date: Nov 2007
Old 01-02-2012 , 15:34   Re: dyn natives: how to get native name from itself? no hardcoding
Reply With Quote #7

Quote:
and then when calling the native
It's not me calling my natives and I can't modify the way they are called.
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.

Last edited by Owyn; 01-02-2012 at 15:36.
Owyn is offline
Send a message via ICQ to Owyn
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-02-2012 , 15:55   Re: dyn natives: how to get native name from itself? no hardcoding
Reply With Quote #8

Quote:
Originally Posted by Owyn View Post
It's not me calling my natives and I can't modify the way they are called.
Then who is? And why would they have any motive to use them if they don't actually do anything?
__________________

Last edited by fysiks; 01-02-2012 at 15:56.
fysiks is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-02-2012 , 15:57   Re: dyn natives: how to get native name from itself? no hardcoding
Reply With Quote #9

I don't know if there is any way to retrieve name without modifying amxx, but if you really need tons of them then you can use #define like this:
PHP Code:
register_native("myfunc1","_myfunc1");
register_native("myfunc2","_myfunc2");
register_native("myfunc3","_myfunc3");  
//...

#define native_handler_log(%1,%2) public %2(pid, param){\
log_to_file("MyLog.log""Native with name %s was used", %1);\
return 
func(pid,param);\
}

native_handler_log("myfunc1",_myfunc1)
native_handler_log("myfunc2",_myfunc2)
native_handler_log("myfunc3",_myfunc3)

public 
func(pidparam){
    
//...
    
return 0;

__________________
Impossible is Nothing
Sylwester is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 01-02-2012 , 16:05   Re: dyn natives: how to get native name from itself? no hardcoding
Reply With Quote #10

Quote:
Then who is? And why would they have any motive to use them if they don't actually do anything?
Other people ^_^ And they don't, it's my motive.
Why don't we talk about theoretical part of the problem? ^_^ Did you like my idea about get_last_used_native() function or would you like to suggest anything instead?

Quote:
Originally Posted by Sylwester
#define
defines are unwrapped (unrolled?) during compilation so it's the same thing I use auto-replace in my text editor and make a big .sma file with many many lines, the thing is to get called natives nameы not making a separate callback for each and every of it.
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.

Last edited by Owyn; 01-02-2012 at 16:13.
Owyn is offline
Send a message via ICQ to Owyn
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 15:59.


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