[Pawn] Function overloading? - Printable Version + open.mp forum (https://forum.open.mp) -- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3) --- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10) --- Thread: [Pawn] Function overloading? (/showthread.php?tid=48) |
Function overloading? - mr_sacrimoni - 2019-04-13 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. RE: Function overloading? - Graber - 2019-04-13 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/blob/a8113cd3a7b5dcee1002622c5901ff78e3e6e3fe/a_mysql.inc.in#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! RE: Function overloading? - mr_sacrimoni - 2019-04-13 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 :) |