Raised This Month: $32 Target: $400
 8% 

How to pass methodmap functions to natives?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 06-21-2015 , 15:58   How to pass methodmap functions to natives?
Reply With Quote #1

How would I pass a method in a methodmap to a native like SMCParser.OnNewSection.set()?

EDIT: I tried via <methodmapname>.<methodname> as well as this.<methodname> but neither work.
__________________

Last edited by WildCard65; 06-21-2015 at 15:58.
WildCard65 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-21-2015 , 16:53   Re: How to pass methodmap functions to natives?
Reply With Quote #2

A few things:
  • The SMCParser methodmap doesn't have an OnNewSection. Did you mean OnEnterSection? Also, you don't call the set method, but rather the syntax is myParser.OnEnterSection = methodnamehere
  • You can't pass a native to a call expecting a Function.

You may ask "why?" for the latter.

The short answer:

A native is just the declared interface and not itself a Function.

The long answer:

It has to do with how forwards work. For a private forward or remote-function call to work, you need to have the plugin Handle for the plugin implementing it. Most plugins use the caller of the registration function (SMCParser.OnEnterSection.set's IPluginContext in this case), but a native declaration is compiled into any plugin that uses #include to include the plugin's inc file, not just the plugin implementing it.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 06-21-2015 , 18:33   Re: How to pass methodmap functions to natives?
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
The SMCParser methodmap doesn't have an OnNewSection. Did you mean OnEnterSection? Also, you don't call the set method, but rather the syntax is myParser.OnEnterSection = methodnamehere
1) Thx for correction of Property Name.
2) I know how to call it, I just put it's full native name cause I wanted to.

Now, for your "why", cause I want to "exploit" methodmaps as much as I can cause they work very closely to classes.
And another thing, I was refering to non-native methodmap method.
eg:
PHP Code:
static int a 5;
methodmap Test
{
    public 
int LOL()
    {
        return 
a;
    }
}; 
__________________

Last edited by WildCard65; 06-21-2015 at 18:35.
WildCard65 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-21-2015 , 19:28   Re: How to pass methodmap functions to natives?
Reply With Quote #4

Quote:
Originally Posted by WildCard65 View Post
1) Thx for correction of Property Name.
2) I know how to call it, I just put it's full native name cause I wanted to.

Now, for your "why", cause I want to "exploit" methodmaps as much as I can cause they work very closely to classes.
And another thing, I was refering to non-native methodmap method.
eg:
PHP Code:
static int a 5;
methodmap Test
{
    public 
int LOL()
    {
        return 
a;
    }
}; 
The function you just mentioned?

It's implicitly this function:

public int Test.LOL(Test this)

That's how Methodmaps work. They add an implicit first argument named this with the methodmap's type as its type.

I don't know if Methodmaps support what we'd call static methods in C#/Java, which belong to the class itself and not the instance, but this isn't one.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 06-21-2015 , 19:47   Re: How to pass methodmap functions to natives?
Reply With Quote #5

i dont knw how itd pass the object so prolly not possible for nonstatic methods in functions that arent designed for them
Miu is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 06-21-2015 , 20:06   Re: How to pass methodmap functions to natives?
Reply With Quote #6

Quote:
Originally Posted by Powerlord View Post
The function you just mentioned?

It's implicitly this function:

public int Test.LOL(Test this)

That's how Methodmaps work. They add an implicit first argument named this with the methodmap's type as its type.

I don't know if Methodmaps support what we'd call static methods in C#/Java, which belong to the class itself and not the instance, but this isn't one.
I tried making it status, but compiler spit out same error with it expecting a '('. Methodmaps also support static methods(see TopMenu's methodmap).
__________________
WildCard65 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 22:52.


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