From 38f51a0737fd4570ce597f6d01a26d3d90e06582 Mon Sep 17 00:00:00 2001 From: black Date: Fri, 31 Oct 2003 19:24:12 +0000 Subject: [PATCH] Added isfunction and changed callfunction so it works git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3620 d7cf8633-e32d-0410-b094-e92efae38249 --- mprogdefs.h | 7 +++---- prvm_cmds.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++----- prvm_edict.c | 2 +- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/mprogdefs.h b/mprogdefs.h index d06e2700..0c7435cf 100644 --- a/mprogdefs.h +++ b/mprogdefs.h @@ -7,9 +7,8 @@ typedef struct int self; } m_globalvars_t; -typedef struct +/*typedef struct { - string_t classname; -} m_entvars_t; +} m_entvars_t;*/ -#define M_PROGHEADER_CRC 40313 +#define M_PROGHEADER_CRC 10020 diff --git a/prvm_cmds.c b/prvm_cmds.c index cc3e46bd..6adb8be7 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -2732,25 +2732,73 @@ VM_M_callfunction ========= */ mfunction_t *PRVM_ED_FindFunction (const char *name); -int PRVM_EnterFunction (mfunction_t *f); void VM_M_callfunction(void) { mfunction_t *func; char *s; + if(prog->argc == 0) + PRVM_ERROR("VM_M_callfunction: 1 parameter is required !\n"); + s = PRVM_G_STRING(OFS_PARM0 + (prog->argc - 1)); if(!s) - PRVM_ERROR("VM_M_getfunction: null string !\n"); + PRVM_ERROR("VM_M_callfunction: null string !\n"); VM_CheckEmptyString(s); func = PRVM_ED_FindFunction(s); - if(func) - PRVM_EnterFunction(func); + if(!func) + PRVM_ERROR("VM_M_callfunciton: function %s not found !\n", s); + else if (func->first_statement < 0) + { + // negative statements are built in functions + int builtinnumber = -func->first_statement; + prog->xfunction->builtinsprofile++; + if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber]) + prog->builtins[builtinnumber](); + else + PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME); + } + else if(func > 0) + { + prog->argc--; + PRVM_ExecuteProgram(func - prog->functions,""); + prog->argc++; + } } +/* +========= +VM_M_isfunction + +float isfunction(string function_name) +========= +*/ +mfunction_t *PRVM_ED_FindFunction (const char *name); +void VM_M_isfunction(void) +{ + mfunction_t *func; + char *s; + + VM_SAFEPARMCOUNT(1, VM_M_isfunction); + + s = PRVM_G_STRING(OFS_PARM0); + + if(!s) + PRVM_ERROR("VM_M_isfunction: null string !\n"); + + VM_CheckEmptyString(s); + + func = PRVM_ED_FindFunction(s); + + if(!func) + PRVM_G_FLOAT(OFS_RETURN) = false; + else + PRVM_G_FLOAT(OFS_RETURN) = true; +} + /* ========= VM_M_writetofile @@ -2905,7 +2953,8 @@ prvm_builtin_t vm_m_builtins[] = { VM_M_setmousetarget, VM_M_getmousetarget, VM_M_callfunction, - VM_M_writetofile // 606 + VM_M_writetofile, + VM_M_isfunction // 607 }; const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t); diff --git a/prvm_edict.c b/prvm_edict.c index 5aa1d6af..45f17c61 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -1134,7 +1134,7 @@ void PRVM_ED_LoadFromFile (const char *data) } // -// immediately call spawn function, but only if there is a self global +// immediately call spawn function, but only if there is a self global and a classname // if(prog->self && prog->flag & PRVM_FE_CLASSNAME) { -- 2.39.2