loadfromdata(string data)
loadfromfile(string file)
float mod(float val, float m)
+const string str_cvar (string)
+ crash()
+ stackdump()
perhaps only : Menu : WriteMsg
===============================
callfunction(...,string function_name)
writetofile(float fhandle, entity ent)
+float isfunction(string function_name)
+vector getresolution(float number)
*/
#include "quakedef.h"
char string[VM_STRINGTEMP_LENGTH];
VM_VarString(0, string, sizeof(string));
- Con_Print(string);
+ Con_Printf(string);
}
/*
PRVM_G_FLOAT(OFS_RETURN) = Cvar_VariableValue(PRVM_G_STRING(OFS_PARM0));
}
+/*
+=================
+VM_str_cvar
+
+const string str_cvar (string)
+=================
+*/
+void VM_str_cvar(void)
+{
+ char *out, *name;
+ const char *cvar_string;
+ VM_SAFEPARMCOUNT(1,VM_str_cvar);
+
+ name = PRVM_G_STRING(OFS_PARM0);
+
+ if(!name)
+ PRVM_ERROR("VM_str_cvar: %s: null string\n", PRVM_NAME);
+
+ VM_CheckEmptyString(name);
+
+ out = VM_GetTempString();
+
+ cvar_string = Cvar_VariableString(name);
+
+ strcpy(out, cvar_string);
+
+ PRVM_G_INT(OFS_PARM0) = PRVM_SetString(out);
+}
+
/*
=================
VM_cvar_set
Cbuf_AddText("\n");
}
+/*
+=========
+VM_stackdump
+
+stackdump()
+=========
+*/
+void PRVM_StackTrace(void);
+void VM_stackdump (void)
+{
+ VM_SAFEPARMCOUNT(0, VM_stackdump);
+
+ PRVM_StackTrace();
+}
+
+/*
+=========
+VM_crash
+
+crash()
+=========
+*/
+
+void VM_crash(void)
+{
+ VM_SAFEPARMCOUNT(0, VM_crash);
+
+ PRVM_ERROR("Crash called by %s\n",PRVM_NAME);
+}
+
/*
=========
VM_traceon
{
char *s;
- if(prog->argc <= 2)
+ if(prog->argc < 2)
PRVM_ERROR("VM_strcat wrong parameter count (min. 2 expected ) !\n");
s = VM_GetTempString();
PRVM_G_FLOAT(OFS_RETURN) = cls.state;
}
+/*
+=========
+VM_getostype
+
+float getostype(void)
+=========
+*/ // not used at the moment -> not included in the common list
+void VM_getostype(void)
+{
+ VM_SAFEPARMCOUNT(0,VM_getostype);
+
+ /*
+ OS_WINDOWS
+ OS_LINUX
+ OS_MAC - not supported
+ */
+
+#ifdef _WIN32
+ PRVM_G_FLOAT(OFS_RETURN) = 0;
+#elif defined _MAC
+ PRVM_G_FLOAT(OFS_RETURN) = 2;
+#else
+ PRVM_G_FLOAT(OFS_RETURN) = 1;
+#endif
+}
+
/*
=========
VM_getmousepos
void VM_Cmd_Reset(void)
{
- Mem_EmptyPool(VM_STRINGS_MEMPOOL);
+ //Mem_EmptyPool(VM_STRINGS_MEMPOOL);
+ Mem_FreePool(&VM_STRINGS_MEMPOOL);
VM_Files_CloseAll();
}
=========
*/
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
PRVM_ED_Write (VM_FILES[filenum], ent);
}
+/*
+=========
+VM_M_getresolution
+
+vector getresolution(float number)
+=========
+*/
+extern unsigned short video_resolutions[][2];
+void VM_M_getresolution(void)
+{
+ int nr;
+ VM_SAFEPARMCOUNT(1, VM_getresolution);
+
+ nr = PRVM_G_FLOAT(OFS_PARM0);
+
+
+ PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr][0];
+ PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr][1];
+ PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
+}
+
prvm_builtin_t vm_m_builtins[] = {
0, // to be consistent with the old vm
// common builtings (mostly)
VM_loadfromdata,
VM_loadfromfile,
VM_modulo, // 70
- e10, // 80
+ VM_str_cvar,
+ VM_crash,
+ VM_stackdump, // 73
+ 0,0,0,0,0,0,0,// 80
e10, // 90
e10, // 100
e100, // 200
VM_M_setmousetarget,
VM_M_getmousetarget,
VM_M_callfunction,
- VM_M_writetofile // 606
+ VM_M_writetofile,
+ VM_M_isfunction,
+ VM_M_getresolution // 608
};
const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);
void VM_M_Cmd_Reset(void)
{
- VM_Cmd_Init();
+ //VM_Cmd_Init();
+ VM_Cmd_Reset();
}