diff --git a/src/map/script.c b/src/map/script.c index 9d2ce581a0..e730df9ef9 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -111,6 +111,8 @@ #define script_getnum(st,val) conv_num(st, script_getdata(st,val)) #define script_getstr(st,val) conv_str(st, script_getdata(st,val)) #define script_getref(st,val) ( script_getdata(st,val)->ref ) +// Returns name of currently running function +#define script_getfuncname(st) ( st->funcname ) // Note: "top" functions/defines use indexes relative to the top of the stack // -1 is the index of the data at the top @@ -623,22 +625,6 @@ static void script_reportfunc(struct script_state* st) } } -// Returns name of currently running function -static char* script_getfuncname(struct script_state *st) -{ - int i; - char* name = NULL; - for( i = 0; i < st->stack->sp; ++i ) { - struct script_data* data = &st->stack->stack_data[i]; - if(data->type == C_NAME && str_data[data->u.num].type == C_FUNC) { - name = reference_getname(data); - if(strcmp(name,"jump_zero")) - break; - } - } - return name; -} - /*========================================== * Output error message *------------------------------------------*/ @@ -3454,8 +3440,7 @@ int run_func(struct script_state *st) for( i = end_sp-1; i > 0 ; --i ) if( st->stack->stack_data[i].type == C_ARG ) break; - if( i == 0 ) - { + if( i == 0 ) { ShowError("script:run_func: C_ARG not found. please report this!!!\n"); st->state = END; script_reportsrc(st); @@ -3466,10 +3451,10 @@ int run_func(struct script_state *st) st->end = end_sp; data = &st->stack->stack_data[st->start]; - if( data->type == C_NAME && str_data[data->u.num].type == C_FUNC ) + if( data->type == C_NAME && str_data[data->u.num].type == C_FUNC ) { func = data->u.num; - else - { + st->funcname = reference_getname(data); + } else { ShowError("script:run_func: not a buildin command.\n"); script_reportdata(data); script_reportsrc(st); @@ -3477,12 +3462,11 @@ int run_func(struct script_state *st) return 1; } - if( script_config.warn_func_mismatch_argtypes ) - { + if( script_config.warn_func_mismatch_argtypes ) { script_check_buildin_argtype(st, func); } - if(str_data[func].func){ + if(str_data[func].func) { if (str_data[func].func(st)) //Report error script_reportsrc(st); } else { @@ -3496,8 +3480,7 @@ int run_func(struct script_state *st) return 0; pop_stack(st, st->start, st->end); - if( st->state == RETFUNC ) - {// return from a user-defined function + if( st->state == RETFUNC ) {// return from a user-defined function struct script_retinfo* ri; int olddefsp = st->stack->defsp; int nargs; diff --git a/src/map/script.h b/src/map/script.h index 9dcc4ac012..4a8df5517c 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -134,6 +134,7 @@ struct script_state { unsigned op2ref : 1;// used by op_2 unsigned npc_item_flag : 1; unsigned mes_active : 1; // Store if invoking character has a NPC dialog box open. + unsigned char* funcname; // Stores the current running function name }; struct script_reg {