Call public function by string
I'm creating a shopmenu and I want to make it as easy to configure as possible. As a result, I'm creating a global constant array, where you specify all the items as well as the function name which gets called once the item is selected, with passed data. What is the best method of calling this function?
Code:
set_task is a possibility but I dislike the delay. There must be a better way. Edit: Ability to stop execution of the function where this was called from would also be handful. It's possible with fakemeta forwards, but do I really need to use fakemeta forwards for one single plugin? |
Re: Call public function by string
have a look here: https://forums.alliedmods.net/showthread.php?t=224430
the shop-part of the plugin. |
Re: Call public function by string
He uses callfunc which is silly.
|
Re: Call public function by string
Quote:
I think you can create a forward. I'm not sure how they work as I've not used them myself but there are many plugins that do this (API-type plugins). |
Re: Call public function by string
Cache the function index and use callfunc_begin_i, it should slightly faster.
I'm using this native which allow to add any function that doesn't take parameters from a plugin : PHP Code:
And menu is here :
|
Re: Call public function by string
Quote:
|
Re: Call public function by string
Quote:
@Connor: Thanks. If I'm correct, callfunc_end returns what the function called does, right? So check if callfunc_end == PLUGIN_HANDLED and prevent the rest of the code execution if that's the case? |
AW: Re: Call public function by string
Quote:
if(callfunc_begin_i(-1, "myfunc") == 1) // successful ... else // failed ... |
Re: Call public function by string
Nope, you need to use the function index instead. See Connor's code.
Also, you have the arguments the other way around, it's supposed to be callfunc_begin_i( iFunctionIndex, -1 ) |
Re: Call public function by string
Oops. :3
|
| All times are GMT -4. The time now is 10:14. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.