From d7db381921c0d6c6b1cdaa4b2083aa1d877046f5 Mon Sep 17 00:00:00 2001 From: Haru Date: Thu, 31 Dec 2015 21:12:31 +0100 Subject: Improved handling of nested function calls by the HULD Signed-off-by: Haru --- src/map/script.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/map/script.c b/src/map/script.c index d97dacb89..46116f75a 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -803,18 +803,13 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom) char *arg = NULL; char null_arg = '\0'; int func; - bool nested_call = false, macro = false; + bool macro = false; // is need add check for arg null pointer below? func = script->add_word(p); - if( script->str_data[func].type == C_FUNC ) { - /** only when unset (-1), valid values are >= 0 **/ - if( script->syntax.last_func == -1 ) - script->syntax.last_func = script->str_data[func].val; - else { //Nested function call - script->syntax.nested_call++; - nested_call = true; - + if (script->str_data[func].type == C_FUNC) { + script->syntax.nested_call++; + if (script->syntax.last_func != -1) { if( script->str_data[func].val == script->buildin_lang_macro_offset ) { script->syntax.lang_macro_active = true; macro = true; @@ -823,6 +818,7 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom) if( !macro ) { // buildin function + script->syntax.last_func = script->str_data[func].val; script->addl(func); script->addc(C_ARG); } @@ -915,14 +911,11 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom) script->syntax.lang_macro_active = false; } - if( nested_call ) - script->syntax.nested_call--; - - if( !script->syntax.nested_call ) - script->syntax.last_func = -1; - - if( !macro ) + if (!macro) { + if (0 == --script->syntax.nested_call) + script->syntax.last_func = -1; script->addc(C_FUNC); + } return p; } @@ -1058,6 +1051,8 @@ const char* parse_variable(const char* p) } // push the set function onto the stack + script->syntax.nested_call++; + script->syntax.last_func = script->str_data[script->buildin_set_ref].val; script->addl(script->buildin_set_ref); script->addc(C_ARG); @@ -1109,6 +1104,8 @@ const char* parse_variable(const char* p) // close the script by appending the function operator script->addc(C_FUNC); + if (--script->syntax.nested_call == 0) + script->syntax.last_func = -1; // push the buffer from the method return p; @@ -1295,7 +1292,7 @@ const char* parse_simpleexpr(const char *p) if( script->lang_export_fp && !duplicate && ( ( ( script->syntax.last_func == script->buildin_mes_offset || - script->syntax.last_func == script->buildin_select_offset ) && !script->syntax.nested_call + script->syntax.last_func == script->buildin_select_offset ) ) || script->syntax.lang_macro_active ) ) { const char *line_start = start_point; const char *line_end = start_point; -- cgit v1.2.3-60-g2f50