• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Function overloading?
#1
I've seen a tutorial on function overloading but that just seems kind of bad.?



I'm creating a function to manipulate entity data (players, houses, businesses, etc.). Since I plan to generate sql queries inside the function I wanted to have the ability of manipulating with player data if the player is online or offline.



My question is, is there any possibility of creating function overloading with the first parameter either being int (playerid) and string (playername). I guess it creates a problem with one being variable and other an array.?



I have been searching forums, github, pawn documentation but still nothing. I figured if anybody can help me it must be Y_Less.
  Reply
#2
It is possible using some macroes and tags to specifically match a "sub-pattern", here's an example:

https://github.com/pBlueG/SA-MP-MySQL/bl...#L185-L189

The thing with tags is that it allows you to define more than one macro replacement for a function (it is technically recognized as different because of the tags). This example macro will match a literal string and variables tagged with "string:" (the tag will be removed during compilation, it's needed because there's no reliable way to detect that a variable contains a string), and it will automatically use cache_get_value_name for them, and anything else will use cache_get_value_index.

I barely know the concept so I might be a bit wrong, but that's the basic concept and it works!
  Reply
#3
I'll try to work something out and post if it works or doesn't. Maybe in the meanwhile someone else posts something helpfull.



Thank you :)
  Reply


Forum Jump: