Jump to content
Sign in to follow this  
dreadkhan

dynamic function calls!

Recommended Posts

dreadkhan

I need a hand in implementing dynamic function calls.

I would like to keep an array of strings, that map to function names like...

global $myarray[3]

$myarray[0] = "function1"

$myarray[1] = "function2"

$myarray[2] = "function3"

this is for an irc bot, where i would have a help command return this array of available commands. then when you send a command, have it call that function.

so when someone in irc says.. function1

it would iterate throguh the available strings in this array, realize that function1 exists and attempt to invoke a function called...function1.

so basically, given a string that represents the name of a function, how can i invoke that function?

I also need to have the ability to check if the function exists, is a try catch that best way to accomplish that?

Share this post


Link to post
Share on other sites
monoceres

Call(), check the help file.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
dreadkhan

Call(), check the help file.

thats incredibly useful, thank you.

how can i check if a function exists before using Call()?

Share this post


Link to post
Share on other sites
monoceres

thats incredibly useful, thank you.

how can i check if a function exists before using Call()?

if the function doesn't exists @error will be set to 0xDEAD.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Richard Robertson

That error code is win.

Share this post


Link to post
Share on other sites
monoceres

That error code is win.

MsgBox(Call(Eval("")),"Win!",Hex(@error*65536+@extended,8))


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Richard Robertson

I feel sorry for you and your wasted free time.

Share this post


Link to post
Share on other sites
monoceres

I feel sorry for you and your wasted free time.

I wouldn't call staying up at 2 am when you should be sleeping free time.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
CodyBarrett

lol that is an awesome error message.. even when you don't WANT to see one... lol

Sets @error to 0xDEAD and @extended to 0xBEEF if the function does not exist or invalid number of parameters.

0xBEEF... WTF hahahaha SWEET i never noticed that before

and

I wouldn't call staying up at 2 am when you should be sleeping free time.

wow man.... all i have to say...

Edited by CodyBarrett

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×