diff options
-rw-r--r-- | src/map/script.c | 69 | ||||
-rw-r--r-- | src/map/script.h | 1 |
2 files changed, 68 insertions, 2 deletions
diff --git a/src/map/script.c b/src/map/script.c index 1fdbc7c01..b03f0ede4 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -3488,7 +3488,7 @@ void run_script_main(struct script_state *st) run_func(st); if(st->state==GOTO){ st->state = RUN; - if( gotocount>0 && (--gotocount)<=0 ){ + if( !st->freeloop && gotocount>0 && (--gotocount)<=0 ){ ShowError("run_script: infinity loop !\n"); script_reportsrc(st); st->state=END; @@ -3536,7 +3536,7 @@ void run_script_main(struct script_state *st) st->state=END; break; } - if( cmdcount>0 && (--cmdcount)<=0 ){ + if( !st->freeloop && cmdcount>0 && (--cmdcount)<=0 ){ ShowError("run_script: infinity loop !\n"); script_reportsrc(st); st->state=END; @@ -15965,6 +15965,64 @@ BUILDIN_FUNC(setmounting) { } return 0; } +/** + * Retrieves quantity of arguments provided to callfunc/callsub. + * getargcount() -> amount of arguments received in a function + **/ +BUILDIN_FUNC(getargcount) { + struct script_retinfo* ri; + + if( st->stack->defsp < 1 || st->stack->stack_data[st->stack->defsp - 1].type != C_RETINFO ) { + ShowError("script:getargcount: used out of function or callsub label!\n"); + st->state = END; + return 1; + } + ri = st->stack->stack_data[st->stack->defsp - 1].u.ri; + + script_pushint(st, ri->nargs); + + return 0; +} +/** + * is_function(<function name>) -> 1 if function exists, 0 otherwise + **/ +BUILDIN_FUNC(is_function) { + const char* str = script_getstr(st,2); + + if( ((struct script_code*)strdb_get(userfunc_db, str)) != NULL ) + script_pushint(st,1); + else + script_pushint(st,0); + + return 0; +} +/** + * get_revision() -> retrieves the current svn revision (if available) + **/ +BUILDIN_FUNC(get_revision) { + const char * revision; + + if ( (revision = get_svn_revision()) != 0 ) + script_pushstrcopy(st,revision); + else + script_pushconststr(st,"Unknown"); + + return 0; +} +/** + * freeloop(<toggle>) -> toggles this script instance's looping-check ability + **/ +BUILDIN_FUNC(freeloop) { + + if( script_getnum(st,2) ) + st->freeloop = 1; + else + st->freeloop = 0; + + script_pushint(st, st->freeloop); + + return 0; +} // declarations that were supposed to be exported from npc_chat.c #ifdef PCRE_SUPPORT BUILDIN_FUNC(defpattern); @@ -16386,6 +16444,13 @@ struct script_function buildin_func[] = { BUILDIN_DEF(setdragon,"?"),//[Ind] BUILDIN_DEF(ismounting,""),//[Ind] BUILDIN_DEF(setmounting,""),//[Ind] + /** + * rAthena and beyond! + **/ + BUILDIN_DEF(getargcount,""), + BUILDIN_DEF(is_function,"s"), + BUILDIN_DEF(get_revision,""), + BUILDIN_DEF(freeloop,"i"), //Quest Log System [Inkfish] BUILDIN_DEF(setquest, "i"), BUILDIN_DEF(erasequest, "i"), diff --git a/src/map/script.h b/src/map/script.h index 2ed163a0f..9de1285b8 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -125,6 +125,7 @@ struct script_state { //For backing up purposes struct script_state *bk_st; int bk_npcid; + unsigned freeloop : 1;// used by buildin_freeloop }; struct script_reg { |