egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Custom options in procedures

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
FallFromGrace
Voice


Joined: 28 Jul 2008
Posts: 17

PostPosted: Mon Jul 28, 2008 8:55 am    Post subject: Custom options in procedures Reply with quote

i can make default values in my procs, f.e. proc1 {string1 string2 {nocase false}}... but how can i make options?

"[proc1 "asd" "qwe" -nocase]", is it possible?
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Jul 28, 2008 9:36 am    Post subject: Reply with quote

I believe you are looking for the special parameter called "args", which accepts 0 or more values..

Code:
proc proc1 {string1 string2 args} {
 #Instantiate option-variables
 set nocase 0

 #Do we have any options to care for?
 if {[llength $args] > 0} {

  #Iterate through the whole list of options...
  foreach arg $args {

   #... and parse each to see if they're valid or not.
   #Use the "default" keyword to catch any unknown options and bail out.
   switch -- $arg {
    "-nocase" {
     set nocase 1
    }
    default {
     error "Unknown option \"$arg\""
    }
   }
  }
 }

 #All options (if any) parsed, and option-variables properly updated,
 # lets do the actual work now

 ...
}


Of course, this could also be done in some manner using default values, although ordering would become an issue. The above example still requires the first two parameters to be the strings to be operated on, however, should you support numerous options, the order among those would not matter. With some modification, you could also support options with values, such as "[proc2 word1 word2 -format "%s - %s"]"
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber