mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
Add a getfunction, which gives an error if it's not found
This commit is contained in:
parent
1a73a4789b
commit
dc98a63098
3 changed files with 26 additions and 10 deletions
|
@ -161,6 +161,7 @@ char *PR_GlobalStringNoContents (progs_t *pr, int ofs);
|
|||
pr_type_t *GetEdictFieldValue(progs_t *pr, edict_t *ed, const char *field);
|
||||
|
||||
void PR_AddBuiltin (progs_t *pr, const char *name, builtin_proc builtin, int num);
|
||||
int PR_FindBuiltin (progs_t *pr, const char *name);
|
||||
|
||||
//
|
||||
// PR Strings stuff
|
||||
|
|
|
@ -1359,7 +1359,7 @@ PR_Init (void)
|
|||
PR_Debug_Init ();
|
||||
}
|
||||
|
||||
#define PR_AUTOBUILTIN 110
|
||||
#define PR_AUTOBUILTIN 120
|
||||
void
|
||||
PR_AddBuiltin (progs_t *pr, const char *name, builtin_proc builtin, int num)
|
||||
{
|
||||
|
@ -1397,6 +1397,16 @@ PR_AddBuiltin (progs_t *pr, const char *name, builtin_proc builtin, int num)
|
|||
pr->builtins[j].name = name;
|
||||
}
|
||||
|
||||
int
|
||||
PR_FindBuiltin (progs_t *pr, const char *name)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < pr->numbuiltins; i++)
|
||||
if (pr->builtins[i].name && strequal (pr->builtins[i].name, name))
|
||||
return i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
edict_t *
|
||||
EDICT_NUM (progs_t * pr, int n)
|
||||
{
|
||||
|
|
|
@ -2001,16 +2001,20 @@ PF_Checkextension (progs_t *pr)
|
|||
void
|
||||
PF_checkfunction (progs_t *pr)
|
||||
{
|
||||
char *name = G_STRING (pr, OFS_PARM0);
|
||||
int i;
|
||||
G_FUNCTION (pr, OFS_RETURN) = -PR_FindBuiltin (pr, G_STRING (pr, OFS_PARM0));
|
||||
}
|
||||
|
||||
for (i = 0; i < pr->numbuiltins; i++) {
|
||||
if (pr->builtins[i].name && strequal (pr->builtins[i].name, name)) {
|
||||
G_FUNCTION (pr, OFS_RETURN) = -i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
G_FUNCTION (pr, OFS_RETURN) = 0;
|
||||
void
|
||||
PF_getfunction (progs_t *pr)
|
||||
{
|
||||
int i;
|
||||
const char *name;
|
||||
|
||||
name = G_STRING (pr, OFS_PARM0);
|
||||
i = PR_FindBuiltin (pr, name);
|
||||
if (!i)
|
||||
PR_RunError (pr, "PF_getfunction: function '%s' not found!\n", name);
|
||||
G_FUNCTION (pr, OFS_RETURN) = -i;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -2136,4 +2140,5 @@ SV_PR_Cmds_Init ()
|
|||
PR_AddBuiltin (&sv_pr_state, "cfeof", PF_cfeof, 107); // float (float desc) cfeof = #107
|
||||
PR_AddBuiltin (&sv_pr_state, "cfquota", PF_cfquota, 108); // float () cfquota = #108
|
||||
PR_AddBuiltin (&sv_pr_state, "checkfunction", PF_checkfunction, 109); // function (string name) checkfunction = #109
|
||||
PR_AddBuiltin (&sv_pr_state, "getfunction", PF_getfunction, 110); // function (string name) getfunction = #110
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue