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

Using another way of calling functions instead of callfunc_*


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 12-10-2010 , 08:23   Using another way of calling functions instead of callfunc_*
Reply With Quote #1

Hy all,
I have made a stock through which i am able to execute any public function present in my plugin using the name of the function
This is the stock
Code:
stock execute_function( const function_name[ ] ) {     // We will use "" in the second parameter since we want to execute     // da function in our own plugin !     if ( callfunc_begin( function_name , "" ) )     {         callfunc_end ( )         return 1;     }     else return -1 }
And this is how i use it
Code:
execute_function( "some_function_name" )

Now i want to use some other method to execute a public function present in my plugin, instead of using callfunc_* natives is there any other way through which i wont have to use so many native calls

i also found this from amx modx source:
PHP Code:
// native callfunc_end();
static cell AMX_NATIVE_CALL callfunc_end(AMX *amxcell *params)
{
    
CPluginMngr::CPlugin *curPlugin g_plugins.findPluginFast(amx);
    
    if (!
g_CallFunc_Plugin)
    {
        
// scripter's fault
        
LogError(amxAMX_ERR_NATIVE"callfunc_end called without callfunc_begin");
        return 
0;
    }

    
// call the func
    
cell retVal;
    
int err;

    
// copy the globs so the called func can also use callfunc
    
cell gparams[CALLFUNC_MAXPARAMS];
    
CallFunc_ParamInfo gparamInfo[CALLFUNC_MAXPARAMS];

    
CPluginMngr::CPlugin *plugin g_CallFunc_Plugin;
    
int func g_CallFunc_Func;
    
int curParam g_CallFunc_CurParam;

    
memcpy(gparamsg_CallFunc_Paramssizeof(cell) * curParam);
    
memcpy(gparamInfog_CallFunc_ParamInfosizeof(CallFunc_ParamInfo) * curParam);

    
// cleanup
    
g_CallFunc_Plugin NULL;
    
g_CallFunc_CurParam 0;

    
AMX *pAmx plugin->getAMX();

    
Debugger *pDebugger = (Debugger *)pAmx->userdata[UD_DEBUGGER];

    if (
pDebugger)
    {
        
pDebugger->BeginExec();
    }

    
// first pass over byref things
    
for (int i curParam 1>= 0i--)
    {
        if (
gparamInfo[i].flags CALLFUNC_FLAG_BYREF)
        {
            
cell amx_addr, *phys_addr;
            
amx_Allot(pAmxgparamInfo[i].size, &amx_addr, &phys_addr);
            
memcpy(phys_addrgparamInfo[i].allocgparamInfo[i].size sizeof(cell));
            
gparams[i] = amx_addr;
            
delete [] gparamInfo[i].alloc;
            
gparamInfo[i].alloc NULL;
        }
    }

    
// second pass, link in reused byrefs
    
for (int i curParam 1>= 0i--)
    {
        if (
gparamInfo[i].flags CALLFUNC_FLAG_BYREF_REUSED)
        {
            
gparams[i] = gparams[gparams[i]];
        }
    }

    
// actual call
    // Pawn - push parameters in reverse order
    
for (int i curParam 1>= 0i--)
    {
        
amx_Push(pAmxgparams[i]);
    }
    
    
err amx_Exec(pAmx, &retValfunc);

    if (
err != AMX_ERR_NONE)
    {
        if (
pDebugger && pDebugger->ErrorExists())
        {
            
//already handled
        
} else {
            
LogError(amxerrNULL);
        }
    }

    if (
pDebugger)
    {
        
pDebugger->EndExec();
    }

    
// process byref params (not byref_reused)
    
for (int i 0curParam; ++i)
    {
        if (
gparamInfo[i].flags CALLFUNC_FLAG_BYREF)
        {
            
// copy back so that references work
            
AMX *amxCalled plugin->getAMX();

            if (
gparamInfo[i].copyback)
            {
                
AMX *amxCaller curPlugin->getAMX();
                
AMX_HEADER *hdrCaller = (AMX_HEADER *)amxCaller->base;
                
AMX_HEADER *hdrCalled = (AMX_HEADER *)amxCalled->base;
                    
memcpy(    /** DEST ADDR **/
                    
(amxCaller->data amxCaller->data : (amxCaller->base hdrCaller->dat)) + gparamInfo[i].byrefAddr
                    
/** SOURCE ADDR **/
                    
(amxCalled->data amxCalled->data : (amxCalled->base hdrCalled->dat)) + gparams[i], 
                    
/** SIZE **/
                    
gparamInfo[i].size sizeof(cell));
            }

            
// free memory used for params passed by reference
            
amx_Release(amxCalledgparams[i]);
        }
    }

    return 
retVal;

But i wasnt able to get a clue about how callfunc* natives execute a public function

Thnx for reading such a long post, hope i was clear !
__________________

My Plugins For ZP

Inactive due to College and Studies

Last edited by abdul-rehman; 12-10-2010 at 08:40.
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 12-10-2010 , 08:38   Re: Using another way of calling functions instead of callfunc_*
Reply With Quote #2

some_function_name( ); ?
__________________
xPaw is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 12-10-2010 , 08:44   Re: Using another way of calling functions instead of callfunc_*
Reply With Quote #3

Quote:
Originally Posted by xPaw View Post
some_function_name( ); ?
I know what you mean but i need a dynamic system to do this:
for eg if the function name is different than i can execute it with my stock instead calling it directly, basically i am making some thing through which other plugins will be able to execute functions in my plugin but i need some other way of executing functions instead of using the old way of callfunc* natives !
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-10-2010 , 10:20   Re: Using another way of calling functions instead of callfunc_*
Reply With Quote #4

Make natives so.
__________________

Last edited by Arkshine; 12-10-2010 at 10:23.
Arkshine is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 12-10-2010 , 10:48   Re: Using another way of calling functions instead of callfunc_*
Reply With Quote #5

Quote:
Originally Posted by Arkshine View Post
Make natives so.
So if i have 87 functions, i will have to make 87 natives ??
Doesnt that sound stupid when i can actually achieve it with one native/stock


PLZ if you guys can give me a solution according to my answer than it would be great, since i also know some other ways but they are not according to my requirrements
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-10-2010 , 11:09   Re: Using another way of calling functions instead of callfunc_*
Reply With Quote #6

i am making some thing through which other plugins will be able to execute functions in my plugin == API

Make an intelligent API in your main plugin. I don't know about your code, it's easy to make a global natives if the functions are the same. ( like pev() for example )
__________________
Arkshine is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 12-10-2010 , 12:27   Re: Using another way of calling functions instead of callfunc_*
Reply With Quote #7

Quote:
Originally Posted by Arkshine View Post
i am making some thing through which other plugins will be able to execute functions in my plugin == API

Make an intelligent API in your main plugin. I don't know about your code, it's easy to make a global natives if the functions are the same. ( like pev() for example )
OK i got you but since you know C++
I think you can help me in directly accessing functions by just there name ??
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-10-2010 , 12:42   Re: Using another way of calling functions instead of callfunc_*
Reply With Quote #8

The callfunc natives were made for this. callfunc natives are the answer to your question. Just because they were created a long time ago doesn't mean they don't work. If you don't want to use that then make a native as Arkshine suggested.
__________________
fysiks is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 12-10-2010 , 12:47   Re: Using another way of calling functions instead of callfunc_*
Reply With Quote #9

Quote:
Originally Posted by fysiks View Post
The callfunc natives were made for this. callfunc natives are the answer to your question. Just because they were created a long time ago doesn't mean they don't work. If you don't want to use that then make a native as Arkshine suggested.
Well i was ready to use them but i hesitated that they might not be effecient and so was searching for an answer
BTW thnx now it means i am restricted to these natives, i will start of with my work now
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-10-2010 , 12:49   Re: Using another way of calling functions instead of callfunc_*
Reply With Quote #10

Quote:
Originally Posted by abdul-rehman View Post
Well i was ready to use them but i hesitated that they might not be effecient and so was searching for an answer
BTW thnx now it means i am restricted to these natives, i will start of with my work now
You should look in other API like plugins and see how it's done.
__________________
fysiks 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 12:18.


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