Raised This Month: $ Target: $400
 0% 

Natives and Forwards


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
x6herbius
Senior Member
Join Date: May 2011
Location: West Sussex, UK
Old 08-19-2011 , 11:00   Natives and Forwards
Reply With Quote #1

I'm not entirely clear on the exact differences between "forwards" and "natives". I've read the Wiki article on them but it would be useful to me to have a couple of things cleared up.

I think (unless I'm mistaken) that a native is a function in a plugin that is called by another plugin, and a forward is a function that is called from the plugin that owns it and that other plugins can hook into when it's called. Is this correct? I'm used to the input/output system from Hammer and the Source SDK so I'm guessing it's a similar kind of thing. If so, if a forward is called then does the code in the parent plugin get run before any code other plugins may hook in with, or after?

Thanks for any info.
x6herbius is offline
Send a message via Skype™ to x6herbius
FaTony
Veteran Member
Join Date: Aug 2008
Old 08-19-2011 , 11:55   Re: Natives and Forwards
Reply With Quote #2

Interplugin communication is not a part of core Pawn language, so I'll start with that.

Pawn is designed as embedded language so it only exists in the context of it's host. Native functions are provided by host and implemented in it (hence the name). Forwards instead exist only as prototypes and program (generally speaking, Pawn do not presume that it's programs are plugins by default) can implement them so the host can call them.

SourcePawn adds the ability for plugins to become the hosts. They can create native functions that users can call. They also can create forwards so the can trigger specific functions in users.
__________________
FaTony is offline
x6herbius
Senior Member
Join Date: May 2011
Location: West Sussex, UK
Old 08-19-2011 , 12:08   Re: Natives and Forwards
Reply With Quote #3

OK, thanks. So if I made a plugin, wrote a native, hooked it up properly and made another plugin that used it as a dependency, I could call that command from the second plugin and the code from the first would be run, correct? In the case of forwards, the prototype would be defined in the first plugin and, whenever it was called, the code from the second plugin would be run instead?

If that's along the right lines then I think I get it. If more than one plugin used a forward from a parent plugin, though, which would be run first?
x6herbius is offline
Send a message via Skype™ to x6herbius
FaTony
Veteran Member
Join Date: Aug 2008
Old 08-19-2011 , 12:34   Re: Natives and Forwards
Reply With Quote #4

The word "hooking" usually means that you're doing something that you're not supposed to do, there's no hooking in terms of writing your own native functions.
Quote:
Originally Posted by x6herbius View Post
I could call that command from the second plugin and the code from the first would be run, correct?
Yes.

Quote:
Originally Posted by x6herbius View Post
In the case of forwards, the prototype would be defined in the first plugin
When you write a plugin that will expose it to others, you provide a separate include file that contains prototypes for all natives and forwards. See SM includes for a good examples.

Quote:
Originally Posted by x6herbius View Post
and, whenever it was called, the code from the second plugin would be run instead?
Yes.

Quote:
Originally Posted by x6herbius View Post
If that's along the right lines then I think I get it. If more than one plugin used a forward from a parent plugin, though, which would be run first?
You should not rely on the order of execution. When the forward is called, it's assumed that all plugins have the same rights. Don't know the exact implementation though.
__________________
FaTony is offline
x6herbius
Senior Member
Join Date: May 2011
Location: West Sussex, UK
Old 08-19-2011 , 12:47   Re: Natives and Forwards
Reply With Quote #5

OK, thanks a lot for clarifying.
x6herbius is offline
Send a message via Skype™ to x6herbius
DarkEnergy
SourceMod Donor
Join Date: Apr 2008
Location: Georgia Tech, MSECE
Old 08-19-2011 , 19:52   Re: Natives and Forwards
Reply With Quote #6

Quote:
Forward- a function call to you (and usually other plugins) and variables are passed to you if any.
Its like one plugins says "Hey everyone, this person's and this race and this skill level changed to this this and this, just letting u know! Thanks for tuning in".
You are not required to implement all forwards, the forward will not affect you if you did not implement it. However some are very important like the one below:
ie OnSkillLevelChanged(client,race,newlevel)

Native- a function call to another plugin (the plugin that registered it, War3Source registered War3_GetGame() so when u call War3_GetGame() War3Source handles it), you provide the variables to them if any. Sort of like a forward to a single plugin. Natives we use often to return values like War3_GetGame() returns you a number which indicates the current game (CS TF DODS).

Stock- A normal function provided by an include file. If unused, it won't be compiled.
__________________
War3:Source Developer
"Your CPU is just a bunch of Muxes"
DarkEnergy 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 08:53.


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