diff --git a/include/QF/progs.h b/include/QF/progs.h index 9817fe0d9..7f11d7cdc 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -65,6 +65,7 @@ void PR_Init (void); void PR_Init_Cvars (void); void PR_PrintStatement (progs_t * pr, dstatement_t *s); +int PR_EnterFunction (progs_t * pr, dfunction_t *f); void PR_ExecuteProgram (progs_t *pr, func_t fnum); void PR_LoadProgsFile (progs_t * pr, QFile *file, int size, int edicts, int zone); diff --git a/libs/gamecode/engine/pr_exec.c b/libs/gamecode/engine/pr_exec.c index 217cdb733..ac5681f5c 100644 --- a/libs/gamecode/engine/pr_exec.c +++ b/libs/gamecode/engine/pr_exec.c @@ -774,6 +774,7 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum) || !pr->builtins[i]->proc) PR_RunError (pr, "Bad builtin call number"); pr->builtins[i]->proc (pr); + st = pr->pr_statements + pr->pr_xstatement; break; } diff --git a/libs/gamecode/engine/pr_obj.c b/libs/gamecode/engine/pr_obj.c index 26696af42..d18b34eca 100644 --- a/libs/gamecode/engine/pr_obj.c +++ b/libs/gamecode/engine/pr_obj.c @@ -48,6 +48,25 @@ static const char rcsid[] = #include "compat.h" +static void +call_function (progs_t *pr, func_t func) +{ + dfunction_t *newf; + + newf = pr->pr_functions + func; + if (newf->first_statement < 0) { + // negative statements are built in functions + int i = -newf->first_statement; + + if (i >= pr->numbuiltins || !pr->builtins[i] + || !pr->builtins[i]->proc) + PR_RunError (pr, "Bad builtin call number"); + pr->builtins[i]->proc (pr); + } else { + pr->pr_xstatement = PR_EnterFunction (pr, newf); + } +} + static const char * class_get_key (void *c, void *pr) { @@ -357,7 +376,8 @@ pr_obj_msgSend (progs_t *pr) PR_RunError (pr, "%s does not respond to %s", PR_GetString (pr, object_get_class_name (pr, self)), PR_GetString (pr, _cmd->sel_id)); - PR_ExecuteProgram (pr, imp); + + call_function (pr, imp); } static void @@ -378,7 +398,7 @@ pr_obj_msgSend_super (progs_t *pr) PR_RunError (pr, "%s does not respond to %s", PR_GetString (pr, object_get_class_name (pr, self)), PR_GetString (pr, _cmd->sel_id)); - PR_ExecuteProgram (pr, imp); + call_function (pr, imp); } static void