Raised This Month: $ Target: $400
 0% 

Function Prototypes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ryan
Senior Member
Join Date: May 2004
Location: NH, USA
Old 03-17-2006 , 01:47   Function Prototypes
Reply With Quote #1

I have read the pawn manual and have seen support for function prototypes, but how can they be implemented in pawn scripts?

are you supposed to call them with a forward? like so?

Code:
// prototype? forward somefunc( var1, var2 ); // then the actual function declared like this? public somefunc( var1, var2 ) {   // ... some code in here   return PLUGIN_HANDLED; }

My script is rather large, and I am having some issues with functions calling other functions or variables before they are defined (i use a multiple file approach already, so the two-parse functionality of pawn does not work).

I would like to start defining prototypes like traditional c-based languages, and just want to know if my syntax above is correct. Thanks.
__________________
Warcraft 3: Expansion
Homepage | Downloads | Forums
Ryan is offline
Send a message via AIM to Ryan
Des12
Senior Member
Join Date: Jan 2005
Old 03-17-2006 , 17:01  
Reply With Quote #2

Nope, no prototypes
__________________
-Dest Romano

www.JustRP.com
A TSRP Server

Quote:
Originally Posted by Brad
Don't you go be bringing reality into this.
Des12 is offline
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 03-17-2006 , 18:32  
Reply With Quote #3

If you want prototypes to read from when you are doing main, I always place them as a comment:

Code:
//int somefunc(int var1, double var2 = 1337)
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 03-17-2006 , 19:01  
Reply With Quote #4

prototypes are not nessasary for PAWN; it has a two stroke compiler.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
BAILOPAN
Join Date: Jan 2004
Old 03-17-2006 , 19:20  
Reply With Quote #5

if this is happening you probably have an organization problem. Your best bet is to, rather than split a script into multiple files, to split it into multiple plugins.

Another recommendation I can give is to keep things organized by prefixing everything in each file with a unique tag, like:
#include <gaben>
would prefix every function with GB_ or something.

Pawn doesn't require any specific ordering because logically it doesn't make sense for a scripting language to have that.
__________________
egg
BAILOPAN is offline
Ryan
Senior Member
Join Date: May 2004
Location: NH, USA
Old 03-17-2006 , 20:48  
Reply With Quote #6

I realize it doesnt require it, however, I would like to do it. Like I said, with mutliple files, the 2-pass compilation doesnt help in taking care of definition problems if they arise, because I'm assuming it makes a 2pass per file, rather than a 2pass on the whole script. i dunno-- regardless, it doesn't work. I am now having to put defines in my global inline file, where I would rather have them in a file specific to the define type.

Bailo, you may be right in that it just needs to be reorganized, but trust me, I have organized this beast enough times to know that with each function added, the possibility of having to move yet another define out from where I want it will arise. It would be much EASIER and more efficient for me to just make headers with their defines and prototypes to ensure that it will never happen. YES it is a script, and YES typically there would be no need to use prototypes, but at > 20k lines and over 300kb compiled, my war3x plugin could make very effective use of prototypes... so if it is possible to do them, I would like to know.

Like I said, I have read the pawn language guide and have seen that prototypes are available, but no examples were given of the syntax.

This plugin may as well be a module, I'm not talking some 100-200 lines of code here. If I were, than yes, I could see how rediculous this request might seem.


Any help is appreciated.
__________________
Warcraft 3: Expansion
Homepage | Downloads | Forums
Ryan is offline
Send a message via AIM to Ryan
BAILOPAN
Join Date: Jan 2004
Old 03-17-2006 , 22:05  
Reply With Quote #7

As the guide says, you can do this:
Code:
#include <amxmodx> forward ThisFunction(num); public plugin_init() {    ThisFunction(5); } ThisFunction() {    return 56 }

However, I seriously recommend not abusing this.

If you need forward declarations for anything other than abstracting a set of API (like natives), you are missing the intent of plugins/doing something wrong. I'm sticking with my recommendations of either using a proper naming scheme or following the increasing trend of splitting plugins into smaller, intercommunicating pieces (the days of massive, monocode plugins are slowly ending).
__________________
egg
BAILOPAN 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 16:45.


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