diff options
author | Haruna <haru@dotalux.com> | 2015-04-25 19:32:45 +0200 |
---|---|---|
committer | Haruna <haru@dotalux.com> | 2015-04-25 19:32:45 +0200 |
commit | 0f7a7933f8940c2d8ae1d739d11dc9c80ffda61a (patch) | |
tree | 4a79261ff07716ce834de97444368cf966dee0a7 /src/map/script.c | |
parent | d27eea4b5c112ab0209045ad65989697899dced0 (diff) | |
parent | 2970847b879821f738bb892e9079c0ae2a5d08c7 (diff) | |
download | hercules-0f7a7933f8940c2d8ae1d739d11dc9c80ffda61a.tar.gz hercules-0f7a7933f8940c2d8ae1d739d11dc9c80ffda61a.tar.bz2 hercules-0f7a7933f8940c2d8ae1d739d11dc9c80ffda61a.tar.xz hercules-0f7a7933f8940c2d8ae1d739d11dc9c80ffda61a.zip |
Merge pull request #502 from k-py/bugfix-return-getvariableofnpc
Fix script function return always removing references from NPC variables.
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/map/script.c b/src/map/script.c index b7fdf1596..51bb344fe 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -5682,6 +5682,13 @@ BUILDIN(getarg) /// return; /// return <value>; BUILDIN(return) { + st->state = RETFUNC; + + if( st->stack->defsp < 1 || st->stack->stack_data[st->stack->defsp-1].type != C_RETINFO ) { + // Incorrect usage of return outside the scope of a function or subroutine. + return true; // No need for further processing, running script is about to be aborted. + } + if( script_hasdata(st,2) ) {// return value struct script_data* data; @@ -5695,16 +5702,19 @@ BUILDIN(return) { script->get_val(st, data);// current scope, convert to value if( data->ref && data->ref->vars == st->stack->stack_data[st->stack->defsp-1].u.ri->scope.vars ) data->ref = NULL; // Reference to the parent scope, remove reference pointer - } else if( name[0] == '.' && !data->ref ) { - // script variable without a reference set, link to current script - data->ref = (struct reg_db *)aCalloc(sizeof(struct reg_db), 1); - script->add_pending_ref(st, data->ref); - data->ref->vars = st->script->local.vars; - if( !st->script->local.arrays ) - st->script->local.arrays = idb_alloc(DB_OPT_BASE); - data->ref->arrays = st->script->local.arrays; - } else if ( name[0] == '.' /* && data->ref != NULL */ ) { - data->ref = NULL; // Reference to the parent scope's script, remove reference pointer. + } else if( name[0] == '.' ) { + // npc variable + if( !data->ref ) { + // npc variable without a reference set, link to current script + data->ref = (struct reg_db *)aCalloc(sizeof(struct reg_db), 1); + script->add_pending_ref(st, data->ref); + data->ref->vars = st->script->local.vars; + if( !st->script->local.arrays ) + st->script->local.arrays = idb_alloc(DB_OPT_BASE); + data->ref->arrays = st->script->local.arrays; + } else if( data->ref->vars == st->stack->stack_data[st->stack->defsp-1].u.ri->script->local.vars ) { + data->ref = NULL; // Reference to the parent scope's script, remove reference pointer. + } } } } @@ -5712,7 +5722,7 @@ BUILDIN(return) { {// no return value script_pushnil(st); } - st->state = RETFUNC; + return true; } |