Added isfunction and changed callfunction so it works
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 31 Oct 2003 19:24:12 +0000 (19:24 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 31 Oct 2003 19:24:12 +0000 (19:24 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3620 d7cf8633-e32d-0410-b094-e92efae38249

mprogdefs.h
prvm_cmds.c
prvm_edict.c

index d06e270..0c7435c 100644 (file)
@@ -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
index cc3e46b..6adb8be 100644 (file)
@@ -2732,27 +2732,75 @@ 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
 
        writetofile(float fhandle, entity ent)
@@ -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);
index 5aa1d6a..45f17c6 100644 (file)
@@ -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)
                {