Jump to content
Sign in to follow this  
delme

[SOLVED] Check if a function is already defined?

Recommended Posts

delme

Hey guys, I'm coding an irc bot that will have plugin funtionality, ie: it will call certain functions when events happen, it will work something like this:

A message is recieved, bot checks for the command trigger, if the trigger is found it will call the function IRC_BOT_TRIGGERED($command)

But there will be loads more functions that can be called. What I want to do is be able to see if the user has defined a function to be called when an event happens, say there are more events such as a ping being recieved etc, but I want to only call the function if the user has defined it in the plugin file, is this possible?

To help a bit more, kind of like using #ifndef in C++, I want to be able to see if the function is defined before trying to call it, as it will meet an error if it isn't defined.

Pretty much exactly how the Messenger Live Plus scripting plugins work.

Any help or pointers to the right direction will be appreciated.

Thanks

DELmE

Edited by DELmE

Share this post


Link to post
Share on other sites
PsaltyDS

Couldn't you do that through Call()? It will set @error and @extended if the function doesn't exist or the parameters are wrong, see helpfile.

Cute. One of those dusty corners of the help file I never dug into. Tested it with this:
For $n = 1 To 3
    Call("_Func" & $n)
    ConsoleWrite($n & ":  @error = " & @error & "; @extended = " & @extended & @LF)
Next

Func _Func1()
    ConsoleWrite("One" & @LF)
EndFunc

Func _Func3()
    ConsoleWrite("Three" & @LF)
EndFunc

Thanks for the teachable moment.

:idea:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
evilertoaster

Internally, AutoIt (used to) make a call to the internal function Parser_FindUserFunction() do explicitly find if a user function is in place.

From the public facing functions, AdlibRegister(),HotKeySet(), GUICtrlSetOnEvent(), Execute() and Call() all use this, so could theoretically be used (by checking the @error/@extended) to find if a function exists.

Share this post


Link to post
Share on other sites
delme

Thanks for all the replys guys, they are all very helpful :idea:

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.