Function Prototypes
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:
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. |
Nope, no prototypes
|
If you want prototypes to read from when you are doing main, I always place them as a comment:
Code:
|
prototypes are not nessasary for PAWN; it has a two stroke compiler.
|
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. |
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. |
As the guide says, you can do this:
Code:
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). |
| All times are GMT -4. The time now is 16:45. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.