From 65a8ab523aa6bd255f48518cdc8e1ca75760b113 Mon Sep 17 00:00:00 2001 From: false_genesis Date: Fri, 25 Apr 2008 23:25:58 +0000 Subject: [PATCH] * added "help" script with some basic information (as suggested by Visagalis). detailed help about specific commands not yet written. * fixed major bug in the DefScript interpreter that could cause a DefReturnResult to return from the calling function too early and terminate the whole call stack. this could lead to scripts beeing executed only to half and then suddenly aborting execution without any sign that something went wrong. * "ljoin"-func does now accept start and end list index to join --- bin/scripts/help.def | 86 +++++++++++++++++++ src/Client/DefScript/DefScript.h | 4 +- .../DefScript/DefScriptListFunctions.cpp | 8 +- 3 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 bin/scripts/help.def diff --git a/bin/scripts/help.def b/bin/scripts/help.def new file mode 100644 index 0000000..9f17c33 --- /dev/null +++ b/bin/scripts/help.def @@ -0,0 +1,86 @@ +#script=help + +set,argstr ?{lowercase ${@def}} +lsplit,args,{ } ${argstr} + +out == ${@version} :: help == + +if ?{not ?{llen args}} + log - type "help list" to list all avalible help topics + out - type "help basic" for some basic usage information. + out >> visit http:\//www.mangosclient.org for more information + out - type "help " to see detailed information about a command + return +endif + +if ?{equal,basic ?{lindex,args 0}} + out >> "say ..." to say something (might not work on servers blocking global language). + out >> "say, ..." to say something in specified language (ID or name). + out >> "yell", "sayguild", "sayparty" is used in the same manner. + out >> there is a fun command, "sl, " that says text in leetspeak. + out >> "whisper,," to whisper to a player, language is optional, like in "say". + out >> "joinchannel " joins a channel, "leavechannel <...>" leaves a channel". + out >> "chan,, " says something in a channel. language is optional. + out >> "me " performs an emote. ID or emote name can be used. + return +endif + +if ?{equal,list ?{lindex,args 0}} + == Help topics avalible: ?{llen reg_name} + set,i 0 + loop + if ?{bigger_eq,${i} ?{llen reg_name}} + exitloop + endif + out "help ?{lindex,reg_name ${i}}" + endloop + return +endif + +set,i ?{lfind,reg_name ?{lindex,args 0}} +if ?{strlen ${i}} + ?{lindex,reg_func ${i}} ?{ljoin,args { }} // call the function attached to the specified name, with all args passed to this func +else + logerror No help exists for "${argstr}"... +endif + + + +//-------------------------------------------------------- +#script=RegisterHelpTopic +//-------------------------------------------------------- +// @def: topic name "help " +// @0: function name to call +set,topic ?{lowercase ${@def}} +set,func ?{lowercase ${@0}} +if ?{not ?{strlen ${topic}}} + return +endif +if ?{not ?{strlen ${name}}} + return +endif + +if ?{not ?{lcontains,#help::reg_name ${topic}}} + lappend,#help::reg_name ${topic} + lappend,#help::reg_func ${func} +endif + + + +//====================================================================================== +//=== Help for some internal/predefined commands ======================================= +//====================================================================================== + +#script=dummy +#onload +RegisterHelpTopic,help__say say +RegisterHelpTopic,help__yell yell +RegisterHelpTopic,help__chan chan +RegisterHelpTopic,help__sl sl +#/onload + + + +#script=help__say +// to be written..... + diff --git a/src/Client/DefScript/DefScript.h b/src/Client/DefScript/DefScript.h index 471e6ba..d22ee94 100644 --- a/src/Client/DefScript/DefScript.h +++ b/src/Client/DefScript/DefScript.h @@ -28,8 +28,8 @@ struct DefReturnResult DefReturnResult() { ok=true; mustreturn=false; ret="true"; } DefReturnResult(bool b) { ok=true; mustreturn=false; ret=b?"true":"false"; } DefReturnResult(std::string s) { ok=true; mustreturn=false; ret=s; } - DefReturnResult(const char *s) { DefReturnResult(std::string(s)); } - DefReturnResult(char *s) { DefReturnResult(std::string(s)); } + DefReturnResult(const char *s) { ok=true; mustreturn=false; ret=s; } + DefReturnResult(char *s) { ok=true; mustreturn=false; ret=s; } bool ok; // true if the execution of the current statement was successful bool mustreturn; std::string ret; // return value used by ?{..} diff --git a/src/Client/DefScript/DefScriptListFunctions.cpp b/src/Client/DefScript/DefScriptListFunctions.cpp index 688bed9..a12c3ed 100644 --- a/src/Client/DefScript/DefScriptListFunctions.cpp +++ b/src/Client/DefScript/DefScriptListFunctions.cpp @@ -159,8 +159,12 @@ DefReturnResult DefScriptPackage::func_ljoin(CmdSet& Set) std::string r; DefList *l = lists.GetNoCreate(_NormalizeVarName(Set.arg[0],Set.myname)); if(!l) - return ""; - for(unsigned int i = 0; i < l->size(); i++) + return ""; + unsigned int start_from = (unsigned int)toUint64(Set.arg[1]); + unsigned int end_at = (unsigned int)toUint64(Set.arg[2]); + if(!end_at) + end_at = l->size(); + for(unsigned int i = start_from; i < end_at; i++) { r += (*l)[i]; if( i+1 != l->size() )