Raised This Month: $ Target: $400
 0% 

[Pawn Question] How to set a function as a parameter for a function?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nergal
Veteran Member
Join Date: Apr 2012
Old 09-16-2014 , 01:11   [Pawn Question] How to set a function as a parameter for a function?
Reply With Quote #1

example

PHP Code:
void DoThis(Function(), int value)
{
    
//stuff
}
int Function()
{
    
//stuff

I know you can do this in C/C++ using pointers but is there way to do this in Pawn in any way?
__________________

Last edited by nergal; 09-16-2014 at 01:11.
nergal is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 09-16-2014 , 05:53   Re: [Pawn Question] How to set a function as a parameter for a function?
Reply With Quote #2

I don't know if you can write it as easily as C/Cpp

However you can look though the "functions" section of https://sm.alliedmods.net/api/

I use it and it works great, although calling a function using this must be done carefully.
h3bus is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 09-16-2014 , 08:01   Re: [Pawn Question] How to set a function as a parameter for a function?
Reply With Quote #3

Quote:
Originally Posted by h3bus View Post
I don't know if you can write it as easily as C/Cpp

However you can look though the "functions" section of https://sm.alliedmods.net/api/

I use it and it works great, although calling a function using this must be done carefully.
so would I do this?....

PHP Code:
public void DoThis(Function funcint value)
{
    
//blah blah stuff with func function.

__________________

Last edited by nergal; 09-16-2014 at 08:01.
nergal is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 09-16-2014 , 08:14   Re: [Pawn Question] How to set a function as a parameter for a function?
Reply With Quote #4

In pawn:
PHP Code:
functag myFunction _:public(value);

stock DoThis(myFunction:funcvalue)
{
    
decl result;
    
    
Call_StartFunction(INVALID_HANDLEfunc);
    
Call_PushCell(value);
    
Call_Finish(result);
    
    
// return result;


Last edited by h3bus; 09-16-2014 at 08:15.
h3bus is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 09-16-2014 , 08:25   Re: [Pawn Question] How to set a function as a parameter for a function?
Reply With Quote #5

Quote:
Originally Posted by h3bus View Post
In pawn:
PHP Code:
functag myFunction _:public(value);

stock DoThis(myFunction:funcvalue)
{
    
decl result;
    
    
Call_StartFunction(INVALID_HANDLEfunc);
    
Call_PushCell(value);
    
Call_Finish(result);
    
    
// return result;

That's a private forward :\
I guess it'll have to do then, thx!
__________________
nergal is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 09-16-2014 , 08:34   Re: [Pawn Question] How to set a function as a parameter for a function?
Reply With Quote #6

Yup, don't know if this possible to do this in a more native way.
I tried, I failed.
h3bus is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 09-16-2014 , 08:34   Re: [Pawn Question] How to set a function as a parameter for a function?
Reply With Quote #7

how does this look?

PHP Code:
functag AbilityFunction void public();

    public 
void UseThis(AbilityFunction func)
    {
        
Call_StartFunction(INVALID_HANDLEfunc);
        
Call_Finish();
    } 
__________________
nergal is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 09-16-2014 , 08:40   Re: [Pawn Question] How to set a function as a parameter for a function?
Reply With Quote #8

It should work, however I was not aware that "void" existed in pawn. Does it?
h3bus is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 09-16-2014 , 08:45   Re: [Pawn Question] How to set a function as a parameter for a function?
Reply With Quote #9

Quote:
Originally Posted by h3bus View Post
It should work, however I was not aware that "void" existed in pawn. Does it?
new transitional syntax.

https://forums.alliedmods.net/showthread.php?t=244092

To compile new syntax, use this...

PHP Code:
#pragma newdecls optional 
__________________

Last edited by nergal; 09-16-2014 at 08:47.
nergal is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-16-2014 , 10:10   Re: [Pawn Question] How to set a function as a parameter for a function?
Reply With Quote #10

Be aware that functag and funcenum don't exist in the new syntax... you need to look up what replaced them and use that instead.
Edit: typedef replaced functag and union replaced funcenum.

Speaking of which, I was going to work on passing a data arg to menus in the 1.7 core... I wonder if the AM team moved the menu code yet so I can start modifying them.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 09-16-2014 at 10:26.
Powerlord 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:59.


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